Bar Logo Dual Active Bridge Development Board (Part-No. )
 
Content
     
Loading...
Searching...
No Matches
pwrctrl_sm.c
Go to the documentation of this file.
1/*
2 (c) 2024 Microchip Technology Inc. and its subsidiaries. You may use this
3 software and any derivatives exclusively with Microchip products.
4
5 THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
6 EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
7 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
8 PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
9 WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
10
11 IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
12 INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
13 WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
14 BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
15 FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
16 ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
17 THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
18
19 MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
20 TERMS.
21 */
22
30#include <xc.h>
31#include <stdint.h> // include standard integer data types
32#include <stdbool.h> // include standard boolean data types
33#include <stddef.h> // include standard definition data types
34
35// DAB header files
36#include "pwrctrl.h"
37#include "pwm_hs/pwm.h"
38
39#include "config/macros.h"
40#include "device/device.h"
41#include "fault/fault.h"
42#include "dcdt/pwrctrl_dcdt.h"
43
44//PRIVATE FUNCTIONS
45static void PCS_INIT_handler(POWER_CONTROL_t* pcInstance);
47static void PCS_STANDBY_handler(POWER_CONTROL_t* pcInstance);
48static void PCS_SOFT_START_handler(POWER_CONTROL_t* pcInstance);
49static void PCS_UP_AND_RUNNING_handler(POWER_CONTROL_t* pcInstance);
50
51
73{
74 switch (pcInstance->State)
75 {
77 PCS_INIT_handler(pcInstance);
78 break;
79
82 break;
83
85 PCS_STANDBY_handler(pcInstance);
86 break;
87
89 PCS_SOFT_START_handler(pcInstance);
90 break;
91
94 break;
95
96 default:
97 pcInstance->State = PWRCTRL_STATE_INITIALIZE;
98 break;
99 }
100}
101
102
112static void PCS_INIT_handler(POWER_CONTROL_t* pcInstance)
113{
114 PwrCtrl_Initialize();//enforce reinit of all compensators variables to 0, avoid glitches at a new startup
116 PWM_Disable();
117
118 #if defined (CURRENT_CALIBRATION) && (CURRENT_CALIBRATION == true)
119 // Execute current sensor offset calibration
121
122 // Checks if the calibration is complete
124 #endif
125 {
126 // Current sensor calibration is complete. Update the offset of the current sensor
128
129 // Reset fault objects status bits
130 Fault_Reset();
131
132 // Clear power control fault active bit
133 pcInstance->Status.bits.FaultActive = 0;
134 // Clear power control running bit
135 pcInstance->Status.bits.Running = 0;
136 // Clear power control enable bit
137 pcInstance->Properties.Enable = 0;
138
139 // Next State assigned to STATE_FAULT_DETECTION
141 }
142}
143
144
155{
156 if (pcInstance->Fault.FaultDetected == 0)
157 {
158 pcInstance->Status.bits.FaultActive = 0;
159 pcInstance->State = PWRCTRL_STATE_STANDBY; // next state
160 }
161}
162
163
179static void PCS_STANDBY_handler(POWER_CONTROL_t* pcInstance)
180{
181 // Check for fault event
182 if (pcInstance->Fault.FaultDetected)
183 {
184 // Clear power control enable bit
185 pcInstance->Properties.Enable = 0;
186
187 // State back to STATE_FAULT_DETECTION
189 }
190
191 // NOTE: Power control enable is controlled externally
192 else if (pcInstance->Properties.Enable)
193 {
194 // Reset fault objects status bits
195 Fault_Reset();
196
198 // Reset the power control properties and control loop histories
200
201 #if defined (CURRENT_CALIBRATION) && (CURRENT_CALIBRATION == true)
202 // reset the PWM settings in Standby mode
204 // Execute current sensor offset calibration
206 // Checks if the calibration is complete
208 #endif
209 {
211
212 // Enable current control loop
213 pcInstance->ILoop.Enable = true;
214
215 // Update PWM distribution
217
218 // Enable PWM physical output
220
221 // Enable power control running bit
222 pcInstance->Status.bits.Running = 1;
223
224 // Next State assigned to STATE_SOFT_START
225 pcInstance->State = PWRCTRL_STATE_SOFT_START;
226
227
228
230 {
232 }
233 else
234 {
236 }
237
238
239
240 }
241 }
242}
243
244
257{
258 // Check for fault event
259 if (pcInstance->Fault.FaultDetected)
260 {
261 // Clear power control enable bit
262 pcInstance->Properties.Enable = 0;
263
264 // State back to STATE_FAULT_DETECTION
266 }
267
268 // Check if Enable bit has been cleared
269 else if (!pcInstance->Properties.Enable)
270 {
271 // Disable PWM physical output
273
274 // Clear power control running bit
275 pcInstance->Status.bits.Running = 0;
276
277 // State back to STATE_STANDBY
278 pcInstance->State = PWRCTRL_STATE_STANDBY;
279 }
280
281 else
282 {
283 // Ramp Up the Voltage, Current and Power reference
284 uint16_t rampComplete = PwrCtrl_RampReference(&pcInstance->VRamp);
285 rampComplete &= PwrCtrl_RampReference(&pcInstance->IRamp);
286 rampComplete &= PwrCtrl_RampReference(&pcInstance->PRamp);
287
288 // Check if ramp up is complete
289 if (rampComplete)
290 // Next State assigned to STATE_ONLINE
291 pcInstance->State = PWRCTRL_STATE_ONLINE;
292
293 }
294}
295
296
307{
308 // Check for fault event
309 if (pcInstance->Fault.FaultDetected)
310 {
311 // Clear power control enable bit
312 pcInstance->Properties.Enable = 0;
313
314 // State back to STATE_FAULT_DETECTION
316 }
317
318 else
319 {
320 // Check if Enable bit has been cleared
321 if (!pcInstance->Properties.Enable)
322 {
323 // Disable PWM physical output
325
326 // Clear power control running bit
327 pcInstance->Status.bits.Running = 0;
328
329 // State back to STATE_INITIALIZE
330 pcInstance->State = PWRCTRL_STATE_INITIALIZE;
331 }
332
333 #if defined (OPEN_LOOP_PBV) && (OPEN_LOOP_PBV == true)
334 else if ((pcInstance->Pwm.ControlPeriod & ~(0x7)) != (pcInstance->Pwm.PBVPeriodTarget& ~(0x7)) ||
335 (pcInstance->Pwm.ControlPhase != pcInstance->Pwm.PBVControlPhaseTarget))
336 pcInstance->State = PWRCTRL_STATE_SOFT_START;
337 #endif
338 // Check if there is change in power control references
339 else
340 {
342 {
343 if ((pcInstance->ILoop.Reference != pcInstance->Properties.IReference) ||
344 (pcInstance->VLoop.Reference != pcInstance->Properties.VSecReference) ||
345 (pcInstance->PLoop.Reference != pcInstance->Properties.PwrReference))
346 // State back to STATE_SOFT_START
347 pcInstance->State = PWRCTRL_STATE_SOFT_START;
348 }
350 {
351 if ((pcInstance->ILoop.Reference != pcInstance->Properties.IReference) ||
352 (pcInstance->VLoop.Reference != pcInstance->Properties.VPriReference) ||
353 (pcInstance->PLoop.Reference != pcInstance->Properties.PwrReference))
354 // State back to STATE_SOFT_START
355 pcInstance->State = PWRCTRL_STATE_SOFT_START;
356 }
357 }
358 }
359}
This is the generated driver header file for the PWM driver.
Contains h files that are part of device layer.
Contains public fault functions.
Contains public functions and data types relevant for DCDT file interface.
uint16_t Dev_CurrentSensor_Get_CalibrationStatus(void)
API function to get the calibration status.
void Dev_CurrentSensor_Clr_Offset(void)
API function to clear the sensor offset.
uint16_t Dev_CurrentSensor_Get_Offset(void)
API function to get the sensor offset.
void Dev_CurrentSensorOffsetCal(void)
Measures the currents sensor offset.
void PwrCtrl_Initialize(void)
Initialize the power control parameters.
Definition pwrctrl.c:45
POWER_CONTROL_t dab
Global data object for a DAB Converter.
Definition pwrctrl.c:28
void PwrCtrl_Reset(void)
Resets the power control properties.
Definition pwrctrl.c:102
void PwrCtrl_PWM_DAB_DirectionSpecificSwapCfg(PWR_CTRL_CHARGE_STATE_t direction)
Forward/Reverse Direction related swap pattern on PWM output.
void PwrCtrl_PWM_Update(POWER_CONTROL_t *pcInstance)
PWM distribution for DAB converter.
Definition pwrctrl_pwm.c:25
void PwrCtrl_PWM_Disable(void)
Disable the PWM output.
void PwrCtrl_PWM_Enable(void)
Enable the PWM output.
void PwrCtrl_StateMachine(POWER_CONTROL_t *pcInstance)
Manages the power control state machine.
Definition pwrctrl_sm.c:72
static void PCS_STANDBY_handler(POWER_CONTROL_t *pcInstance)
Executes Standby State machine.
Definition pwrctrl_sm.c:179
static void PCS_INIT_handler(POWER_CONTROL_t *pcInstance)
Executes function for initialze state machine.
Definition pwrctrl_sm.c:112
static void PCS_UP_AND_RUNNING_handler(POWER_CONTROL_t *pcInstance)
Executes the Online state.
Definition pwrctrl_sm.c:306
static void PCS_WAIT_IF_FAULT_ACTIVE_handler(POWER_CONTROL_t *pcInstance)
Executes the fault handler state machine.
Definition pwrctrl_sm.c:154
static void PCS_SOFT_START_handler(POWER_CONTROL_t *pcInstance)
Executes the power control soft start state machine.
Definition pwrctrl_sm.c:256
bool PwrCtrl_RampReference(START_UP_RAMP_t *rampUp)
Softly increment / decrement to the set reference target.
@ PWRCTRL_STATE_ONLINE
power converter control state #4: output is in regulation and power is OK (normal continuous operatio...
@ PWRCTRL_STATE_STANDBY
power converter control state #2: waiting for status bits allowing power supply to run
@ PWRCTRL_STATE_INITIALIZE
power converter control state #0: initializes object properties and clears status bits
@ PWRCTRL_STATE_SOFT_START
power converter control state #3: performs soft-start sequence
@ PWRCTRL_STATE_FAULT_DETECTION
power converter control state #1: checks if a fault occurs
@ PWR_CTRL_CHARGING
power converter is in charging mode
@ PWR_CTRL_DISCHARGING
power converter is in discharging mode
void Fault_Reset(void)
Clears the fault object flag bits.
Definition fault.c:248
static void PWM_Disable(void)
This inline function will disable all the generators of PWM module.
Definition pwm.h:426
uint16_t FaultDetected
Fault indication for fault occurrence.
uint16_t ControlPeriod
Control period value from control loop.
uint16_t PBVPeriodTarget
Power Board Visualizer Set Control target.
uint16_t ControlPhase
Control phase value from control loop.
uint16_t PBVControlPhaseTarget
Power Board Visualizer Set Control phase.
uint16_t ISecSensorOffset
Offset of the secondary current sensor.
unsigned Running
Bit 0: Power converter is running.
unsigned FaultActive
Bit 1: Power converter fault is active.
uint16_t * ptrReferenceTarget
pointer to the ramp-up reference target
bool Enable
Enable control loop.
int16_t Reference
actual reference
uint16_t PwrReference
User power reference setting used to control the converter controller.
bool Enable
Control Flag: When set, enables the converter triggering a startup sequence; When cleared,...
int16_t IReference
User current reference setting used to control the converter controller.
uint16_t VPriReference
User primary-voltage port reference setting used to control the power converter output voltage in boo...
uint16_t VSecReference
User secondary-voltage port reference setting used to control the power converter output voltage in b...
Power control API structure.
CONTROLLER_t ILoop
structure for current controller data
SWITCH_NODE_t Pwm
Switch node settings.
CONTROLLER_t PLoop
structure for power controller data
PWR_CTRL_PROPERTIES_t Properties
Power Control properties
CONTROLLER_t VLoop
structure for voltage controller data
START_UP_RAMP_t PRamp
Power ramp-up settings.
PWR_CTRL_STATE_t State
Power Control SM State ID.
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.
FAULT_SETTINGS_t Fault
Fault flags and settings.
START_UP_RAMP_t VRamp
Voltage ramp-up settings.
START_UP_RAMP_t IRamp
Current ramp-up settings.