Bar Logo 4kW dsPIC33C PSFB DC-DC DA (Part-No. )
 
Content
     
Loading...
Searching...
No Matches
pwrctrl_pwm.c
Go to the documentation of this file.
1
9#include <xc.h>
10#include <stdbool.h>
11#include "pwm_hs/pwm.h"
12#include "pwrctrl_typedef.h"
13#include "pwrctrl_pwm.h"
14
15#define DEAD_TIME_ADJ 240
16
17
43
44
54{
55 // Turn-On PWM outputs by disabling the output override
56 // on each high and low PWM output
57 // Start PWM
58 PG4CONLbits.ON = 1;
59 PG2CONLbits.ON = 1;
60 PG3CONLbits.ON = 1;
61 PG1CONLbits.ON = 1;
62
63 PCLKCONbits.MCLKSEL = 1;
64 PCLKCONbits.DIVSEL = 0;
65
66 int timeout = 0;
67
68 while ((0 == PCLKCONbits.HRRDY) && (++timeout < 5000));
69 if (timeout < 5000)
70 {
71 PG1STATbits.UPDREQ = 1; // make sure all PWM channels are updated before enabling outputs
72
73 // Hand over pin control to PWM module
74 PG1IOCONHbits.PENH = 1;
75 PG1IOCONHbits.PENL = 1;
76 PG2IOCONHbits.PENH = 0; // not used
77 PG2IOCONHbits.PENL = 1;
78 PG3IOCONHbits.PENH = 1;
79 PG3IOCONHbits.PENL = 1;
80 PG4IOCONHbits.PENH = 0; // not used
81 PG4IOCONHbits.PENL = 1;
82
83 for (int i=1000; i>0; i--); // short delay
84
85 // enable PWM channel outputs by clearing override bits
86 PG1IOCONLbits.OVRENH = 0;
87 PG1IOCONLbits.OVRENL = 0;
88
89 PG2IOCONLbits.OVRENH = 1; // not used
90 //PG2IOCONLbits.OVRENL = 0;
91 PG2IOCONLbits.OVRENL = 1; // temporary.
92
93 PG3IOCONLbits.OVRENH = 0;
94 PG3IOCONLbits.OVRENL = 0;
95
96 PG4IOCONLbits.OVRENH = 1; // not used
97 //PG4IOCONLbits.OVRENL = 0;
98 PG4IOCONLbits.OVRENL = 1;
99 }
100
101}
102
103
104
113{
114 // Turn-Off PWM outputs by enabling the output override
115 // on each high and low PWM output
116// PWM_OverrideHighEnable(PWM_PRI_1);
117// PWM_OverrideHighEnable(PWM_SEC_1);
118// PWM_OverrideHighEnable(PWM_PRI_2);
119// PWM_OverrideHighEnable(PWM_SEC_2);
120//
121// PWM_OverrideLowEnable(PWM_PRI_1);
122// PWM_OverrideLowEnable(PWM_SEC_1);
123// PWM_OverrideLowEnable(PWM_PRI_2);
124// PWM_OverrideLowEnable(PWM_SEC_2);
125
126 // Set update request of the last PWM in the cascade
127 // to update all pwm registers
128 PG1IOCONLbits.OVRENH = 1;
129 PG1IOCONLbits.OVRENL = 1;
130 PG2IOCONLbits.OVRENH = 1;
131 PG2IOCONLbits.OVRENL = 1;
132 PG3IOCONLbits.OVRENH = 1;
133 PG3IOCONLbits.OVRENL = 1;
134 PG4IOCONLbits.OVRENH = 1;
135 PG4IOCONLbits.OVRENL = 1;
136// PWM_SoftwareUpdateRequest(PWM_SEC_2);
137
138}
139
140
141
150{
151 /*
152 PG1 is the leading PWM channel
153 PG3 is triggered by PG1, where PG3 is synchronized to PG1 including updates
154 PG4 is sync rectifier of PWM1H+PWM3L and is also synchronized to PG1
155 PG2 is sync rectifier of PWM3H+PWM1L and is synchronized to PG3
156 All updates are triggered by the PG1 broadcast
157 All updates are performed at the cycle boundary (EOC)
158 PG2 and PG4 only use PWMxL output
159 PG2 and PG4 are swapped, hence, their respective HIGH signal is used
160 Sync Rectifier edge placement is tuned by PGxDTH and PGxDC of PG2 and PG4,
161 where the duty cycle = PER - PHASE-SHIFT +/- EDGEPLACEMENT
162 */
163
164 // Set base register of PWM channels
165 PG1CONL = 0x0088; // CLKSEL=1, HREN=1, ON=0
166 PG2CONL = 0x0088; // CLKSEL=1, HREN=1, ON=0
167 PG3CONL = 0x0088; // CLKSEL=1, HREN=1, ON=0
168 PG4CONL = 0x0088; // CLKSEL=1, HREN=1, ON=0
169
170 // Set synchronization of PWM start and register update
171 PG1CONH = 0x0800; // SOCS=0, MSTEN=1
172 PG2CONH = 0x0243; // SOCS=3, TRGMOD=1, UPDMOD=2
173 PG3CONH = 0x0241; // SOCS=1, TRGMOD=1, UPDMOD=2
174 PG4CONH = 0x0241; // SOCS=1, TRGMOD=1, UPDMOD=2
175
176 // Set I/O Configuration
177 PG1IOCONL = 0x3000; // OVRENH/L=1
178 PG1IOCONH = 0; // PENH/L=0
179 PG2IOCONL = 0x7000; // SWAP=1, OVRENH=1=1, OVRENL=1
180 PG2IOCONH = 0; // PENH/L=0
181 PG3IOCONL = 0x3000; // OVRENH/L=1
182 PG3IOCONH = 0; // PENH/L=0
183 PG4IOCONL = 0x7000; // SWAP=1, OVRENH=1=1, OVRENL=1
184 PG4IOCONH = 0; // PENH/L=0
185
186 // Set PG synchronization triggers
187 PG1EVTL = 0; // clear register
188 PG1EVTLbits.PGTRGSEL = 0b011; // use PGxTRIGC to set phase shift
189 PG1EVTLbits.UPDTRG = 0; // requires UPDREQ bit to be set manually
190 PG1EVTLbits.ADTR1EN1 = 1; // enable ADC trigger 1 => TRIGA
191 PG1EVTH = 0; // disable all triggers
192 PG1EVTHbits.ADTR2EN2 = 1; // enable ADC trigger 2 => TRIGB
193
194 PG2EVTL = 0; // disable all triggers
195 PG2EVTH = 0; // disable all triggers
196 PG3EVTLbits.PGTRGSEL = 0b011; // use PGxTRIGC to set phase shift
197 PG3EVTLbits.UPDTRG = 0; // requires UPDREQ bit to be set manually
198 PG3EVTH = 0; // disable all triggers
199 PG4EVTL = 0; // disable all triggers
200 PG4EVTH = 0; // disable all triggers
201
202 // Set Period
203 PG1PER = 40000;
204 PG2PER = 40000;
205 PG3PER = 40000;
206 PG4PER = 40000;
207
208 // Set Duty Cycle
209 PG1DC = 20000;
210 PG3DC = 20000;
211
212 // Set dead times
213 PG1DTH = 640; // set dead time to 160ns
214 PG1DTL = 640; // set dead time to 160ns
215 PG2DTH = 0; // no dead time on PWMxH
216 PG2DTL = 640 + DEAD_TIME_ADJ; // set dead time to 160ns
217 PG3DTH = 640; // set dead time to 160ns
218 PG3DTL = 640; // set dead time to 160ns
219 PG4DTH = 0; // no dead time on PWMxH
220 PG4DTL = 640 + DEAD_TIME_ADJ; // set dead time to 160ns
221
222 // Set synchronization triggers
223 PG1TRIGC = 0; // phase shift = 0
224 PG3TRIGC = PG1DC; // phase shift = duty cycle of leading PWM channel
225 PG2DC = (PG1PER - PG1TRIGC - PG2DTL);
226 PG4DC = (PG1PER - PG1TRIGC - PG4DTL);
227
228}
229
230
231
241 PG1IOCONLbits.OVRENH = 1;
242 PG1IOCONLbits.OVRENL = 1;
243 PG3IOCONLbits.OVRENH = 1;
244 PG3IOCONLbits.OVRENL = 1;
245}
246
247
248
258void PwrCtrl_PWM_SetDutyCyclePrimary(uint16_t dutycycle){
259 // max phase shift 20000;
260 // 1 percent = 20000 / 200;
261 uint16_t phaseValue = dutycycle * 200;
265}
266
267
268
279 if (psfb_ptr->SecRec.SR_Enabled == 0){
280 return;
281 }
282
283 if (psfb_ptr->SecRec.SR_Flag == 0)
284 {
285 //threshhold = 970;
286
287// if (psfb_ptr->Data.ISenseSecondary > psfb_ptr->SecRec.Threshold_high) { //approx 34 amps Iout psfb_ptr->Secondary_Rolling_val;
289 //debug_SetHigh();
291 PG4IOCONLbits.OVRENL = 0; //turning on SR
292 PG2IOCONLbits.OVRENL = 0;
293 }
294 } else {
295 //threshhold = 950;
296// if (psfb_ptr->Data.ISenseSecondary < psfb_ptr->SecRec.Threshold_low) { // approx 26 amps Iout
298 //debug_SetLow();
300 PG4IOCONLbits.OVRENL = 1; //turning off SR
301 PG2IOCONLbits.OVRENL = 1;
302 }
303 }
304}
This is the generated driver header file for the PWM driver.
@ PWM_SEC_1
@ PWM_PRI_1
@ PWM_SEC_2
POWER_CONTROL_t * psfb_ptr
Definition pwrctrl.c:28
#define DEAD_TIME_ADJ
Definition pwrctrl_pwm.c:15
Contains public functions for PWM.
void PwrCtrl_PWM_Update()
PWM distribution for PSFB converter.
Definition pwrctrl_pwm.c:26
void PwrCtrl_PWM_Disable(void)
Disable the PWM output.
void PwrCtrl_PWM_Initialize(void)
Initialize the PWM peripheral.
void PwrCtrl_PWM_SetDutyCyclePrimary(uint16_t dutycycle)
set the PWM output to particular duty cycle.
void PwrCtrl_PWM_Stop_Switching(void)
Disable the PWM output.
void PwrCtrl_PWM_Enable(void)
Enable the PWM output.
Definition pwrctrl_pwm.c:53
void PwrCtrl_PWM_UpdateSecondaryRectifiers(void)
set the PWM output to particular duty cycle.
static void PWM_TriggerBCompareValueSet(enum PWM_GENERATOR genNum, uint16_t trigB)
This inline function sets the Trigger B compare value in count for a specific PWM generator selected ...
Definition pwm.h:1323
static void PWM_DutyCycleSet(enum PWM_GENERATOR genNum, uint16_t dutyCycle)
This inline function sets the PWM generator specific duty cycle register.
Definition pwm.h:500
static void PWM_SoftwareUpdateRequest(enum PWM_GENERATOR genNum)
This inline function requests to update the data registers for specific PWM generator selected by the...
Definition pwm.h:1239
static void PWM_TriggerCCompareValueSet(enum PWM_GENERATOR genNum, uint16_t trigC)
This inline function sets the Trigger C compare value in count for a specific PWM generator selected ...
Definition pwm.h:1350
uint16_t ControlPhase
Control phase value from control loop.
uint16_t PBVControlPhaseTarget
Power Board Visualizer Set Control phase.
bool Enable
Enable control loop.
uint16_t Threshold_high
uint8_t SR_Flag
uint16_t Threshold_low
uint8_t SR_Enabled
CONTROLLER_t ILoop
structure for current controller data
SWITCH_NODE_t Pwm
Switch node settings.
SEC_REC_t SecRec
structure for secondary rectification data
uint16_t Secondary_Rolling_val
Secondary Current Rolling Average Value.