Digital Power Starter Kit 3 Firmware
dsPIC33C Buck Converter Voltage Mode Control Example
init_dac.c
1 /*
2  * File: init_opa.c
3  * Author: M91406
4  *
5  * Created on May 19, 2020, 1:19 PM
6  */
7 
8 
9 #include <xc.h> // include processor files - each processor file is guarded.
10 #include <stdint.h> // include standard integer types header file
11 #include <stdbool.h> // include standard boolean types header file
12 
13 #include "config/hal.h"
14 #include "init_dac.h"
15 #include "power_control/devices/dev_buck_typedef.h"
16 
21 
39 volatile uint16_t sysDacModule_Initialize(void)
40 {
41  volatile uint16_t retval=1;
42  volatile struct P33C_DAC_MODULE_s* dac;
43 
45  retval &= p33c_DacModule_Dispose();
47 
48  return (retval);
49 
50 }
51 
52 
71 volatile uint16_t sysDacOutput_Initialize(volatile uint16_t dacInstance, volatile uint16_t initValue)
72 {
73  volatile uint16_t retval=1;
74  volatile struct P33C_DAC_INSTANCE_s* dac;
75 
76  dac = p33c_DacInstance_GetHandle(dacInstance);
77  retval &= p33c_DacInstance_Dispose(dacInstance);
78 
79  dac->DACxCONL.bits.DACOEN = 1; // Enable DAC output pin
80  dac->DACxCONH.bits.TMCB = BUCK_LEB_PERIOD; // Set Leading Edge blanking interval period
81  dac->DACxDATH.value = initValue; // Set DAC output to initial value
82 
83  return (retval);
84 }
85 
86 
99 volatile uint16_t sysDacOutput_Enable(volatile uint16_t dacInstance) {
100 
101  volatile uint16_t retval=1;
102  volatile struct P33C_DAC_MODULE_s* dacmod;
103  volatile struct P33C_DAC_INSTANCE_s* dacinst;
104 
105  // Capture DAC module SFR set
106  dacmod = p33c_DacModule_GetHandle();
107  dacmod->DacModuleCtrl1L.bits.DACON = true; // Ensure DAC module is enabled
108 
109  // Capture specified DAC instance SFR set
110  dacinst = p33c_DacInstance_GetHandle(dacInstance);
111  dacinst->DACxCONL.bits.DACEN = true; // Enable DAC instance
112  dacinst->DACxCONL.bits.DACOEN = true; // Enable DAC output pin
113 
114  return (retval);
115 }
116 
117 
129 volatile uint16_t sysDacOutput_Disable(volatile uint16_t dacInstance) {
130 
131  volatile uint16_t retval=1;
132  volatile struct P33C_DAC_INSTANCE_s* dacinst;
133 
134  // Capture specified DAC instance SFR set
135  dacinst = p33c_DacInstance_GetHandle(dacInstance);
136  dacinst->DACxCONL.bits.DACOEN = false; // Disable DAC output pin
137  dacinst->DACxCONL.bits.DACEN = false; // Disable DAC instance
138 
139  return (retval);
140 } // end of group dac-initialization
142 
143 // end of file
sysDacModule_Initialize
volatile uint16_t sysDacModule_Initialize(void)
DAC Module Base Register Initialization.
Definition: init_dac.c:39
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_INSTANCE_s::bits
volatile struct tagDAC1CONLBITS bits
Definition: p33c_dac.h:96
P33C_DAC_MODULE_s::DacModuleCtrl1L
union P33C_DAC_MODULE_s::@0 DacModuleCtrl1L
sysDacOutput_Disable
volatile uint16_t sysDacOutput_Disable(volatile uint16_t dacInstance)
Definition: init_dac.c:129
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
dacModuleDefault
volatile struct P33C_DAC_MODULE_s dacModuleDefault
Default configuration of DAC module running from 500 MHz input clock.
Definition: p33c_dac.c:314
sysDacOutput_Enable
volatile uint16_t sysDacOutput_Enable(volatile uint16_t dacInstance)
Definition: init_dac.c:99
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_DAC_INSTANCE_s::DACxCONH
union P33C_DAC_INSTANCE_s::@7 DACxCONH
P33C_DAC_MODULE_s
Abstracted set of Special Function Registers of a Digital-to-Analog Converter peripheral.
Definition: p33c_dac.h:60
P33C_DAC_MODULE_s::bits
volatile struct tagDACCTRL1LBITS bits
Definition: p33c_dac.h:62
BUCK_LEB_PERIOD
#define BUCK_LEB_PERIOD
Leading Edge Blanking = n x PWM resolution (here: 50 x 2ns = 100ns)
Definition: dpsk3_hwdescr.h:375
P33C_DAC_INSTANCE_s
Definition: p33c_dac.h:94
P33C_DAC_INSTANCE_s::DACxDATH
union P33C_DAC_INSTANCE_s::@9 DACxDATH
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_INSTANCE_s::DACxCONL
union P33C_DAC_INSTANCE_s::@6 DACxCONL
sysDacOutput_Initialize
volatile uint16_t sysDacOutput_Initialize(volatile uint16_t dacInstance, volatile uint16_t initValue)
Initializes a user specified DAC instance with DAC output enabled.
Definition: init_dac.c:71