|  | 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 "config/macros.h"
38#include "device/device.h"
39#include "fault/fault.h"
40#include "dcdt/pwrctrl_dcdt.h"
41
42//PRIVATE FUNCTIONS
43static void PCS_INIT_handler(POWER_CONTROL_t* pcInstance);
44static void PCS_WAIT_IF_FAULT_ACTIVE_handler(POWER_CONTROL_t* pcInstance);
45static void PCS_STANDBY_handler(POWER_CONTROL_t* pcInstance);
46static void PCS_SOFT_START_handler(POWER_CONTROL_t* pcInstance);
47static void PCS_UP_AND_RUNNING_handler(POWER_CONTROL_t* pcInstance);
48
49
70 void PwrCtrl_StateMachine(POWER_CONTROL_t* pcInstance)
71{
72 switch (pcInstance->State)
73 {
74 case PWRCTRL_STATE_INITIALIZE:
75 PCS_INIT_handler(pcInstance);
76 break;
77
78 case PWRCTRL_STATE_FAULT_DETECTION:
79 PCS_WAIT_IF_FAULT_ACTIVE_handler(pcInstance);
80 break;
81
82 case PWRCTRL_STATE_STANDBY:
83 PCS_STANDBY_handler(pcInstance);
84 break;
85
86 case PWRCTRL_STATE_SOFT_START:
87 PCS_SOFT_START_handler(pcInstance);
88 break;
89
90 case PWRCTRL_STATE_ONLINE:
91 PCS_UP_AND_RUNNING_handler(pcInstance);
92 break;
93
94 default:
95 pcInstance->State = PWRCTRL_STATE_INITIALIZE;
96 break;
97 }
98}
99
100
110 static void PCS_INIT_handler(POWER_CONTROL_t* pcInstance)
111{
112 #if defined (CURRENT_CALIBRATION) && (CURRENT_CALIBRATION == true)
113 // Execute current sensor offset calibration
114 Dev_CurrentSensorOffsetCal();
115
116 // Checks if the calibration is complete
117 if (Dev_CurrentSensor_Get_CalibrationStatus())
118 #endif
119 {
120 // Current sensor calibration is complete. Update the offset of the current sensor
121 pcInstance->Data.ISecSensorOffset = Dev_CurrentSensor_Get_Offset();
122
123 // Ensure PWM output is disabled
124 PwrCtrl_PWM_Disable();
125
126 // Reset fault objects status bits
127 Fault_Reset();
128
129 // Clear power control fault active bit
130 pcInstance->Status.bits.FaultActive = 0;
131 // Clear power control running bit
132 pcInstance->Status.bits.Running = 0;
133 // Clear power control enable bit
134 pcInstance->Properties.Enable = 0;
135
136 // Next State assigned to STATE_FAULT_DETECTION
137 pcInstance->State = PWRCTRL_STATE_FAULT_DETECTION;
138 }
139}
140
141
151 static void PCS_WAIT_IF_FAULT_ACTIVE_handler(POWER_CONTROL_t* pcInstance)
152{
153 if (pcInstance->Fault.FaultDetected == 0)
154 {
155 pcInstance->Status.bits.FaultActive = 0;
156 pcInstance->State = PWRCTRL_STATE_STANDBY; // next state
157 }
158}
159
160
176 static void PCS_STANDBY_handler(POWER_CONTROL_t* pcInstance)
177{
178 // Check for fault event
179 if (pcInstance->Fault.FaultDetected)
180 {
181 // Clear power control enable bit
182 pcInstance->Properties.Enable = 0;
183
184 // State back to STATE_FAULT_DETECTION
185 pcInstance->State = PWRCTRL_STATE_FAULT_DETECTION;
186 }
187
188 // NOTE: Power control enable is controlled externally
189 else if (pcInstance->Properties.Enable)
190 {
191 // Reset fault objects status bits
192 Fault_Reset();
193
194 // Reset the power control properties and control loop histories
195 PwrCtrl_Reset();
196
197 #if defined (CURRENT_CALIBRATION) && (CURRENT_CALIBRATION == true)
198 // reset the PWM settings in Standby mode
199 Dev_CurrentSensor_Clr_Offset();
200 // Execute current sensor offset calibration
201 Dev_CurrentSensorOffsetCal();
202 // Checks if the calibration is complete
203 if (Dev_CurrentSensor_Get_CalibrationStatus())
204 #endif
205 {
206 pcInstance->Data.ISecSensorOffset = Dev_CurrentSensor_Get_Offset();
207
208 // Enable current control loop
209 pcInstance->ILoop.Enable = true;
210
211 // Update PWM distribution
212 PwrCtrl_PWM_Update(&dab);
213
214 // Enable PWM physical output
215 PwrCtrl_PWM_Enable();
216
217 // Enable power control running bit
218 pcInstance->Status.bits.Running = 1;
219
220 // Next State assigned to STATE_SOFT_START
221 pcInstance->State = PWRCTRL_STATE_SOFT_START;
222 }
223 }
224}
225
226
238 static void PCS_SOFT_START_handler(POWER_CONTROL_t* pcInstance)
239{
240 // Check for fault event
241 if (pcInstance->Fault.FaultDetected)
242 {
243 // Clear power control enable bit
244 pcInstance->Properties.Enable = 0;
245
246 // State back to STATE_FAULT_DETECTION
247 pcInstance->State = PWRCTRL_STATE_FAULT_DETECTION;
248 }
249
250 // Check if Enable bit has been cleared
251 else if (!pcInstance->Properties.Enable)
252 {
253 // Disable PWM physical output
254 PwrCtrl_PWM_Disable();
255
256 // Clear power control running bit
257 pcInstance->Status.bits.Running = 0;
258
259 // State back to STATE_STANDBY
260 pcInstance->State = PWRCTRL_STATE_STANDBY;
261 }
262
263 else
264 {
265 // Ramp Up the Voltage, Current and Power reference
266 uint16_t rampComplete = PwrCtrl_RampReference(&pcInstance->VRamp);
267 rampComplete &= PwrCtrl_RampReference(&pcInstance->IRamp);
268 rampComplete &= PwrCtrl_RampReference(&pcInstance->PRamp);
269
270 // Check if ramp up is complete
271 if (rampComplete)
272 // Next State assigned to STATE_ONLINE
273 pcInstance->State = PWRCTRL_STATE_ONLINE;
274
275 }
276}
277
278
288 static void PCS_UP_AND_RUNNING_handler(POWER_CONTROL_t* pcInstance)
289{
290 // Check for fault event
291 if (pcInstance->Fault.FaultDetected)
292 {
293 // Clear power control enable bit
294 pcInstance->Properties.Enable = 0;
295
296 // State back to STATE_FAULT_DETECTION
297 pcInstance->State = PWRCTRL_STATE_FAULT_DETECTION;
298 }
299
300 else
301 {
302 // Check if Enable bit has been cleared
303 if (!pcInstance->Properties.Enable)
304 {
305 // Disable PWM physical output
306 PwrCtrl_PWM_Disable();
307
308 // Clear power control running bit
309 pcInstance->Status.bits.Running = 0;
310
311 // State back to STATE_INITIALIZE
312 pcInstance->State = PWRCTRL_STATE_INITIALIZE;
313 }
314
315 #if defined (OPEN_LOOP_PBV) && (OPEN_LOOP_PBV == true)
316 else if ((pcInstance->Pwm.ControlPeriod & ~(0x7)) != (pcInstance->Pwm.PBVPeriodTarget& ~(0x7)) ||
317 (pcInstance->Pwm.ControlPhase != pcInstance->Pwm.PBVControlPhaseTarget))
318 pcInstance->State = PWRCTRL_STATE_SOFT_START;
319 #endif
320
321 // Check if there is change in power control references
322 else if ((pcInstance->ILoop.Reference != pcInstance->Properties.IReference) ||
323 (pcInstance->VLoop.Reference != pcInstance->Properties.VSecReference) ||
324 (pcInstance->PLoop.Reference != pcInstance->Properties.PwrReference))
325
326 // State back to STATE_SOFT_START
327 pcInstance->State = PWRCTRL_STATE_SOFT_START;
328 }
329}
device.h
Contains h files that are part of device layer.
fault.h
Contains public fault functions.
pwrctrl_dcdt.h
Contains public functions and data types relevant for DCDT file interface.
Dev_CurrentSensor_Get_CalibrationStatus
uint16_t Dev_CurrentSensor_Get_CalibrationStatus(void)
API function to get the calibration status.
Definition dev_current_sensor.c:101
Dev_CurrentSensor_Clr_Offset
void Dev_CurrentSensor_Clr_Offset(void)
API function to clear the sensor offset.
Definition dev_current_sensor.c:121
Dev_CurrentSensor_Get_Offset
uint16_t Dev_CurrentSensor_Get_Offset(void)
API function to get the sensor offset.
Definition dev_current_sensor.c:111
Dev_CurrentSensorOffsetCal
void Dev_CurrentSensorOffsetCal(void)
Measures the currents sensor offset.
Definition dev_current_sensor.c:87
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_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_PWM_Enable
void PwrCtrl_PWM_Enable(void)
Enable the PWM output.
Definition pwrctrl_pwm.c:97
PwrCtrl_StateMachine
void PwrCtrl_StateMachine(POWER_CONTROL_t *pcInstance)
Manages the power control state machine.
Definition pwrctrl_sm.c:70
PCS_STANDBY_handler
static void PCS_STANDBY_handler(POWER_CONTROL_t *pcInstance)
Executes Standby State machine.
Definition pwrctrl_sm.c:176
PCS_INIT_handler
static void PCS_INIT_handler(POWER_CONTROL_t *pcInstance)
Executes function for initialze state machine.
Definition pwrctrl_sm.c:110
PCS_UP_AND_RUNNING_handler
static void PCS_UP_AND_RUNNING_handler(POWER_CONTROL_t *pcInstance)
Executes the Online state.
Definition pwrctrl_sm.c:288
PCS_WAIT_IF_FAULT_ACTIVE_handler
static void PCS_WAIT_IF_FAULT_ACTIVE_handler(POWER_CONTROL_t *pcInstance)
Executes the fault handler state machine.
Definition pwrctrl_sm.c:151
PCS_SOFT_START_handler
static void PCS_SOFT_START_handler(POWER_CONTROL_t *pcInstance)
Executes the power control soft start state machine.
Definition pwrctrl_sm.c:238
PwrCtrl_RampReference
bool PwrCtrl_RampReference(START_UP_RAMP_t *rampUp)
Softly increment / decrement to the set reference target.
Definition pwrctrl_common.c:46
PWRCTRL_STATE_ONLINE
@ PWRCTRL_STATE_ONLINE
power converter control state #4: output is in regulation and power is OK (normal continuous operatio...
Definition pwrctrl_typedef.h:24
PWRCTRL_STATE_STANDBY
@ PWRCTRL_STATE_STANDBY
power converter control state #2: waiting for status bits allowing power supply to run
Definition pwrctrl_typedef.h:22
PWRCTRL_STATE_INITIALIZE
@ PWRCTRL_STATE_INITIALIZE
power converter control state #0: initializes object properties and clears status bits
Definition pwrctrl_typedef.h:20
PWRCTRL_STATE_SOFT_START
@ PWRCTRL_STATE_SOFT_START
power converter control state #3: performs soft-start sequence
Definition pwrctrl_typedef.h:23
PWRCTRL_STATE_FAULT_DETECTION
@ PWRCTRL_STATE_FAULT_DETECTION
power converter control state #1: checks if a fault occurs
Definition pwrctrl_typedef.h:21
Fault_Reset
void Fault_Reset(void)
Clears the fault object flag bits.
Definition fault.c:200
FAULT_SETTINGS_s::FaultDetected
uint16_t FaultDetected
Fault indication for fault occurrence.
Definition fault_typedef.h:41
SWITCH_NODE_s::ControlPeriod
uint16_t ControlPeriod
Control period value from control loop.
Definition pwrctrl_typedef.h:37
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
FEEDBACK_SETTINGS_s::ISecSensorOffset
uint16_t ISecSensorOffset
Offset of the secondary current sensor.
Definition pwrctrl_typedef.h:68
STATUS_FLAGS_s::Running
unsigned Running
Bit 0: Power converter is running.
Definition pwrctrl_typedef.h:82
STATUS_FLAGS_s::FaultActive
unsigned FaultActive
Bit 1: Power converter fault is active.
Definition pwrctrl_typedef.h:83
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
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::Enable
bool Enable
Control Flag: When set, enables the converter triggering a startup sequence; When cleared,...
Definition pwrctrl_typedef.h:156
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::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::State
PWR_CTRL_STATE_t State
Power Control State ID.
Definition pwrctrl_typedef.h:169
POWER_CONTROL_s::Data
FEEDBACK_SETTINGS_t Data
Feedback channel settings.
Definition pwrctrl_typedef.h:172
POWER_CONTROL_s::Status
STATUS_FLAGS_t Status
Power Supply status flags.
Definition pwrctrl_typedef.h:168
POWER_CONTROL_s::Fault
FAULT_SETTINGS_t Fault
Fault flags and settings.
Definition pwrctrl_typedef.h:173
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