Bar Logo Dual Active Bridge Development Board (Part-No. )
 
Content
     
Loading...
Searching...
No Matches
pwrctrl_isr_extension.c
Go to the documentation of this file.
1
9#include <xc.h>
10#include <math.h>
11#include <stdbool.h>
12#include <stdlib.h>
13
14// MCC header files
15#include "adc/adc_types.h"
16#include "adc/adc1.h"
17#include "system/pins.h"
18
19// DAB header files
20#include "config/macros.h"
21#include "config/config.h"
22#include "pwrctrl.h"
23#include "fault/fault.h"
24#include "dcdt/pwrctrl_dcdt.h"
25
26
27
35
43
51
52// STATIC VARIABLES and FUNCTIONS
53static void PwrCtrl_AdaptiveGainUpdate(void);
54static bool VLoopInterleaveExec = true;
55
56
101
102
113{
114 static uint16_t cnt = 0;
115
116 //Interleave the execution of VLoop and PLoop control for 10KHz execution
117 if(++cnt == (VPLOOP_ILOOP_EXE_RATIO))
118 {
119 // Averaging of Secondary Voltage
123
124 #if(OPEN_LOOP_PBV == false)
125 //Condition for control loop execution controlling the loop enable bit
126 if((dab.VLoop.Enable == false) && (VLoopInterleaveExec == true) && (dab.Status.bits.Running == 1))
127 #endif
128 {
129 // Enable Vloop control
130 dab.VLoop.Enable = true;
131 dab.PLoop.Enable = false;
132
133 // Averaging of Primary Voltage
137
138 // Compute the Adaptive Gain
140 }
141
142 #if(OPEN_LOOP_PBV == false)
143 else if((dab.PLoop.Enable == false) && (VLoopInterleaveExec == false) && (dab.Status.bits.Running == 1))
144 #endif
145 {
146 // Enable PLoop control
147 dab.VLoop.Enable = false;
148 dab.PLoop.Enable = true;
149
150 // Averaging of Secondary Current
154
155 // Bit-shift value used to perform input value normalization
156 // Scaled the feedback to Power (Watts in units)
157 uint32_t buf = (uint32_t)iSecAveraging.AverageValue *
159
160 // scale back the 14 bit from the POWER_RESOLUTION calculation
161 // to get the Watts value for Power Loop
162 buf >>= POWER_SCALER;
163
164 // Transfer to SecPower data member the power computation in [Watts]
165 dab.Data.SecPower = buf;
166
167 }
168
169 // If Power supply is not yet running, the averaging of
170 // primary voltage and secondary voltage continues to display in PBV
171 if(!dab.Status.bits.Running){
172 // Averaging of Primary Voltage
176
177 // Averaging of Secondary Current
181
182 // Bit-shift value used to perform input value normalization
183 // Scaled the feedback to Power (Watts in units)
184 uint32_t buf = (uint32_t)iSecAveraging.AverageValue *
186
187 // scale back the 14 bit from the POWER_RESOLUTION calculation
188 // to get the Watts value for Power Loop
189 buf >>= POWER_SCALER;
190
191 // Transfer to SecPower data member the power computation in [Watts]
192 dab.Data.SecPower = buf;
193 }
194
195 cnt = 0;
196 }
197}
198
199
211{
212 // Execute the Voltage Loop Control
213 if((dab.VLoop.Enable == true) && (VLoopInterleaveExec == true))
214 {
215 VLoopInterleaveExec = false;
216
218 {
219 VMC_2p2z.KfactorCoeffsB = 0x7FFF;
220 VMC_2p2z.maxOutput = 0x7FFF;
221
222 // Bit-shift value used to perform input value normalization
225
226 // Execute the Voltage Loop Control
229
230 // Reset the Vloop reference to its original scaling
232 }
233 }
234
235 // Execute the Power Loop Control
236 if((dab.PLoop.Enable == true) && (VLoopInterleaveExec == false))
237 {
238 VLoopInterleaveExec = true;
239
242
243 // Execute the Power Loop Control
246
247 }
248
249 // Execute the Current Loop Control
250 if(dab.ILoop.Enable == true)
251 {
253 //Bit-shift value used to perform input value normalization
255 //adaptive gain factor
257 //refresh limits
258 IMC_2p2z.maxOutput = 0x7FFF;
259
260 // Mixing stage from voltage loop 10KHz
261 uint32_t RefBuf = (uint32_t)(dab.ILoop.Reference) *
262 (uint32_t)(dab.VLoop.Output & 0x7FFF);
263 uint16_t ILoopReference = (uint16_t)(RefBuf >> 12);
264
265 // Mixing stage from power loop 10KHz
266 RefBuf = (uint32_t)ILoopReference * (uint32_t)(dab.PLoop.Output & 0x7FFF);
267 ILoopReference = (int16_t)(RefBuf >> 15);
268
269 // Basic clamping in rising direction, in case of Iloop or Vloop overshoot during large load step.
271 {
273 }
274 else
276 {
278 }
279 else
280 {
282 }
283
284
285 // Control loop output copied to control phase
286 dab.Pwm.ControlPhase = (((uint32_t)(dab.Pwm.ControlDutyCycle) *
287 (uint32_t)dab.ILoop.Output) >> 15); //range 0..180
289
290 // Clamping value of control phase
293 // Clamping value of control phase
296
298 }
299}
300
301
311{
312
313 // Calculate the primary voltage in terms of Volts
314 uint16_t DAB_PrimaryVoltage = __builtin_divud((vPrimAveraging.AverageValue * VPRI_SCALER), VPRI_FACTOR);
315
317 {
318 // Apply AGC when primary voltage is greater than the minimum VIN AGC threshold
319 if(DAB_PrimaryVoltage > AGC_MINIMUM_VIN_THRESHOLD)
320 dab.ILoop.AgcFactor = (int16_t) (0x7FFF &
321 __builtin_divud(AGC_VOLTAGE_FACTOR, DAB_PrimaryVoltage));
322 else // AGC is not active
323 dab.ILoop.AgcFactor = 0x7FFF;
324
325
326 #if(ENABLE_VLOOP_AGC == true)
328 dab.VLoop.AgcFactor = (int16_t) (0x7FFF &
329 __builtin_divud(AGC_CURRENT_FACTOR, dab.ILoop.Reference));
330 else // AGC is not active
331 dab.VLoop.AgcFactor = 0x7FFF;
332 #endif
333 }
334
335 // Reserved for future Development
337 {
338 }
339}
340
341
342
352{
353 // Calculation of Primary and Secondary degrees phase
354 // Normalize phase to 0..90.
355 uint32_t buff = ((unsigned long)dab.Pwm.ControlPhase) << DEGREES_PHASE_SCALER;
356 uint16_t buf = __builtin_divud( buff ,dab.Pwm.ControlDutyCycle);
357 buff = __builtin_muluu(buf, PRI_TO_SEC_PHASE_DEGREES_LIMIT);
358 buf = __builtin_divud( buff ,DEGREES_PHASE_SCALING_10);
359
360 // Calculation result for phase value scaled by 10x
362
363 // Clamping value for degrees phase when it exceeds the 90.0 degrees
365 {
366 // Override the calculated control phase value
368 }
369}
370
371
380{
381 uint16_t NewDT = 0;
382
383 // Deadtime values adjusted on rough phase range. experimentally measured values.
384 // If the control phase is less than 29.0 degrees phase
386 {NewDT = 2000;} // Equivalent to 500ns DeadTime
387 // If the control phase is within the range of 33.0 and 80.0 degrees phase
389 {NewDT = 1500;} // Equivalent to 375ns DeadTime
390 // If the control phase is within the range of 80.5 and 87.5 degrees phase
392 {NewDT = 700;} // Equivalent to 175ns DeadTime
393 // If the control phase is greater than 88.0 degrees phase
394 else if (dab.Pwm.ControlPhase_P2S_Degreex10 > 880)
395 {NewDT = 600;} // Equivalent to 150ns DeadTime
396
397 // When new dead-time did not satisfy any condition in degrees phase
398 //retain the previous dead-time value
399 if(NewDT)
400 {
401 // Minimum clamping value of dead-time
402 if (NewDT < MINIMUM_DEADTIME)
403 NewDT = MINIMUM_DEADTIME;
404
405 // Write the new dead-time to the PWM
406 dab.Pwm.DeadTimeLow = NewDT;
407 dab.Pwm.DeadTimeHigh = NewDT;
408
409 // Clear NewDT variable
410 NewDT=0;
411 }
412}
413
414#if defined (PERIOD_MODULATION_DEMO) && (PERIOD_MODULATION_DEMO == true)
415
423{
424 static uint16_t decimPM;
425 decimPM++;
426
428 dab.Pwm.ControlPhase_P2S_Target = PRI_TO_SEC_PHASE_TARGET;//clamp cutoff while modulating period
431
432 if(decimPM>=8)
433 {
435 {
437 {
439 }
440 else
441 {
442 // When phase shift between primary to secondary is 68 degrees,
443 // DAB runs in low power mode
445 {
447 }
448 }
449 }
450
452 {
454 {
456 }
457 }
458
459 if(dab.Pwm.LowPowerSlowMode == 1)
460 {
462 {
464 }
465 else
466 {
468 {
470 }
471 else
472 if (dab.Pwm.ControlPhase_P2S_Degreex10 > 330 )//snap out
473 {
475 }
476 }
477 }
478 decimPM=0;
479 }
480}
481
482#endif
This is the generated driver header file for the ADC1 driver.
This is the generated driver types header file for the ADC driver.
@ ISEC_CT
Definition adc_types.h:62
@ VSEC
Definition adc_types.h:57
@ IPRI_CT
Definition adc_types.h:58
@ TEMP
Definition adc_types.h:60
@ VPRI
Definition adc_types.h:59
@ VRAIL_5V
Definition adc_types.h:61
@ ISEC_AVG
Definition adc_types.h:63
Contains public fault functions.
Contains public functions and data types relevant for DCDT file interface.
void XFT_SMPS_Controller2P2ZUpdate(SMPS_2P2Z_T *controllerData, volatile uint16_t *controllerInputRegister, int16_t reference, volatile uint16_t *controllerOutputRegister)
void SMPS_Controller2P2ZUpdate(SMPS_2P2Z_T *controllerData, volatile uint16_t *controllerInputRegister, int16_t reference, volatile uint16_t *controllerOutputRegister)
void PwrCtrl_PeriodModulator(void)
static bool VLoopInterleaveExec
#define PRI_TO_SEC_PHASE_DEGREES_LIMIT
Maximum Limit for primary to secondary phase in degrees [deg].
Definition config.h:31
#define PERIODSTEP
period increment with 3LSBs needs to be 0 based from PWM FRM with cascaded PWM
Definition config.h:35
#define MINIMUM_DEADTIME
Minimum Deadtime in seconds [sec].
Definition config.h:27
#define PRI_TO_SEC_PHASE_TARGET
Primary to Secondary phase target before switching to period modulation.
Definition config.h:34
#define MAX_PWM_PERIOD
This sets the switching period of the converter.
Definition macros.h:40
#define DEGREES_PHASE_SCALING_10
Definition macros.h:56
#define DEGREES_PHASE_SCALER
Definition macros.h:55
#define MIN_PWM_PERIOD
This sets the switching period of the converter.
Definition macros.h:41
#define MIN_PHASE_SHIFTED_PULSE
Maximum dead time [tick = 250ps].
Definition macros.h:52
#define VPRI_FACTOR
Definition macros.h:135
#define VPRI_SCALER
Definition macros.h:134
#define VSEC_LOAD_STEP_CLAMP
Definition macros.h:115
#define ISEC_LOAD_STEP_CLAMP
Definition macros.h:77
#define VPLOOP_ILOOP_EXE_RATIO
ratio of ILOOP /VPLOOP execution [100KHz / 10KHz], the divide 2 is for interleaved VLoop and PLoop
Definition config.h:44
#define AGC_MINIMUM_VIN_THRESHOLD
Minimum VIN threshold to activate AGC in [V]
Definition config.h:45
#define AGC_CURRENT_FACTOR
Definition macros.h:170
#define AGC_MINIMUM_CURRENT_THRESHOLD
Definition macros.h:169
#define POWER_FACTOR
Definition macros.h:166
#define POWER_SCALER
Definition macros.h:165
#define AGC_VOLTAGE_FACTOR
Definition macros.h:168
POWER_CONTROL_t dab
Global data object for a DAB Converter.
Definition pwrctrl.c:28
void PwrCtrl_ControlLoopExecute(void)
Executes the power converter control loop.
AVERAGING_t iSecAveraging
Data Object of secondary current averaging.
void PwrCtrl_DeadTimeAdjust(void)
This function updates the DAB data members dead time based on load.
static void PwrCtrl_AdaptiveGainUpdate(void)
Updates the Adaptive gain for the power converter control loop.
AVERAGING_t vPrimAveraging
Data Object of primary voltage averaging.
void PwrCtrl_UpdateADConverterData(void)
This function updates the DAB data members with ADC raw values.
void PwrCtrl_10KHzVPLoopPrepareData(void)
This function prepares the data for control loop and selects which control loop will be executed.
void PwrCtrl_PrimToSecPHDegree(void)
This function updates the DAB data members with phase values normalized in degree.
AVERAGING_t vSecAveraging
Data Object of secondary voltage averaging.
SMPS_2P2Z_T PMC_2p2z
Data Object of power mode control.
SMPS_2P2Z_T VMC_2p2z
Data Object of voltage mode control generated by DCDT.
SMPS_2P2Z_T IMC_2p2z
Data Object of current mode control.
@ PWR_CTRL_CHARGING
power converter is in charging mode
@ PWR_CTRL_DISCHARGING
power converter is in discharging mode
static bool ADC1_IsConversionComplete(enum ADC_CHANNEL channel)
This inline function returns the status of conversion.This function is used to determine if conversio...
Definition adc1.h:223
static void ADC1_SoftwareTriggerEnable(void)
This inline function sets software common trigger.
Definition adc1.h:134
static uint16_t ADC1_ConversionResultGet(enum ADC_CHANNEL channel)
Returns the conversion value for the channel selected.
Definition adc1.h:178
#define DPD_TP31_SetHigh()
Sets the RC14 GPIO Pin which has a custom name of DPD_TP31 to High.
Definition pins.h:155
#define DPD_TP31_SetLow()
Sets the RC14 GPIO Pin which has a custom name of DPD_TP31 to Low.
Definition pins.h:164
uint16_t maxOutput
uint16_t KfactorCoeffsB
uint32_t Accumulator
uint16_t AverageValue
uint16_t Counter
uint16_t ControlPhase_P2S_Target
Control phase value from control loop in degrees.
uint16_t ControlPeriod
Control period value from control loop.
uint16_t ControlPhase_P2S_Degreex10
Control phase value from control loop in 10 x degree, integer.
uint16_t DeadTimeHigh
Deadtime High settings for PWM.
uint16_t ControlDutyCycle
Control Duty Cycle calculation based on Control Period.
uint16_t DeadTimeLow
Deadtime High settings for PWM.
uint16_t LowPowerSlowMode
future development
uint16_t ControlPhase
Control phase value from control loop.
uint16_t VPriVoltage
Data value for input voltage.
uint16_t ISecAverageRectified
Data value for average secondary current rectified.
uint16_t ISensePrimary
Data value for primary current as measured with CT.
uint16_t VSecVoltage
Data value for output voltage.
int16_t SecPower
Data value for Secondary power (Watt)
uint16_t ISecAverage
Data value for average secondary current as measured with isolated current sensor.
uint16_t ISecSensorOffset
Offset of the secondary current sensor.
uint16_t ISenseSecondary
Data value for secondary current as measured with CT.
uint16_t VRail_5V
Data value for 5V auxiliary rail.
uint16_t Temperature
Data value for temperature.
unsigned Running
Bit 0: Power converter is running.
uint16_t Output
controller output
bool Enable
Enable control loop.
int16_t Reference
actual reference
uint16_t Feedback
coming
int16_t AgcFactor
Adaptive gain control.
CONTROLLER_t ILoop
structure for current controller data
SWITCH_NODE_t Pwm
Switch node settings.
CONTROLLER_t PLoop
structure for power controller data
CONTROLLER_t VLoop
structure for voltage controller data
FEEDBACK_SETTINGS_t Data
Feedback channel settings.
PWR_CTRL_CHARGE_STATE_t PowerDirection
defines if the power converter is in charging or discharging mode
STATUS_FLAGS_t Status
Power Supply status flags.