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 "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);
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
71{
72 switch (pcInstance->State)
73 {
75 PCS_INIT_handler(pcInstance);
76 break;
77
80 break;
81
83 PCS_STANDBY_handler(pcInstance);
84 break;
85
87 PCS_SOFT_START_handler(pcInstance);
88 break;
89
92 break;
93
94 default:
95 pcInstance->State = PWRCTRL_STATE_INITIALIZE;
96 break;
97 }
98}
99
100
110static void PCS_INIT_handler(POWER_CONTROL_t* pcInstance)
111{
112 #if defined (CURRENT_CALIBRATION) && (CURRENT_CALIBRATION == true)
113 // Execute current sensor offset calibration
115
116 // Checks if the calibration is complete
118 #endif
119 {
120 // Current sensor calibration is complete. Update the offset of the current sensor
122
123 // Ensure PWM output is disabled
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
138 }
139}
140
141
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
176static 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
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
196
197 #if defined (CURRENT_CALIBRATION) && (CURRENT_CALIBRATION == true)
198 // reset the PWM settings in Standby mode
200 // Execute current sensor offset calibration
202 // Checks if the calibration is complete
204 #endif
205 {
207
208 // Enable current control loop
209 pcInstance->ILoop.Enable = true;
210
211 // Update PWM distribution
213
214 // Enable PWM physical output
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
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
248 }
249
250 // Check if Enable bit has been cleared
251 else if (!pcInstance->Properties.Enable)
252 {
253 // Disable PWM physical output
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
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
298 }
299
300 else
301 {
302 // Check if Enable bit has been cleared
303 if (!pcInstance->Properties.Enable)
304 {
305 // Disable PWM physical output
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}
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.
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_Update(POWER_CONTROL_t *pcInstance)
PWM distribution for DAB converter.
Definition pwrctrl_pwm.c:24
void PwrCtrl_PWM_Disable(void)
Disable the PWM output.
void PwrCtrl_PWM_Enable(void)
Enable the PWM output.
Definition pwrctrl_pwm.c:97
void PwrCtrl_StateMachine(POWER_CONTROL_t *pcInstance)
Manages the power control state machine.
Definition pwrctrl_sm.c:70
static void PCS_STANDBY_handler(POWER_CONTROL_t *pcInstance)
Executes Standby State machine.
Definition pwrctrl_sm.c:176
static void PCS_INIT_handler(POWER_CONTROL_t *pcInstance)
Executes function for initialze state machine.
Definition pwrctrl_sm.c:110
static void PCS_UP_AND_RUNNING_handler(POWER_CONTROL_t *pcInstance)
Executes the Online state.
Definition pwrctrl_sm.c:288
static void PCS_WAIT_IF_FAULT_ACTIVE_handler(POWER_CONTROL_t *pcInstance)
Executes the fault handler state machine.
Definition pwrctrl_sm.c:151
static void PCS_SOFT_START_handler(POWER_CONTROL_t *pcInstance)
Executes the power control soft start state machine.
Definition pwrctrl_sm.c:238
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
void Fault_Reset(void)
Clears the fault object flag bits.
Definition fault.c:200
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.
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 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 State ID.
FEEDBACK_SETTINGS_t Data
Feedback channel settings.
STATUS_FLAGS_t Status
Power Supply status flags.
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.