|  | Dual Active Bridge Development Board (Part-No. ) |
Content |  |  |  |  |  |

Loading...
Searching...
No Matches
pwrctrl.c
Go to the documentation of this file.
1
9#include <xc.h>
10
11//MCC header files
12#include "pwm_hs/pwm_hs_types.h"
13#include "pwm_hs/pwm.h"
14
15//DAB header files
16#include "config/macros.h"
17#include "pwrctrl.h"
18#include "fault/fault.h"
19#include "dcdt/pwrctrl_dcdt.h"
20
21
28 POWER_CONTROL_t dab; // Declare DAB converter data structure
29
30// PRIVATE FUNCTIONS
31static void PwrCtrl_StartUpInitialize(void);
32static void PwrCtrl_ControlLoopInitialize(void);
33
34// PUBLIC FUNCTIONS
35extern void PwrCtrl_StateMachine(POWER_CONTROL_t* pcInstance);
36
37
45 void PwrCtrl_Initialize(void)
46{
47 // Clear dab references
48 dab.Properties.VPriReference = 0;
49 dab.Properties.VSecReference = 0;
50 dab.Properties.IReference = 0;
51 dab.Properties.PwrReference = 0;
52
53 // Initialize the Control Period and Control Phase during start-up
54 dab.Pwm.ControlPeriod = MAX_PWM_PERIOD;
55 dab.Pwm.DeadTimeHigh = MINIMUM_DEADTIME;
56 dab.Pwm.DeadTimeLow = MINIMUM_DEADTIME;
57 dab.Pwm.PBVPeriodTarget = MAX_PWM_PERIOD;
58
59 // Initialize the DAB to charging state
60 dab.PowerDirection = PWR_CTRL_CHARGING;
61
62 // Initialize Start-Up ramp settings
63 PwrCtrl_StartUpInitialize();
64
65 // Initialize Power Control Loop
66 PwrCtrl_ControlLoopInitialize();
67
68 // Disable PWM output by setting the PWM override bits to High
69 PwrCtrl_PWM_Disable();
70
71 // Enable PWM peripheral
72 PWM_Enable();
73
74 // Update the Period, Duty Cycle and Phases of the PWMs based on
75 // the given Control period and Control Phase
76 PwrCtrl_PWM_Update(&dab);
77}
78
79
88 void PwrCtrl_Execute(void)
89{
90 // Execute the state machine
91 PwrCtrl_StateMachine(&dab);
92}
93
94
102 void PwrCtrl_Reset(void)
103{
104 //set the period to maximum
105 dab.Pwm.ControlPeriod = MAX_PWM_PERIOD;
106 dab.Pwm.ControlPhase = dab.Pwm.DeadTimeLow;
107 dab.Pwm.PBVPeriodTarget = MAX_PWM_PERIOD;
108 dab.Pwm.PBVControlPhaseTarget = dab.Pwm.DeadTimeLow;
109
110 // Reset the power control references
111 dab.Properties.VPriReference = 0;
112 dab.Properties.VSecReference = 0;
113 dab.Properties.IReference = 0;
114 dab.Properties.PwrReference = 0;
115
116 // Initialize current loop reference to 0, to be controlled externally
117 dab.ILoop.Reference = 0;
118 // Initialize power loop reference to 0, to be controlled externally
119 dab.PLoop.Reference = 0;
120 // Initialize voltage loop reference to current secondary voltage
121 dab.VLoop.Reference = 0;
122
123 // Set the AGC to 1
124 dab.VLoop.AgcFactor = 0x7FFF;
125 dab.ILoop.AgcFactor = 0x7FFF;
126 dab.PLoop.AgcFactor = 0x7FFF;
127
128 // Reset Control Loop Histories
129 PwrCtrl_ResetControlLoopHistories();
130}
131
132
133
141 void PwrCtrl_ControlLoopInitialize(void)
142{
143 // Initialize voltage loop compensator
144 PwrCtrl_VComp_Initialize();
145
146 // Initialize current loop compensator
147 PwrCtrl_IComp_Initialize();
148
149 // Initialize power loop compensator
150 PwrCtrl_PComp_Initialize();
151
152 // Voltage loop properties initialize
153 dab.VLoop.Enable = false;
154 dab.VLoop.AgcFactor = 0x7FFF;
155 dab.VLoop.Feedback = 0;
156 dab.VLoop.Output = 0;
157 dab.VLoop.Reference = 0;
158
159 // Current loop properties initialize
160 dab.ILoop.Enable = false;
161 dab.ILoop.AgcFactor = 0x7FFF;
162 dab.ILoop.Feedback = 0;
163 dab.ILoop.Output = 0;
164 dab.ILoop.Reference = 0;
165
166 // Power loop properties initialize
167 dab.PLoop.Enable = false;
168 dab.PLoop.AgcFactor = 0x7FFF;
169 dab.PLoop.Feedback = 0;
170 dab.PLoop.Output = 0;
171 dab.PLoop.Reference = 0;
172
173}
174
175
186 static void PwrCtrl_StartUpInitialize(void)
187{
188 // Initialize Voltage ramp-up settings
189 dab.VRamp.ptrReference = (uint16_t*)&dab.VLoop.Reference;
190 dab.VRamp.ptrReferenceTarget = &dab.Properties.VSecReference;
191 dab.VRamp.StepSize = 1;
192 dab.VRamp.Delay = 20;
193 dab.VRamp.Counter = 0;
194 dab.VRamp.RampComplete = 0;
195
196 //Initialize Current ramp-up settings
197 dab.IRamp.ptrReference = (uint16_t*)&dab.ILoop.Reference;
198 dab.IRamp.ptrReferenceTarget = (uint16_t*)&dab.Properties.IReference;
199 dab.IRamp.StepSize = 1;
200 dab.IRamp.Delay = 60;
201 dab.IRamp.Counter = 0;
202 dab.IRamp.RampComplete = 0;
203
204 //Initialize Power ramp-up settings
205 dab.PRamp.ptrReference = (uint16_t*)&dab.PLoop.Reference;
206 dab.PRamp.ptrReferenceTarget = &dab.Properties.PwrReference;
207 dab.PRamp.StepSize = 1;
208 dab.PRamp.Delay = 4;
209 dab.PRamp.Counter = 0;
210 dab.PRamp.RampComplete = 0;
211
212 #if defined (OPEN_LOOP_PBV) && (OPEN_LOOP_PBV == true)
213 // The PWM Period bits [2:0] needs to be mask when using cascaded PWM setup
214 // (please refer to Section 4.1.3.3 in High Resolution PWM FRM)
215 uint16_t PeriodMask = 0x7;
216
217 // Initialize Voltage ramp-up settings for Period control
218 dab.Pwm.ControlPeriod = dab.Pwm.ControlPeriod & ~(PeriodMask);
219 dab.Pwm.PBVPeriodTarget = dab.Pwm.PBVPeriodTarget & ~(PeriodMask);
220
221 dab.VRamp.ptrReference = &dab.Pwm.ControlPeriod;
222 dab.VRamp.ptrReferenceTarget = &dab.Pwm.PBVPeriodTarget;
223 dab.VRamp.StepSize = 0xE;
224 dab.VRamp.Delay = 0;
225
226 //Initialize Current ramp-up settings for Phase control
227 dab.Pwm.ControlPhase = dab.Pwm.ControlPhase & ~(PeriodMask);
228 dab.Pwm.PBVControlPhaseTarget = dab.Pwm.PBVControlPhaseTarget & ~(PeriodMask);
229
230 dab.IRamp.ptrReference = &dab.Pwm.ControlPhase;
231 dab.IRamp.ptrReferenceTarget = &dab.Pwm.PBVControlPhaseTarget;
232 dab.IRamp.StepSize = 0xE;
233 dab.IRamp.Delay = 0;
234
235#endif
236}
237
pwm.h
This is the generated driver header file for the PWM driver.
pwm_hs_types.h
This is the generated driver types header file for the PWM driver.
fault.h
Contains public fault functions.
pwrctrl_dcdt.h
Contains public functions and data types relevant for DCDT file interface.
MINIMUM_DEADTIME
#define MINIMUM_DEADTIME
Minimum Deadtime in seconds [sec].
Definition config.h:27
MAX_PWM_PERIOD
#define MAX_PWM_PERIOD
This sets the switching period of the converter.
Definition macros.h:40
PwrCtrl_Initialize
void PwrCtrl_Initialize(void)
Initialize the power control parameters.
Definition pwrctrl.c:45
PwrCtrl_StartUpInitialize
static void PwrCtrl_StartUpInitialize(void)
Initialize the StartUp Ramp configuration.
Definition pwrctrl.c:186
PwrCtrl_Execute
void PwrCtrl_Execute(void)
Executes the power control state machine.
Definition pwrctrl.c:88
dab
POWER_CONTROL_t dab
Global data object for a DAB Converter.
Definition pwrctrl.c:28
PwrCtrl_Reset
void PwrCtrl_Reset(void)
Resets the power control properties.
Definition pwrctrl.c:102
PwrCtrl_ControlLoopInitialize
static void PwrCtrl_ControlLoopInitialize(void)
Initializes the control loop.
Definition pwrctrl.c:141
PwrCtrl_PWM_Update
void PwrCtrl_PWM_Update(POWER_CONTROL_t *pcInstance)
PWM distribution for DAB converter.
Definition pwrctrl_pwm.c:24
PwrCtrl_PWM_Disable
void PwrCtrl_PWM_Disable(void)
Disable the PWM output.
Definition pwrctrl_pwm.c:127
PwrCtrl_StateMachine
void PwrCtrl_StateMachine(POWER_CONTROL_t *pcInstance)
Manages the power control state machine.
Definition pwrctrl_sm.c:70
PwrCtrl_IComp_Initialize
void PwrCtrl_IComp_Initialize(void)
Initialize the Current Loop Control.
Definition pwrctrl_dcdt.c:204
PwrCtrl_PComp_Initialize
void PwrCtrl_PComp_Initialize(void)
Initialize the Power Loop Control.
Definition pwrctrl_dcdt.c:244
PwrCtrl_VComp_Initialize
void PwrCtrl_VComp_Initialize(void)
Initialize the Voltage Loop Control.
Definition pwrctrl_dcdt.c:165
PwrCtrl_ResetControlLoopHistories
void PwrCtrl_ResetControlLoopHistories(void)
Clear the control and error histories of the control loops.
Definition pwrctrl_dcdt.c:282
PWR_CTRL_CHARGING
@ PWR_CTRL_CHARGING
power converter is in charging mode
Definition pwrctrl_typedef.h:136
PWM_Enable
static void PWM_Enable(void)
This inline function will enable all the generators of PWM module.
Definition pwm.h:412
SWITCH_NODE_s::ControlPeriod
uint16_t ControlPeriod
Control period value from control loop.
Definition pwrctrl_typedef.h:37
SWITCH_NODE_s::DeadTimeHigh
uint16_t DeadTimeHigh
Deadtime High settings for PWM.
Definition pwrctrl_typedef.h:42
SWITCH_NODE_s::DeadTimeLow
uint16_t DeadTimeLow
Deadtime High settings for PWM.
Definition pwrctrl_typedef.h:43
SWITCH_NODE_s::PBVPeriodTarget
uint16_t PBVPeriodTarget
Power Board Visualizer Set Control target.
Definition pwrctrl_typedef.h:44
SWITCH_NODE_s::ControlPhase
uint16_t ControlPhase
Control phase value from control loop.
Definition pwrctrl_typedef.h:39
SWITCH_NODE_s::PBVControlPhaseTarget
uint16_t PBVControlPhaseTarget
Power Board Visualizer Set Control phase.
Definition pwrctrl_typedef.h:45
START_UP_RAMP_s::RampComplete
bool RampComplete
indicates when ramp-up is complete
Definition pwrctrl_typedef.h:105
START_UP_RAMP_s::Delay
uint16_t Delay
Soft-Start Period (POD, RAMP PERIOD, PGD, etc.)
Definition pwrctrl_typedef.h:101
START_UP_RAMP_s::ptrReferenceTarget
uint16_t * ptrReferenceTarget
pointer to the ramp-up reference target
Definition pwrctrl_typedef.h:104
START_UP_RAMP_s::ptrReference
uint16_t * ptrReference
pointer the reference variable
Definition pwrctrl_typedef.h:103
START_UP_RAMP_s::Counter
uint16_t Counter
Soft-Start Execution Counter. This setting is set/cleared by the device driver and is 'read only'.
Definition pwrctrl_typedef.h:100
START_UP_RAMP_s::StepSize
uint16_t StepSize
Size/value of one reference increment/decrement or this period.
Definition pwrctrl_typedef.h:102
CONTROLLER_s::Output
uint16_t Output
controller output
Definition pwrctrl_typedef.h:122
CONTROLLER_s::Enable
bool Enable
Enable control loop.
Definition pwrctrl_typedef.h:124
CONTROLLER_s::Reference
int16_t Reference
actual reference
Definition pwrctrl_typedef.h:120
CONTROLLER_s::Feedback
uint16_t Feedback
coming
Definition pwrctrl_typedef.h:121
CONTROLLER_s::AgcFactor
int16_t AgcFactor
Adaptive gain control.
Definition pwrctrl_typedef.h:123
PWR_CTRL_PROPERTIES_s::PwrReference
uint16_t PwrReference
User power reference setting used to control the converter controller.
Definition pwrctrl_typedef.h:153
PWR_CTRL_PROPERTIES_s::IReference
int16_t IReference
User current reference setting used to control the converter controller.
Definition pwrctrl_typedef.h:152
PWR_CTRL_PROPERTIES_s::VPriReference
uint16_t VPriReference
User primary-voltage port reference setting used to control the power converter output voltage in boo...
Definition pwrctrl_typedef.h:151
PWR_CTRL_PROPERTIES_s::VSecReference
uint16_t VSecReference
User secondary-voltage port reference setting used to control the power converter output voltage in b...
Definition pwrctrl_typedef.h:150
POWER_CONTROL_s
Power control API structure.
Definition pwrctrl_typedef.h:167
POWER_CONTROL_s::ILoop
CONTROLLER_t ILoop
structure for current controller data
Definition pwrctrl_typedef.h:177
POWER_CONTROL_s::Pwm
SWITCH_NODE_t Pwm
Switch node settings.
Definition pwrctrl_typedef.h:171
POWER_CONTROL_s::PLoop
CONTROLLER_t PLoop
structure for power controller data
Definition pwrctrl_typedef.h:179
POWER_CONTROL_s::Properties
PWR_CTRL_PROPERTIES_t Properties
Power Control properties
Definition pwrctrl_typedef.h:170
POWER_CONTROL_s::VLoop
CONTROLLER_t VLoop
structure for voltage controller data
Definition pwrctrl_typedef.h:178
POWER_CONTROL_s::PRamp
START_UP_RAMP_t PRamp
Power ramp-up settings.
Definition pwrctrl_typedef.h:176
POWER_CONTROL_s::PowerDirection
PWR_CTRL_CHARGE_STATE_t PowerDirection
defines if the power converter is in charging or discharging mode
Definition pwrctrl_typedef.h:180
POWER_CONTROL_s::VRamp
START_UP_RAMP_t VRamp
Voltage ramp-up settings.
Definition pwrctrl_typedef.h:174
POWER_CONTROL_s::IRamp
START_UP_RAMP_t IRamp
Current ramp-up settings.
Definition pwrctrl_typedef.h:175