Digital Power Starter Kit 3 Firmware
dsPIC33C Buck Converter Voltage Mode Control Example
p33c_dac.c
1 /* Microchip Technology Inc. and its subsidiaries. You may use this software
2  * and any derivatives exclusively with Microchip products.
3  *
4  * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
5  * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
6  * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
7  * PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
8  * WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
9  *
10  * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
11  * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
12  * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
13  * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
14  * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS
15  * IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF
16  * ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
17  *
18  * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
19  * TERMS.
20  */
21 
22 // Include standard header files
23 #include <xc.h> // include processor files - each processor file is guarded.
24 #include <stdint.h> // include standard integer data types
25 #include <stdbool.h> // include standard boolean data types
26 #include <stddef.h> // include standard definition data types
27 
28 #include "p33c_dac.h"
29 
30 
45 {
46  volatile struct P33C_DAC_MODULE_s* dac;
47 
48  // Capture Handle: set pointer to memory address of desired DAC instance
49  dac = (volatile struct P33C_DAC_MODULE_s*)((volatile uint8_t*) &DACCTRL1L);
50 
51  return(dac);
52 }
53 
54 
75 volatile uint16_t p33c_DacModule_Dispose(void)
76 {
77  volatile uint16_t retval=1;
78 
80 
81  return(retval);
82 }
83 
84 
100 volatile struct P33C_DAC_MODULE_s p33c_DacModule_ConfigRead(void)
101 {
102  volatile struct P33C_DAC_MODULE_s* dac;
103 
104  // Set pointer to memory address of desired DAC instance
105  dac = (volatile struct P33C_DAC_MODULE_s*)((volatile uint8_t*) &DACCTRL1L);
106 
107  return(*dac);
108 
109 }
110 
111 
129 volatile uint16_t p33c_DacModule_ConfigWrite(
130  volatile struct P33C_DAC_MODULE_s dacModuleConfig
131 )
132 {
133  volatile uint16_t retval=1;
134  volatile struct P33C_DAC_MODULE_s* dac;
135 
136  // Set pointer to memory address of the DAC module base registers
137  dac = (volatile struct P33C_DAC_MODULE_s*)((volatile uint8_t*) &DACCTRL1L);
138  *dac = dacModuleConfig;
139 
140  return(retval);
141 
142 }
143 
144 
145 /* ============================================================================== */
146 /* ============================================================================== */
147 /* ============================================================================== */
148 
149 
150 
165 volatile struct P33C_DAC_INSTANCE_s* p33c_DacInstance_GetHandle(volatile uint16_t dacInstance)
166 {
167  volatile struct P33C_DAC_INSTANCE_s* dac;
168 
169  // Capture Handle: set pointer to memory address of desired DAC instance
170  dac = (volatile struct P33C_DAC_INSTANCE_s*)
171  ((volatile uint8_t*) &DAC1CONL + ((dacInstance - 1) * P33C_DAC_SFR_OFFSET));
172 
173  return(dac);
174 }
175 
176 
197 volatile uint16_t p33c_DacInstance_Dispose(volatile uint16_t dacInstance)
198 {
199  volatile uint16_t retval=1;
200 
201  retval = p33c_DacInstance_ConfigWrite(dacInstance, dacConfigClear);
202 
203  return(retval);
204 }
205 
206 
221 volatile struct P33C_DAC_INSTANCE_s p33c_DacInstance_ConfigRead(volatile uint16_t dacInstance)
222 {
223  volatile struct P33C_DAC_INSTANCE_s* dac;
224 
225  // Set pointer to memory address of desired DAC instance
226  dac = (volatile struct P33C_DAC_INSTANCE_s*)
227  ((volatile uint8_t*) &DAC1CONL + ((dacInstance - 1) * P33C_DAC_SFR_OFFSET));
228 
229  return(*dac);
230 
231 }
232 
233 
253  volatile uint16_t dacInstance,
254  volatile struct P33C_DAC_INSTANCE_s dacConfig)
255 {
256  volatile uint16_t retval=1;
257  volatile struct P33C_DAC_INSTANCE_s* dac;
258 
259  // Set pointer to memory address of desired DAC instance
260  dac = (volatile struct P33C_DAC_INSTANCE_s*)
261  ((volatile uint8_t*) &DAC1CONL + ((dacInstance - 1) * P33C_DAC_SFR_OFFSET));
262  *dac = dacConfig;
263 
264  return(retval);
265 
266 }
267 
268 
269 /* ============================================================================== */
270 /* ============================================================================== */
271 /* ============================================================================== */
272 
273 
287 volatile struct P33C_DAC_MODULE_s dacModuleConfigClear = {
288 
289  .DacModuleCtrl1L.value = 0x0000,
290  .DacModuleCtrl2L.value = 0x0000,
291  .DacModuleCtrl2H.value = 0x0000
292 
293  };
294 
295 
314 volatile struct P33C_DAC_MODULE_s dacModuleDefault = {
315  .DacModuleCtrl1L.value = 0x0080,
316  .DacModuleCtrl2H.bits.SSTIME = 0x008A,
317  .DacModuleCtrl2L.bits.TMODTIME = 0x0055
318 };
319 
320 
335 volatile struct P33C_DAC_INSTANCE_s dacConfigClear = {
336 
337  .DACxCONL.value = 0x0000,
338  .DACxCONH.value = 0x0000,
339  .DACxDATL.value = 0x0000,
340  .DACxDATH.value = 0x0000,
341  .SLPxCONL.value = 0x0000,
342  .SLPxCONH.value = 0x0000,
343  .SLPxDAT.value = 0x0000
344 
345  };
346 
347 
348 // end of file
p33c_DacInstance_GetHandle
volatile struct P33C_DAC_INSTANCE_s * p33c_DacInstance_GetHandle(volatile uint16_t dacInstance)
Gets pointer to DAC Instance SFR set.
Definition: p33c_dac.c:165
p33c_DacInstance_Dispose
volatile uint16_t p33c_DacInstance_Dispose(volatile uint16_t dacInstance)
Resets all DAC Instance registers to their RESET default values.
Definition: p33c_dac.c:197
P33C_DAC_MODULE_s::DacModuleCtrl1L
union P33C_DAC_MODULE_s::@0 DacModuleCtrl1L
dacConfigClear
volatile struct P33C_DAC_INSTANCE_s dacConfigClear
Default RESET configuration of one DAC instance channel SFRs.
Definition: p33c_dac.c:335
p33c_DacModule_GetHandle
volatile struct P33C_DAC_MODULE_s * p33c_DacModule_GetHandle(void)
Gets pointer to DAC Module SFR set.
Definition: p33c_dac.c:44
p33c_DacInstance_ConfigWrite
volatile uint16_t p33c_DacInstance_ConfigWrite(volatile uint16_t dacInstance, volatile struct P33C_DAC_INSTANCE_s dacConfig)
Writes a user-defined configuration to the DAC instance registers.
Definition: p33c_dac.c:252
dacModuleDefault
volatile struct P33C_DAC_MODULE_s dacModuleDefault
Default configuration of DAC module running from 500 MHz input clock.
Definition: p33c_dac.c:314
p33c_DacModule_ConfigWrite
volatile uint16_t p33c_DacModule_ConfigWrite(volatile struct P33C_DAC_MODULE_s dacModuleConfig)
Writes a user-defined configuration to the DAC module base registers.
Definition: p33c_dac.c:129
p33c_DacModule_ConfigRead
volatile struct P33C_DAC_MODULE_s p33c_DacModule_ConfigRead(void)
Read the current configuration from the DAC module base registers.
Definition: p33c_dac.c:100
P33C_DAC_MODULE_s
Abstracted set of Special Function Registers of a Digital-to-Analog Converter peripheral.
Definition: p33c_dac.h:60
P33C_DAC_INSTANCE_s
Definition: p33c_dac.h:94
dacModuleConfigClear
volatile struct P33C_DAC_MODULE_s dacModuleConfigClear
Default RESET configuration of the DAC module base SFRs.
Definition: p33c_dac.c:287
p33c_DacModule_Dispose
volatile uint16_t p33c_DacModule_Dispose(void)
Resets all DAC Module registers to their RESET default values.
Definition: p33c_dac.c:75
P33C_DAC_INSTANCE_s::value
volatile uint16_t value
Definition: p33c_dac.h:97
P33C_DAC_MODULE_s::value
volatile uint16_t value
Definition: p33c_dac.h:63
P33C_DAC_INSTANCE_s::DACxCONL
union P33C_DAC_INSTANCE_s::@6 DACxCONL
p33c_DacInstance_ConfigRead
volatile struct P33C_DAC_INSTANCE_s p33c_DacInstance_ConfigRead(volatile uint16_t dacInstance)
Read the current configuration from the DAC instance registers.
Definition: p33c_dac.c:221