Bar Logo Dual Active Bridge Development Board (Part-No. )
 
Content
     
Loading...
Searching...
No Matches
fault.c
Go to the documentation of this file.
1
9#include "xc.h"
10#include <stdbool.h>
11#include <stddef.h>
12
13#include "cmp/cmp1.h"
14#include "cmp/cmp3.h"
15#include "pwm_hs/pwm.h"
16#include "system/pins.h"
17
18#include "config/macros.h"
19#include "device/device.h"
20#include "pwrctrl/pwrctrl.h"
21#include "fault_common.h"
22#include "fault.h"
24#include "../driver/mcc_extension/drv_mcc_extension_pwm.h"
25
26// PRIVATE FUNCTIONS
28
29bool loadDisconnect = false;
30
31
42void Fault_Handler(void)
43{
44 // Drive the fault pin to Low when Fault trips
46
47 // Turn off PWM output
49
50 // set the fault active bit
51 dab.Status.bits.FaultActive = 1;
52
53 // clear the running bit
54 dab.Status.bits.Running = 0;
55
56}
57
58
67{
68 // Initialize Primary Over Current Protection
71
72 // Initialize Secondary Over Current Protection
75
76 // Initialize Primary Over Voltage Protection
79
80 // Initialize Primary Over Voltage Protection
83
84 // Initialize Secondary Over Voltage Protection
87
88 // Initialize Secondary Over Voltage Protection
91
92 // Initialize 5V Rail instability Protection
95
96 // Initialize Over Temperature Protection
99
100#if defined (FAULT_SHORT_CCT) && (FAULT_SHORT_CCT == true)
101 // Initialize short circuit fault protection with comparators
103#endif
104
105}
106
107
117{
118 uint16_t faultCheck = 0;
119 // secondary over current fault handler
120 #if defined(FAULT_ISEC_OC) && (FAULT_ISEC_OC == true)
122 #endif
123
124 // secondary over voltage fault handler
125 #if defined(FAULT_VSEC_OV) && (FAULT_VSEC_OV == true)
127 #endif
128
129 // primary over current fault handler
130 #if defined (FAULT_IPRI_OC) && (FAULT_IPRI_OC == true)
132 #endif
133
134 // primary over voltage fault handler
135 #if defined(FAULT_VPRI_OV) && (FAULT_VPRI_OV == true)
137 #endif
138
139 // primary over voltage fault handler
140 #if defined(FAULT_VPRI_UV) && (FAULT_VPRI_UV == true)
142 #endif
143
144 // primary over voltage fault handler
145 #if defined(FAULT_VRAIL_5V) && (FAULT_VRAIL_5V == true)
147 #endif
148
149 // Hardware short circuit
150// if(CMP1_StatusGet() || CMP3_StatusGet()){
151//
152// Fault_Handler();
153//
154// // Set fault bits
155// dab.Fault.Object.ISenseSCP.FaultActive = 1;
156// dab.Fault.Object.ISenseSCP.FaultLatch = 1;
157//
158// faultCheck &= dab.Fault.Object.ISenseSCP.FaultActive;
159// }
160
161
162 //sometimes the comparator state changes back to 0 by the time it is read by fault controller code
163 //it is still captured inside PWM generator as fault signal.
164 //act on this signal if detected, as generic Short Circuit detection fault.
165 //PWM signals are already turned off by HW, so adjust SW flow accordingly
166 if(FAULT_ACTIVE)
167 {
169
170 // Set fault bits
173
174 faultCheck &= dab.Fault.Object.ISenseSCP.FaultActive;
175 }
176
177
178 //check OC comparator and set fault signals if needed
179 if(CMP3_StatusGet() )
180 {
182
183 // Set fault bits
186
187 faultCheck &= dab.Fault.Object.IPrimaryOCP.FaultActive;
188 }
189 //check OC comparator and set fault signals if needed
190 if(CMP1_StatusGet())
191 {
193
194 // Set fault bits
197
199 }
200
201 #if defined (LOAD_DISCONNECT) && (LOAD_DISCONNECT == true)
202 // Protection when Load is removed by accident.
203 //DAB does not sink power in this modulation. Voltage builds up on output.
204 if(dab.State==PWRCTRL_STATE_ONLINE)//ignore all other transient or off states
205 {
207 {
210 (dab.Properties.IReference >= 3) &&
212 )
213 {
214 loadDisconnect = true;
216 }
217 }
219 {
222 (dab.Properties.IReference >= 3) &&
224 )
225 {
226 loadDisconnect = true;
228 }
229 }
230 }
231 #endif
232
233 dab.Status.bits.FaultActive = faultCheck;
234
235 // Identify the fault that trips
237}
238
239
240
248void Fault_Reset(void)
249{
250 // Drive the fault pin to high to allow PWM signal drive
252
253 // Clear fault Objects FaultActive bit
261
262 // Clear fault Objects FaultLatch bit
270
271 loadDisconnect = false;
272
273 dab.Status.bits.FaultActive = 0;
274}
275
276
286{
287 // on dsPIC33CK DP-PIM:
288 // CMP1B used for short circuit protection on the secondary side
289 // CMP3B used for short circuit protection on the primary side
290
291 // initialize thresholds of comparators used for short circuit protection
294
295 // turn on comparator DACs
298
299}
300
301
312{
313 #if defined (FAULT_PS_OTP) && (FAULT_PS_OTP == true)
315 {
316 devTempData.OverTemperatureFlag = 1; //for over temperature
317 dab.Status.bits.FaultActive = 1;
318 }
319 else
320 {
321 devTempData.OverTemperatureFlag = 0; //for over temperature
322 dab.Status.bits.FaultActive = 0;
323 }
324 #endif
325}
This is the generated driver header file for the CMP1 driver.
This is the generated driver header file for the CMP3 driver.
This is the generated driver header file for the PWM driver.
Contains h files that are part of device layer.
bool loadDisconnect
Definition fault.c:29
Contains public fault functions.
Contains fault generic public functions.
uint16_t Fault_GetFlags(void)
Contains API functions for fault protection.
#define VPRI_OV_T_BLANK_TRIG
Definition macros.h:127
#define VPRIM_LOAD_STEP_CLAMP
Definition macros.h:135
#define VPRI_OV_THRES_TRIG
Definition macros.h:125
#define VPRI_OV_T_BLANK_CLEAR
Definition macros.h:128
#define VPRI_OV_THRES_CLEAR
Definition macros.h:126
#define VSEC_OV_THRES_TRIG
Definition macros.h:105
#define VSEC_OV_T_BLANK_TRIG
Definition macros.h:107
#define VSEC_OV_THRES_CLEAR
Definition macros.h:106
#define VSEC_LOAD_STEP_CLAMP
Definition macros.h:115
#define VSEC_OV_T_BLANK_CLEAR
Definition macros.h:108
#define IPRI_OC_THRES_CLEAR
Definition macros.h:93
#define IPRI_SC_THRES_TRIG
Definition macros.h:97
#define IPRI_OC_T_BLANK_CLEAR
Definition macros.h:95
#define IPRI_OC_THRES_TRIG
Definition macros.h:92
#define IPRI_OC_T_BLANK_TRIG
Definition macros.h:94
#define ISEC_OC_THRES_CLEAR
Definition macros.h:72
#define ISEC_SC_THRES_TRIG
Definition macros.h:76
#define ISEC_OC_T_BLANK_CLEAR
Definition macros.h:74
#define ISEC_LOAD_STEP_CLAMP
Definition macros.h:77
#define ISEC_OC_THRES_TRIG
Definition macros.h:71
#define ISEC_OC_T_BLANK_TRIG
Definition macros.h:73
#define VRAIL_5V_UV_T_BLANK_CLEAR
Definition macros.h:149
#define VRAIL_5V_UV_T_BLANK_TRIG
Definition macros.h:148
#define VRAIL_5V_UV_THRES_TRIG
Definition macros.h:146
#define VRAIL_5V_UV_THRES_CLEAR
Definition macros.h:147
#define FAULT_PERSISTENCE_COUNT_TEMP
Definition config.h:170
#define OTP_THRES_TRIG_CELCIUS
Degrees Celcius.
Definition config.h:168
#define OTP_THRES_CLEAR_CELCIUS
Degrees Celcius.
Definition config.h:169
TEMP_SETTINGS_t devTempData
Data Object of temperature settings.
Definition dev_temp.c:30
int8_t Dev_Temp_Get_Temperature_Celcius(void)
This converts the raw values to temperature celcius as per device lookup table.
Definition dev_temp.c:87
#define FAULT_ACTIVE
Checks if there is any fault PCI occurred.
POWER_CONTROL_t dab
Global data object for a DAB Converter.
Definition pwrctrl.c:28
AVERAGING_t iSecAveraging
Data Object of secondary current averaging.
AVERAGING_t vPrimAveraging
Data Object of primary voltage averaging.
AVERAGING_t vSecAveraging
Data Object of secondary voltage averaging.
void PwrCtrl_PWM_Disable(void)
Disable the PWM output.
@ PWRCTRL_STATE_ONLINE
power converter control state #4: output is in regulation and power is OK (normal continuous operatio...
@ PWR_CTRL_CHARGING
power converter is in charging mode
@ PWR_CTRL_DISCHARGING
power converter is in discharging mode
void Fault_Execute_100ms(void)
Fault evaluation for Temperature and other slow fault detection executed every 100ms.
Definition fault.c:311
void Fault_Reset(void)
Clears the fault object flag bits.
Definition fault.c:248
static void Fault_EnableShortCircuitProtection(void)
Enable Short circuit hardware protection.
Definition fault.c:285
void Fault_Initialize(void)
Initialize the fault objects.
Definition fault.c:66
void Fault_Execute(void)
Executes the fault handlers.
Definition fault.c:116
void Fault_Handler(void)
Handles the fault trip by turning off the power control switching.
Definition fault.c:42
bool FAULT_CheckMax(FAULT_OBJ_T *faultInput, int16_t faultSource, FAULT_CALLBACK callback)
This function compares the fault source value with the threshold limits and sets (or) resets the faul...
bool FAULT_CheckMin(FAULT_OBJ_T *faultInput, int16_t faultSource, FAULT_CALLBACK callback)
This function compares the fault source value with the threshold limits and sets (or) resets the faul...
void FAULT_Init(FAULT_OBJ_T *faultInput, int16_t threshold, int16_t hysLimit, uint16_t thresholdCnt, uint32_t hysCnt)
This function initializes the fault object data structure with the values that required to detect a f...
bool CMP3_StatusGet(void)
Returns the comparator output status.
Definition cmp3.c:111
#define CMP_IPRI_SC_DACDataWrite
This macro defines the Custom Name for CMP3_DACDataWrite API.
Definition cmp3.h:100
bool CMP1_StatusGet(void)
Returns the comparator output status.
Definition cmp1.c:111
#define CMP_IPRI_SC_DACEnable
This macro defines the Custom Name for CMP3_DACEnable API.
Definition cmp3.h:90
#define CMP_ISEC_SC_DACDataWrite
This macro defines the Custom Name for CMP1_DACDataWrite API.
Definition cmp1.h:100
#define CMP_ISEC_SC_DACEnable
This macro defines the Custom Name for CMP1_DACEnable API.
Definition cmp1.h:90
#define FAULT_SetLow()
Sets the RD9 GPIO Pin which has a custom name of FAULT to Low.
Definition pins.h:368
#define FAULT_SetHigh()
Sets the RD9 GPIO Pin which has a custom name of FAULT to High.
Definition pins.h:359
uint8_t OverTemperatureFlag
Over temperature flag.
Definition dev_temp.h:44
uint8_t FaultActive
Set/Cleared inside flt check loop
uint8_t FaultLatch
Flag indicating if FAULT has been tripped.
FAULT_OBJ_T VRail_5V
Fault object for 5V rail.
FAULT_OBJ_T VSecondaryUVP
Fault object for Secondary under voltage protection.
FAULT_OBJ_T PowerSupplyOTP
Fault object for Power Supply Temperature.
FAULT_OBJ_T VSecondaryOVP
Fault object for Secondary over voltage protection.
FAULT_OBJ_T ISecondaryOCP
Fault object for Secondary over current protection.
FAULT_OBJ_T VPrimaryOVP
Fault object for Primary over voltage protection.
FAULT_OBJ_T VPrimaryUVP
Fault object for Primary under voltage protection.
FAULT_OBJ_T IPrimaryOCP
Fault object for Primary over current protection.
FAULT_OBJ_T ISenseSCP
Fault object for Short circuit protection.
uint16_t FaultDetected
Fault indication for fault occurrence.
FAULT_t Object
Fault Objects.
uint16_t AverageValue
uint16_t VPriVoltage
Data value for input voltage.
uint16_t ISensePrimary
Data value for primary current as measured with CT.
uint16_t VSecVoltage
Data value for output voltage.
uint16_t ISenseSecondary
Data value for secondary current as measured with CT.
uint16_t VRail_5V
Data value for 5V auxiliary rail.
unsigned Running
Bit 0: Power converter is running.
unsigned FaultActive
Bit 1: Power converter fault is active.
int16_t Reference
actual reference
uint16_t PwrReference
User power reference setting used to control the converter controller.
int16_t IReference
User current reference setting used to control the converter controller.
PWR_CTRL_PROPERTIES_t Properties
Power Control properties
CONTROLLER_t VLoop
structure for voltage controller data
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.