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 // Averaging of Primary Voltage
128
129 #if(OPEN_LOOP_PBV == false)
130 //Condition for control loop execution controlling the loop enable bit
131 if((dab.VLoop.Enable == false) && (VLoopInterleaveExec == true) && (dab.Status.bits.Running == 1))
132 #endif
133 {
134 // Enable Vloop control
135 dab.VLoop.Enable = true;
136 dab.PLoop.Enable = false;
137 // Compute the Adaptive Gain
139 }
140
141 #if(OPEN_LOOP_PBV == false)
142 else if((dab.PLoop.Enable == false) && (VLoopInterleaveExec == false) && (dab.Status.bits.Running == 1))
143 #endif
144 {
145 // Enable PLoop control
146 dab.VLoop.Enable = false;
147 dab.PLoop.Enable = true;
148
149 // Averaging of Secondary Current
153
154 // Bit-shift value used to perform input value normalization
155 // Scaled the feedback to Power (Watts in units)
156 uint32_t buf = (uint32_t)iSecAveraging.AverageValue *
158
159 // scale back the 14 bit from the POWER_RESOLUTION calculation
160 // to get the Watts value for Power Loop
161 buf >>= POWER_SCALER;
162
163 // Transfer to SecPower data member the power computation in [Watts]
164 dab.Data.SecPower = buf;
165
166 }
167
168 // If Power supply is not yet running, the averaging of
169 // primary voltage and secondary voltage continues to display in PBV
170 if(!dab.Status.bits.Running){
171
172 // Averaging of Secondary Current
176
177 // Bit-shift value used to perform input value normalization
178 // Scaled the feedback to Power (Watts in units)
179 uint32_t buf = (uint32_t)iSecAveraging.AverageValue *
181
182 // scale back the 14 bit from the POWER_RESOLUTION calculation
183 // to get the Watts value for Power Loop
184 buf >>= POWER_SCALER;
185
186 // Transfer to SecPower data member the power computation in [Watts]
187 dab.Data.SecPower = buf;
188 }
189 cnt = 0;
190 }
191}
192
193
206
213#define MIN_REFERENCE_THRESHOLD_IV (10)//roughly 300mA
214#define MIN_REFERENCE_THRESHOLD_P (15)//
215#define PIRM_MIN_VOLTAGE_55V (250)
216#define PRIMARY_VOLTAGE_MODE_SENSOR_SAFE_CHECK() do { \
217 if (dab.Properties.IReference > MIN_REFERENCE_THRESHOLD_IV) \
218 if (dab.Properties.VPriReference > MIN_REFERENCE_THRESHOLD_IV) \
219 if (dab.Properties.PwrReference > MIN_REFERENCE_THRESHOLD_P) \
220 if (vPrimAveraging.AverageValue < PIRM_MIN_VOLTAGE_55V) { \
221 dab.Properties.IReference = MIN_REFERENCE_THRESHOLD_IV; \
222 dab.ILoop.Reference = MIN_REFERENCE_THRESHOLD_IV; \
223 dab.Properties.PwrReference = MIN_REFERENCE_THRESHOLD_P; \
224 dab.PLoop.Reference = MIN_REFERENCE_THRESHOLD_P; \
225 } \
226} while (0)
227
229{
230
231 // Execute the Voltage Loop Control
232 if((dab.VLoop.Enable == true) && (VLoopInterleaveExec == true))
233 {
234 VLoopInterleaveExec = false;
235
237 {
238 VMC_2p2z.KfactorCoeffsB = 0x7FFF;
239 VMC_2p2z.maxOutput = 0x7FFF;
240
241 // Bit-shift value used to perform input value normalization
244
245 // Execute the Voltage Loop Control
247
248 // Reset the Vloop reference to its original scaling
250 }
251
253 {
255 VMC_2p2z_Rev.maxOutput = 0x7FFF;
256
257 // Bit-shift value used to perform input value normalization
259 dab.VLoop.Reference = (dab.VLoop.Reference << 3);//should be limited range or even fixed for GTI input
260
261 // Execute the Voltage Loop Control
264
265 // Reset the Vloop reference to its original scaling
267 }
268 }
269
270
271 // Execute the Power Loop Control
272 if((dab.PLoop.Enable == true) && (VLoopInterleaveExec == false))
273 {
275 {
276 VLoopInterleaveExec = true;
277
280
281 // Execute the Power Loop Control
284 }
285
287 {
288 VLoopInterleaveExec = true;
289
292
293 // Execute the Power Loop Control
296 }
297 }
298
299 // Execute the Current Loop Control
300 if(dab.ILoop.Enable == true)
301 {
302 DPD_TP31_SetHigh();//Test/dbg purpose only
303 //Bit-shift value used to perform input value normalization
305 //adaptive gain factor
308 //refresh limits
309 IMC_2p2z.maxOutput = 0x7FFF;
310
312 {
313 // Mixing stage from voltage loop 10KHz
314 uint32_t RefBuf = (uint32_t)(dab.ILoop.Reference) * (uint32_t)(dab.VLoop.Output & 0x7FFF);
315 uint16_t ILoopReference = (uint16_t)(RefBuf >> 12);
316
317 // Mixing stage from power loop 10KHz
318 RefBuf = (uint32_t)ILoopReference * (uint32_t)(dab.PLoop.Output & 0x7FFF);
319 ILoopReference = (int16_t)(RefBuf >> 15);
320
321 // Basic clamping in rising direction, in case of Iloop or Vloop overshoot during large load step.
323 {
325 }
326 else
328 {
330 }
331 else
332 {
334 }
335 }
336
338 {
340
341 // Mixing stage from voltage loop 10KHz
342 uint32_t RefBuf = (uint32_t)(dab.ILoop.Reference) * (uint32_t)(dab.VLoop.Output & 0x7FFF);
343 uint16_t ILoopReference = (uint16_t)(RefBuf >> 12);
344
345 // Mixing stage from power loop 10KHz
346 RefBuf = (uint32_t)ILoopReference * (uint32_t)(dab.PLoop.Output & 0x7FFF);
347 ILoopReference = (int16_t)(RefBuf >> 15);
348
349 // Basic clamping in rising direction, in case of Iloop or Vloop overshoot during large load step.
351 {
353 }
354 else
356 {
357 XFT_SMPS_Controller2P2ZUpdate(&IMC_2p2z_Rev, &dab.ILoop.Feedback, 0, &dab.ILoop.Output);//force I ref to 0, clipping V
358 }
359 else
360 {
362 }
363 }
364
365 // Control loop output mapped to control phase. Normalized to Duty Cycle value
366 dab.Pwm.ControlPhase = (((uint32_t)(dab.Pwm.ControlDutyCycle) *
367 (uint32_t)dab.ILoop.Output) >> 15); //range 0..180
369
370 // Clamping value of maximum control phase
371 if(dab.Pwm.ControlPhase > (dab.Pwm.ControlDutyCycle - MAXIMUM_DEADTIME))//MIN_PHASE_SHIFTED_PULSE))
372 dab.Pwm.ControlPhase = dab.Pwm.ControlDutyCycle - MAXIMUM_DEADTIME;//MIN_PHASE_SHIFTED_PULSE;
373
374 // Clamping value of minimum control phase
377
378 DPD_TP31_SetLow();//Test/dbg purpose only
379 }
380}
381
382
392{
393
395 {
396 // Calculate the primary voltage in terms of Volts
397 uint16_t DAB_PrimaryVoltage = __builtin_divud((vPrimAveraging.AverageValue * VPRI_SCALER), VPRI_FACTOR);
398
399 // Apply AGC when primary voltage is greater than the minimum VIN AGC threshold
400 if(DAB_PrimaryVoltage > AGC_MINIMUM_VIN_THRESHOLD)
401 dab.ILoop.AgcFactor = (int16_t) (0x7FFF &
402 __builtin_divud(AGC_VOLTAGE_FACTOR, DAB_PrimaryVoltage));
403 else // AGC is not active
404 dab.ILoop.AgcFactor = 0x7FFF;
405 }
406
407
409 {
410 // Calculate the secondary voltage in terms of Volts
411 uint16_t DAB_SecondaryVoltage = __builtin_divud((vSecAveraging.AverageValue * VSEC_SCALER), VSEC_FACTOR);
412
413 // Apply AGC when secondary voltage is greater than the minimum VIN AGC threshold
414 if(DAB_SecondaryVoltage > AGC_MINIMUM_VIN_THRESHOLD_SEC)
415 dab.ILoop.AgcFactor = (int16_t) (0x7FFF &
416 __builtin_divud(AGC_VOLTAGE_FACTOR_SEC, DAB_SecondaryVoltage));
417 else // AGC is not active
418 dab.ILoop.AgcFactor = 0x7FFF;
419 }
420}
421
422
423
433{
434 // Calculation of Primary and Secondary degrees phase
435 // Normalize phase to 0..90.
436 uint32_t buff = ((unsigned long)dab.Pwm.ControlPhase) << DEGREES_PHASE_SCALER;
437 uint16_t buf = __builtin_divud( buff ,dab.Pwm.ControlDutyCycle);
438 buff = __builtin_muluu(buf, PRI_TO_SEC_PHASE_DEGREES_LIMIT);
439 buf = __builtin_divud( buff ,DEGREES_PHASE_SCALING_10);
440
441 // Calculation result for phase value scaled by 10x
443
444 // Clamping value for degrees phase when it exceeds the 90.0 degrees
446 {
447 // Override the calculated control phase value
449 }
450}
451
452
461{
462 uint16_t NewDT = 0;
463
464 // Deadtime values adjusted on rough phase range. experimentally measured values.
465 // If the control phase is less than 29.0 degrees phase
467 {NewDT = 2000;} // Equivalent to 500ns DeadTime
468 // If the control phase is within the range of 33.0 and 80.0 degrees phase
470 {NewDT = 1500;} // Equivalent to 375ns DeadTime
471 // If the control phase is within the range of 80.5 and 87.5 degrees phase
473 {NewDT = 700;} // Equivalent to 175ns DeadTime
474 // If the control phase is greater than 88.0 degrees phase
475 else if (dab.Pwm.ControlPhase_P2S_Degreex10 > 880)
476 {NewDT = 600;} // Equivalent to 150ns DeadTime
477
478 // When new dead-time did not satisfy any condition in degrees phase
479 //retain the previous dead-time value
480 if(NewDT)
481 {
482 // Minimum clamping value of dead-time
483 if (NewDT < MINIMUM_DEADTIME)
484 NewDT = MINIMUM_DEADTIME;
485
486 // Write the new dead-time to the PWM
487 dab.Pwm.DeadTimeLow = NewDT;
488 dab.Pwm.DeadTimeHigh = NewDT;
489
490 // Clear NewDT variable
491 NewDT=0;
492 }
493}
494
495#if defined (PERIOD_MODULATION_DEMO) && (PERIOD_MODULATION_DEMO == true)
496
504{
505 static uint16_t decimPM;
506 decimPM++;
507
509 dab.Pwm.ControlPhase_P2S_Target = PRI_TO_SEC_PHASE_TARGET;//clamp cutoff while modulating period
512
513 if(decimPM>=8)
514 {
516 {
518 {
520 }
521 else
522 {
523 // When phase shift between primary to secondary is 68 degrees,
524 // DAB runs in low power mode
526 {
528 }
529 }
530 }
531
533 {
535 {
537 }
538 }
539
540 if(dab.Pwm.LowPowerSlowMode == 1)
541 {
543 {
545 }
546 else
547 {
549 {
551 }
552 else
553 if (dab.Pwm.ControlPhase_P2S_Degreex10 > 440 )//snap out
554 {
556 }
557 }
558 }
559 decimPM=0;
560 }
561}
562
563#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)
#define PRIMARY_VOLTAGE_MODE_SENSOR_SAFE_CHECK()
void PwrCtrl_ControlLoopExecute(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 MAXIMUM_DEADTIME
Maximum Deadtime in seconds [sec].
Definition config.h:28
#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 VPRIM_LOAD_STEP_CLAMP
Definition macros.h:135
#define VPRI_FACTOR
Definition macros.h:138
#define VPRI_SCALER
Definition macros.h:137
#define VSEC_FACTOR
Definition macros.h:118
#define VSEC_SCALER
Definition macros.h:117
#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_SEC
Minimum VIN secondary threshold to activate AGC reverse mode in [V]
Definition config.h:47
#define AGC_MINIMUM_VIN_THRESHOLD
Minimum VIN threshold to activate AGC in [V]
Definition config.h:45
#define POWER_FACTOR
Definition macros.h:169
#define POWER_SCALER
Definition macros.h:168
#define AGC_VOLTAGE_FACTOR
Definition macros.h:171
#define AGC_VOLTAGE_FACTOR_SEC
Definition macros.h:172
POWER_CONTROL_t dab
Global data object for a DAB Converter.
Definition pwrctrl.c:28
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 VMC_2p2z_Rev
Data Object of voltage mode control generated by DCDT.
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 PMC_2p2z_Rev
Data Object of power mode control.
SMPS_2P2Z_T IMC_2p2z_Rev
Data Object of current mode control.
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, running or fault.