|  | 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"
23#include "fault_comm_interface.h"
24
25// PRIVATE FUNCTIONS
26static void Fault_EnableShortCircuitProtection(void);
27
28 bool loadDisconnect = false;
29
30
41 void Fault_Handler(void)
42{
43 // Drive the fault pin to Low when Fault trips
44 FAULT_SetLow();
45
46 // Turn off PWM output
47 PwrCtrl_PWM_Disable();
48
49 // set the fault active bit
50 dab.Status.bits.FaultActive = 1;
51
52 // clear the running bit
53 dab.Status.bits.Running = 0;
54
55}
56
57
65 void Fault_Initialize(void)
66{
67 // Initialize Primary Over Current Protection
68 FAULT_Init(&dab.Fault.Object.IPrimaryOCP, IPRI_OC_THRES_TRIG,
69 IPRI_OC_THRES_CLEAR, IPRI_OC_T_BLANK_TRIG, IPRI_OC_T_BLANK_CLEAR);
70
71 // Initialize Secondary Over Current Protection
72 FAULT_Init(&dab.Fault.Object.ISecondaryOCP, ISEC_OC_THRES_TRIG,
73 ISEC_OC_THRES_CLEAR, ISEC_OC_T_BLANK_TRIG, ISEC_OC_T_BLANK_CLEAR);
74
75 // Initialize Primary Over Voltage Protection
76 FAULT_Init(&dab.Fault.Object.VPrimaryOVP, VPRI_OV_THRES_TRIG,
77 VPRI_OV_THRES_CLEAR, VPRI_OV_T_BLANK_TRIG, VPRI_OV_T_BLANK_CLEAR);
78
79 // Initialize Primary Over Voltage Protection
80 FAULT_Init(&dab.Fault.Object.VPrimaryUVP, VPRI_OV_THRES_TRIG,
81 VPRI_OV_THRES_CLEAR, VPRI_OV_T_BLANK_TRIG, VPRI_OV_T_BLANK_CLEAR);
82
83 // Initialize Secondary Over Voltage Protection
84 FAULT_Init(&dab.Fault.Object.VSecondaryOVP, VSEC_OV_THRES_TRIG,
85 VSEC_OV_THRES_CLEAR, VSEC_OV_T_BLANK_TRIG, VSEC_OV_T_BLANK_CLEAR);
86
87 // Initialize Secondary Over Voltage Protection
88 FAULT_Init(&dab.Fault.Object.VSecondaryUVP, VSEC_OV_THRES_TRIG,
89 VSEC_OV_THRES_CLEAR, VSEC_OV_T_BLANK_TRIG, VSEC_OV_T_BLANK_CLEAR);
90
91 // Initialize 5V Rail instability Protection
92 FAULT_Init(&dab.Fault.Object.VRail_5V, VRAIL_5V_UV_THRES_TRIG,
93 VRAIL_5V_UV_THRES_CLEAR, VRAIL_5V_UV_T_BLANK_TRIG, VRAIL_5V_UV_T_BLANK_CLEAR);
94
95 // Initialize Over Temperature Protection
96 FAULT_Init(&dab.Fault.Object.PowerSupplyOTP, OTP_THRES_TRIG_CELCIUS,
97 OTP_THRES_CLEAR_CELCIUS, FAULT_PERSISTENCE_COUNT_TEMP, FAULT_PERSISTENCE_COUNT_TEMP);
98
99#if defined (FAULT_SHORT_CCT) && (FAULT_SHORT_CCT == true)
100 // Initialize short circuit fault protection with comparators
101 Fault_EnableShortCircuitProtection();
102#endif
103
104}
105
106
115 void Fault_Execute(void)
116{
117 uint16_t faultCheck = 0;
118 // secondary over current fault handler
119 #if defined(FAULT_ISEC_OC) && (FAULT_ISEC_OC == true)
120 faultCheck = FAULT_CheckMax(&dab.Fault.Object.ISecondaryOCP, dab.Data.ISenseSecondary, &Fault_Handler);
121 #endif
122
123 // secondary over voltage fault handler
124 #if defined(FAULT_VSEC_OV) && (FAULT_VSEC_OV == true)
125 faultCheck &= FAULT_CheckMax(&dab.Fault.Object.VSecondaryOVP, dab.Data.VSecVoltage, &Fault_Handler);
126 #endif
127
128 // primary over current fault handler
129 #if defined (FAULT_IPRI_OC) && (FAULT_IPRI_OC == true)
130 faultCheck &= FAULT_CheckMax(&dab.Fault.Object.IPrimaryOCP, dab.Data.ISensePrimary, &Fault_Handler);
131 #endif
132
133 // primary over voltage fault handler
134 #if defined(FAULT_VPRI_OV) && (FAULT_VPRI_OV == true)
135 faultCheck &= FAULT_CheckMax(&dab.Fault.Object.VPrimaryOVP, dab.Data.VPriVoltage, &Fault_Handler);
136 #endif
137
138 // primary over voltage fault handler
139 #if defined(FAULT_VPRI_UV) && (FAULT_VPRI_UV == true)
140 faultCheck &= FAULT_CheckMin(&dab.Fault.Object.VPrimaryUVP, dab.Data.VPriVoltage, &Fault_Handler);
141 #endif
142
143 // primary over voltage fault handler
144 #if defined(FAULT_VRAIL_5V) && (FAULT_VRAIL_5V == true)
145 faultCheck &= FAULT_CheckMin(&dab.Fault.Object.VRail_5V, dab.Data.VRail_5V, &Fault_Handler);
146 #endif
147
148 // Hardware short circuit
149 if(CMP1_StatusGet() || CMP3_StatusGet()){
150
151 Fault_Handler();
152
153 // Set fault bits
154 dab.Fault.Object.ISenseSCP.FaultActive = 1;
155 dab.Fault.Object.ISenseSCP.FaultLatch = 1;
156
157 faultCheck &= dab.Fault.Object.ISenseSCP.FaultActive;
158 }
159
160 #if defined (LOAD_DISCONNECT) && (LOAD_DISCONNECT == true)
161 // Protection when Load is removed by accident.
162 //DAB does not sink power in this modulation. Voltage builds up on output.
163 if(dab.PowerDirection==PWR_CTRL_CHARGING)
164 {
165 if((iSecAveraging.AverageValue <= (ISEC_LOAD_STEP_CLAMP>>2)) &&
166 (vSecAveraging.AverageValue > (dab.VLoop.Reference + VSEC_LOAD_STEP_CLAMP)) &&
167 (dab.Properties.IReference >= 1) )
168 {
169 loadDisconnect = true;
170 Fault_Handler();
171 }
172 }
173 if(dab.PowerDirection==PWR_CTRL_DISCHARGING)
174 {
175 if((iSecAveraging.AverageValue <= (ISEC_LOAD_STEP_CLAMP>>2)) &&
176 (vPrimAveraging.AverageValue > (dab.VLoop.Reference + VPRIM_LOAD_STEP_CLAMP)) &&
177 (dab.Properties.IReference >= 1) )
178 {
179 loadDisconnect = true;
180 Fault_Handler();
181 }
182 }
183 #endif
184
185 dab.Status.bits.FaultActive = faultCheck;
186
187 // Identify the fault that trips
188 dab.Fault.FaultDetected = Fault_GetFlags();
189}
190
191
192
200 void Fault_Reset(void)
201{
202 // Drive the fault pin to high to allow PWM signal drive
203 FAULT_SetHigh();
204
205 // Clear fault Objects FaultActive bit
206 dab.Fault.Object.VPrimaryOVP.FaultActive = 0;
207 dab.Fault.Object.VSecondaryOVP.FaultActive = 0;
208 dab.Fault.Object.IPrimaryOCP.FaultActive = 0;
209 dab.Fault.Object.ISecondaryOCP.FaultActive = 0;
210 dab.Fault.Object.ISenseSCP.FaultActive = 0;
211 dab.Fault.Object.PowerSupplyOTP.FaultActive = 0;
212 dab.Fault.Object.VRail_5V.FaultActive = 0;
213
214 // Clear fault Objects FaultLatch bit
215 dab.Fault.Object.VPrimaryOVP.FaultLatch = 0;
216 dab.Fault.Object.VSecondaryOVP.FaultLatch = 0;
217 dab.Fault.Object.IPrimaryOCP.FaultLatch = 0;
218 dab.Fault.Object.ISecondaryOCP.FaultLatch = 0;
219 dab.Fault.Object.ISenseSCP.FaultLatch = 0;
220 dab.Fault.Object.VRail_5V.FaultLatch = 0;
221 dab.Fault.Object.PowerSupplyOTP.FaultActive = 0;
222
223 loadDisconnect = false;
224
225 dab.Status.bits.FaultActive = 0;
226}
227
228
237 static void Fault_EnableShortCircuitProtection(void)
238{
239 // on dsPIC33CK DP-PIM:
240 // CMP1B used for short circuit protection on the secondary side
241 // CMP3B used for short circuit protection on the primary side
242
243 // initialize thresholds of comparators used for short circuit protection
244 CMP_ISEC_SC_DACDataWrite(ISEC_SC_THRES_TRIG);
245 CMP_IPRI_SC_DACDataWrite(IPRI_SC_THRES_TRIG);
246
247 // turn on comparator DACs
248 CMP_IPRI_SC_DACEnable();
249 CMP_ISEC_SC_DACEnable();
250
251}
252
253
263 void Fault_Execute_100ms(void)
264{
265 #if defined (FAULT_PS_OTP) && (FAULT_PS_OTP == true)
266 if(FAULT_CheckMax(&dab.Fault.Object.PowerSupplyOTP, Dev_Temp_Get_Temperature_Celcius(), &Fault_Handler))
267 {
268 devTempData.OverTemperatureFlag = 1; //for over temperature
269 dab.Status.bits.FaultActive = 1;
270 }
271 else
272 {
273 devTempData.OverTemperatureFlag = 0; //for over temperature
274 dab.Status.bits.FaultActive = 0;
275 }
276 #endif
277}
cmp1.h
This is the generated driver header file for the CMP1 driver.
cmp3.h
This is the generated driver header file for the CMP3 driver.
pwm.h
This is the generated driver header file for the PWM driver.
device.h
Contains h files that are part of device layer.
loadDisconnect
bool loadDisconnect
Definition fault.c:28
fault.h
Contains public fault functions.
fault_common.h
Contains fault generic public functions.
Fault_GetFlags
uint16_t Fault_GetFlags(void)
Definition fault_comm_interface.c:28
fault_comm_interface.h
Contains API functions for fault protection.
VPRI_OV_T_BLANK_TRIG
#define VPRI_OV_T_BLANK_TRIG
Definition macros.h:125
VPRI_OV_THRES_TRIG
#define VPRI_OV_THRES_TRIG
Definition macros.h:123
VPRI_OV_T_BLANK_CLEAR
#define VPRI_OV_T_BLANK_CLEAR
Definition macros.h:126
VPRI_OV_THRES_CLEAR
#define VPRI_OV_THRES_CLEAR
Definition macros.h:124
VSEC_OV_THRES_TRIG
#define VSEC_OV_THRES_TRIG
Definition macros.h:105
VPRIM_LOAD_STEP_CLAMP
#define VPRIM_LOAD_STEP_CLAMP
Definition macros.h:116
VSEC_OV_T_BLANK_TRIG
#define VSEC_OV_T_BLANK_TRIG
Definition macros.h:107
VSEC_OV_THRES_CLEAR
#define VSEC_OV_THRES_CLEAR
Definition macros.h:106
VSEC_LOAD_STEP_CLAMP
#define VSEC_LOAD_STEP_CLAMP
Definition macros.h:115
VSEC_OV_T_BLANK_CLEAR
#define VSEC_OV_T_BLANK_CLEAR
Definition macros.h:108
IPRI_OC_THRES_CLEAR
#define IPRI_OC_THRES_CLEAR
Definition macros.h:93
IPRI_SC_THRES_TRIG
#define IPRI_SC_THRES_TRIG
Definition macros.h:97
IPRI_OC_T_BLANK_CLEAR
#define IPRI_OC_T_BLANK_CLEAR
Definition macros.h:95
IPRI_OC_THRES_TRIG
#define IPRI_OC_THRES_TRIG
Definition macros.h:92
IPRI_OC_T_BLANK_TRIG
#define IPRI_OC_T_BLANK_TRIG
Definition macros.h:94
ISEC_OC_THRES_CLEAR
#define ISEC_OC_THRES_CLEAR
Definition macros.h:72
ISEC_SC_THRES_TRIG
#define ISEC_SC_THRES_TRIG
Definition macros.h:76
ISEC_OC_T_BLANK_CLEAR
#define ISEC_OC_T_BLANK_CLEAR
Definition macros.h:74
ISEC_LOAD_STEP_CLAMP
#define ISEC_LOAD_STEP_CLAMP
Definition macros.h:77
ISEC_OC_THRES_TRIG
#define ISEC_OC_THRES_TRIG
Definition macros.h:71
ISEC_OC_T_BLANK_TRIG
#define ISEC_OC_T_BLANK_TRIG
Definition macros.h:73
VRAIL_5V_UV_T_BLANK_CLEAR
#define VRAIL_5V_UV_T_BLANK_CLEAR
Definition macros.h:146
VRAIL_5V_UV_T_BLANK_TRIG
#define VRAIL_5V_UV_T_BLANK_TRIG
Definition macros.h:145
VRAIL_5V_UV_THRES_TRIG
#define VRAIL_5V_UV_THRES_TRIG
Definition macros.h:143
VRAIL_5V_UV_THRES_CLEAR
#define VRAIL_5V_UV_THRES_CLEAR
Definition macros.h:144
FAULT_PERSISTENCE_COUNT_TEMP
#define FAULT_PERSISTENCE_COUNT_TEMP
Definition config.h:169
OTP_THRES_TRIG_CELCIUS
#define OTP_THRES_TRIG_CELCIUS
Degrees Celcius.
Definition config.h:167
OTP_THRES_CLEAR_CELCIUS
#define OTP_THRES_CLEAR_CELCIUS
Degrees Celcius.
Definition config.h:168
devTempData
TEMP_SETTINGS_t devTempData
Data Object of temperature settings.
Definition dev_temp.c:30
Dev_Temp_Get_Temperature_Celcius
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
dab
POWER_CONTROL_t dab
Global data object for a DAB Converter.
Definition pwrctrl.c:28
iSecAveraging
AVERAGING_t iSecAveraging
Data Object of secondary current averaging.
Definition pwrctrl_isr_extension.c:50
vPrimAveraging
AVERAGING_t vPrimAveraging
Data Object of primary voltage averaging.
Definition pwrctrl_isr_extension.c:34
vSecAveraging
AVERAGING_t vSecAveraging
Data Object of secondary voltage averaging.
Definition pwrctrl_isr_extension.c:42
PwrCtrl_PWM_Disable
void PwrCtrl_PWM_Disable(void)
Disable the PWM output.
Definition pwrctrl_pwm.c:127
PWR_CTRL_CHARGING
@ PWR_CTRL_CHARGING
power converter is in charging mode
Definition pwrctrl_typedef.h:136
PWR_CTRL_DISCHARGING
@ PWR_CTRL_DISCHARGING
power converter is in discharging mode
Definition pwrctrl_typedef.h:137
Fault_Execute_100ms
void Fault_Execute_100ms(void)
Fault evaluation for Temperature and other slow fault detection executed every 100ms.
Definition fault.c:263
Fault_Reset
void Fault_Reset(void)
Clears the fault object flag bits.
Definition fault.c:200
Fault_EnableShortCircuitProtection
static void Fault_EnableShortCircuitProtection(void)
Enable Short circuit hardware protection.
Definition fault.c:237
Fault_Initialize
void Fault_Initialize(void)
Initialize the fault objects.
Definition fault.c:65
Fault_Execute
void Fault_Execute(void)
Executes the fault handlers.
Definition fault.c:115
Fault_Handler
void Fault_Handler(void)
Handles the fault trip by turning off the power control switching.
Definition fault.c:41
FAULT_CheckMax
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...
Definition fault_common.c:126
FAULT_CheckMin
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...
Definition fault_common.c:184
FAULT_Init
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...
Definition fault_common.c:27
CMP3_StatusGet
bool CMP3_StatusGet(void)
Returns the comparator output status.
Definition cmp3.c:111
CMP_IPRI_SC_DACDataWrite
#define CMP_IPRI_SC_DACDataWrite
This macro defines the Custom Name for CMP3_DACDataWrite API.
Definition cmp3.h:100
CMP1_StatusGet
bool CMP1_StatusGet(void)
Returns the comparator output status.
Definition cmp1.c:111
CMP_IPRI_SC_DACEnable
#define CMP_IPRI_SC_DACEnable
This macro defines the Custom Name for CMP3_DACEnable API.
Definition cmp3.h:90
CMP_ISEC_SC_DACDataWrite
#define CMP_ISEC_SC_DACDataWrite
This macro defines the Custom Name for CMP1_DACDataWrite API.
Definition cmp1.h:100
CMP_ISEC_SC_DACEnable
#define CMP_ISEC_SC_DACEnable
This macro defines the Custom Name for CMP1_DACEnable API.
Definition cmp1.h:90
FAULT_SetLow
#define FAULT_SetLow()
Sets the RD9 GPIO Pin which has a custom name of FAULT to Low.
Definition pins.h:368
FAULT_SetHigh
#define FAULT_SetHigh()
Sets the RD9 GPIO Pin which has a custom name of FAULT to High.
Definition pins.h:359
TEMP_SETTINGS_s::OverTemperatureFlag
uint8_t OverTemperatureFlag
Over temperature flag.
Definition dev_temp.h:44
FAULT_OBJ_T::FaultActive
uint8_t FaultActive
Set/Cleared inside flt check loop
Definition fault_common.h:32
FAULT_OBJ_T::FaultLatch
uint8_t FaultLatch
Flag indicating if FAULT has been tripped.
Definition fault_common.h:33
FAULT_s::VRail_5V
FAULT_OBJ_T VRail_5V
Fault object for 5V rail.
Definition fault_typedef.h:30
FAULT_s::VSecondaryUVP
FAULT_OBJ_T VSecondaryUVP
Fault object for Secondary under voltage protection.
Definition fault_typedef.h:27
FAULT_s::PowerSupplyOTP
FAULT_OBJ_T PowerSupplyOTP
Fault object for Power Supply Temperature.
Definition fault_typedef.h:29
FAULT_s::VSecondaryOVP
FAULT_OBJ_T VSecondaryOVP
Fault object for Secondary over voltage protection.
Definition fault_typedef.h:26
FAULT_s::ISecondaryOCP
FAULT_OBJ_T ISecondaryOCP
Fault object for Secondary over current protection.
Definition fault_typedef.h:23
FAULT_s::VPrimaryOVP
FAULT_OBJ_T VPrimaryOVP
Fault object for Primary over voltage protection.
Definition fault_typedef.h:24
FAULT_s::VPrimaryUVP
FAULT_OBJ_T VPrimaryUVP
Fault object for Primary under voltage protection.
Definition fault_typedef.h:25
FAULT_s::IPrimaryOCP
FAULT_OBJ_T IPrimaryOCP
Fault object for Primary over current protection.
Definition fault_typedef.h:22
FAULT_s::ISenseSCP
FAULT_OBJ_T ISenseSCP
Fault object for Short circuit protection.
Definition fault_typedef.h:28
FAULT_SETTINGS_s::FaultDetected
uint16_t FaultDetected
Fault indication for fault occurrence.
Definition fault_typedef.h:41
FAULT_SETTINGS_s::Object
FAULT_t Object
Fault Objects.
Definition fault_typedef.h:42
AVERAGING_s::AverageValue
uint16_t AverageValue
Definition pwrctrl_common.h:22
FEEDBACK_SETTINGS_s::VPriVoltage
uint16_t VPriVoltage
Data value for input voltage.
Definition pwrctrl_typedef.h:59
FEEDBACK_SETTINGS_s::ISensePrimary
uint16_t ISensePrimary
Data value for primary current as measured with CT.
Definition pwrctrl_typedef.h:61
FEEDBACK_SETTINGS_s::VSecVoltage
uint16_t VSecVoltage
Data value for output voltage.
Definition pwrctrl_typedef.h:60
FEEDBACK_SETTINGS_s::ISenseSecondary
uint16_t ISenseSecondary
Data value for secondary current as measured with CT.
Definition pwrctrl_typedef.h:62
FEEDBACK_SETTINGS_s::VRail_5V
uint16_t VRail_5V
Data value for 5V auxiliary rail.
Definition pwrctrl_typedef.h:67
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::Reference
int16_t Reference
actual reference
Definition pwrctrl_typedef.h:120
PWR_CTRL_PROPERTIES_s::IReference
int16_t IReference
User current reference setting used to control the converter controller.
Definition pwrctrl_typedef.h:152
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::Data
FEEDBACK_SETTINGS_t Data
Feedback channel settings.
Definition pwrctrl_typedef.h:172
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::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