EPC9143 300 W 16th Brick DC/DC Module Reference Design
init_acmp.c
1 /*
2  * File: init_acmp.c
3  * Author: M91406
4  *
5  * Created on July 9, 2019, 11:12 AM
6  */
7 
8 
9 #include <xc.h>
10 #include <stdint.h>
11 #include <stdbool.h>
12 
13 #include "init_acmp.h"
14 
15 
16 
17 volatile uint16_t init_acmp_module(void) {
18 
19  // Make sure power is turned on to comparator module #1 & #2
20  PMD7bits.CMP1MD = 0; // Comparator 1 Module Power Disable: Comparator 1 module is enabled
21 // PMD7bits.CMP2MD = 0; // Comparator 2 Module Power Disable: Comparator 2 module is enabled
22 // PMD7bits.CMP3MD = 0; // Comparator 3 Module Power Disable: Comparator 3 module is enabled
23 
24 
25  // Turn off all Comparator/DAC modules during configuration
26  DACCTRL1Lbits.DACON = 0; // Common DAC Module Enable: Disables all DAC modules
27  DAC1CONLbits.DACEN = 0; // Individual DAC1 Module Enable: Disables DAC1 module during configuration
28  DAC2CONLbits.DACEN = 0; // Individual DAC2 Module Enable: Disables DAC2 module during configuration
29  DAC3CONLbits.DACEN = 0; // Individual DAC3 Module Enable: Disables DAC3 module during configuration
30 
31  // VREGCON: VOLTAGE REGULATOR CONTROL REGISTER
32  VREGCONbits.LPWREN = 0; // Low-Power Mode Enable: Voltage regulators are in Full Power mode
33  VREGCONbits.VREG1OV = 0b00; // Regulator #1 Low-Power Mode Enable: VOUT = 1.5 * VBG = 1.2V
34  VREGCONbits.VREG2OV = 0b00; // Regulator #2 Low-Power Mode Enable: VOUT = 1.5 * VBG = 1.2V
35  VREGCONbits.VREG3OV = 0b00; // Regulator #3 Low-Power Mode Enable: VOUT = 1.5 * VBG = 1.2V
36 
37  // DACCTRL1L: DAC CONTROL 1 LOW REGISTER
38  DACCTRL1Lbits.DACSIDL = 0; // DAC Stop in Idle Mode: Continues module operation in Idle mode
39  DACCTRL1Lbits.CLKSEL = 0b10; // DAC Clock Source Selection: AFPLLO
40  DACCTRL1Lbits.CLKDIV = 0b00; // DAC Clock Divider: Divider = 1:1
41  DACCTRL1Lbits.FCLKDIV = 0b000; // Comparator Filter Clock Divider: Divider = 1:1
42 
43  // DACCTRL2H/L: DAC CONTROL 2 HIGH and DAC CONTROL 2 LOW REGISTER
44  // Settings = 2 x
45  DACCTRL2Lbits.TMODTIME = (TMOD_DURATION & 0x03FF); // Transition Mode Duration (default 0x55 = 340ns @ 500 MHz)
46  DACCTRL2Hbits.SSTIME = (SS_DURATION & 0x0FFF); // Time from Start of Transition Mode until Steady-State Filter is Enabled (default 0x8A = 552ns @ 500 MHz)
47 
48  return(1);
49 }
50 
51 volatile uint16_t init_buck_vmc(void) {
52 
53  // DACxCONL: DACx CONTROL LOW REGISTER
54  DAC1CONLbits.DACEN = 0; // Individual DACx Module Enable: Disables DACx module during configuration
55  DAC1CONLbits.IRQM = 0b00; // Interrupt Mode Selection: Interrupts are disabled
56  DAC1CONLbits.CBE = 1; // Comparator Blank Enable: Enables the analog comparator output to be blanked (gated off) during the recovery transition following the completion of a slope operation
57  DAC1CONLbits.DACOEN = 1; // DACx Output Buffer Enable: DACx analog voltage is connected to the DACOUT1 pin (RA3/TP35 on DPSK3)
58  DAC1CONLbits.FLTREN = 0; // Comparator Digital Filter Enable: Digital filter is disabled
59  // DAC1CONLbits.CMPSTAT (read only bit)
60  DAC1CONLbits.CMPPOL = 0; // Comparator Output Polarity Control: Output is non-inverted
61  DAC1CONLbits.INSEL = 0b001; // Comparator Input Source Select: feedback is connected to CMPxB input pin
62  DAC1CONLbits.HYSPOL = 0; // Comparator Hysteresis Polarity Selection: Hysteresis is applied to the rising edge of the comparator output
63  DAC1CONLbits.HYSSEL = 0b11; // Comparator Hysteresis Selection: 45 mv hysteresis (0 = 0mV, 1 = 15mV, 2 = 30mV, 3 = 45mV)
64 
65  // DACxCONH: DACx CONTROL HIGH REGISTER
66 
67  // ***********************************************
68  // ToDo: CHECK DAC LEB PERIOD TO BE CORRECT AND DOESN'T CREATE CONFLICTS
69  DAC1CONHbits.TMCB = LEB_PER_COMP; // DACx Leading-Edge Blanking: period for the comparator
70  // ***********************************************
71 
72  // DACxDATH: DACx DATA HIGH REGISTER
73  DAC1DATH = (DACDATH & 0x0FFF); // DACx Data: This register specifies the high DACx data value. Valid values are from 205 to 3890.
74  DAC1DATL = (DACDATL & 0x0FFF); // DACx Low Data
75 
76  // SLPxCONH: DACx SLOPE CONTROL HIGH REGISTER
77  SLP1CONHbits.SLOPEN = 1; // Slope Function Enable/On: Enables slope function
78  SLP1CONHbits.HME = 0; // Hysteretic Mode Enable: Disables Hysteretic mode for DACx
79  SLP1CONHbits.TWME = 0; // Triangle Wave Mode Enable: Disables Triangle Wave mode for DACx
80  SLP1CONHbits.PSE = 0; // Positive Slope Mode Enable: Slope mode is negative (decreasing)
81 
82  // SLPxCONL: DACx SLOPE CONTROL LOW REGISTER
83  SLP1CONLbits.HCFSEL = 0b0000; // Hysteretic Comparator Function Input Selection: (none)
84  SLP1CONLbits.SLPSTOPA = 0b0001; // Slope Stop A Signal Selection: PWM1 Trigger 2
85  SLP1CONLbits.SLPSTOPB = 0b0001; // Slope Stop B Signal Selection: CMP1 Out
86 // SLP1CONLbits.SLPSTOPB = 0b0000; // Slope Stop B Signal Selection: 0
87  SLP1CONLbits.SLPSTRT = 0b0001; // Slope Start Signal Selection: PWM1 Trigger 1
88 
89  // ToDo: CHECK SLP1DAT in conjunction with DAC1DATH and DAC1DATL
90  // DAC1DATL should be reserved/valid only in hysteretic and triangular mode
91  // So for normal slope compensation the valid registers should be DAC1DATH as reference level
92  // and SLP1DAT for the slew rate (V/usec translated in DAC-ticks/time-ticks)
93  // Previous configurations have shown that this might not be true, so please revisit this setting.
94 
95  // SLPxDAT: DACx SLOPE DATA REGISTER
96 // SLP1DAT = 500; // Slope Ramp Rate Value
97  SLP1DAT = SLOPE_RATE; // Slope Ramp Rate Value
98 
99 
100  return(1);
101 }
102 
103 volatile uint16_t launch_buck_acmp(void) {
104 
105  DAC1CONLbits.DACEN = 1; // Individual DACx Module Enable: Enables DAC1 module
106  DACCTRL1Lbits.DACON = 1; // Common DAC Module Enable: Enables all enabled DAC modules
107 
108  return(1);
109 }
110