|  | Dual Active Bridge Development Board (Part-No. ) |
Content |  |  |  |  |  |

Loading...
Searching...
No Matches
fault_common.c
1
8#include "fault_common.h"
9#include "system/pins.h"
10#include <stdbool.h>
11#include <stddef.h>
12
13
27 void FAULT_Init(FAULT_OBJ_T *faultInput,
28 int16_t threshold, int16_t hysLimit,
29 uint16_t thresholdCnt, uint32_t hysCnt)
30{
31 faultInput->Val1_Threshold = threshold;
32 faultInput->Val1_Hysteresis = hysLimit;
33 faultInput->CounterSet = thresholdCnt;
34 faultInput->CounterReset = hysCnt;
35 faultInput->FaultCode = 0U;
36 faultInput->FaultActive = 0;
37}
38
39
55 void FAULT_InitRange(FAULT_OBJ_T *faultInput,
56 int16_t thresholdMin, int16_t hysLimitMin,
57 int16_t thresholdMax, int16_t hysLimitMax,
58 uint16_t thresholdCnt, uint32_t hysCnt)
59{
60 faultInput->Val1_Threshold = thresholdMin;
61 faultInput->Val1_Hysteresis = hysLimitMin;
62 faultInput->Val2_Threshold = thresholdMax;
63 faultInput->Val2_Hysteresis = hysLimitMax;
64 faultInput->CounterSet = thresholdCnt;
65 faultInput->CounterReset = hysCnt;
66 faultInput->FaultCode = 0U;
67 faultInput->FaultActive = 0;
68 faultInput->FaultLatch = 0;
69}
70
71
83 void FAULT_SetCounters(FAULT_OBJ_T *faultInput, uint16_t fltThresholdCnt, uint32_t fltHysCnt)
84{
85 faultInput->CounterSet = fltThresholdCnt;
86 faultInput->CounterReset = fltHysCnt;
87}
88
89
101 void FAULT_SetThresholds(FAULT_OBJ_T *faultInput, int16_t fltThreshold, int16_t fltHysLimit)
102{
103 faultInput->Val1_Threshold = fltThreshold;
104 faultInput->Val1_Hysteresis = fltHysLimit;
105}
106
107
126 bool FAULT_CheckMax(FAULT_OBJ_T *faultInput, int16_t faultSource, FAULT_CALLBACK callback)
127{
128
129 if ((faultSource >= faultInput->Val1_Threshold) && (faultInput->FaultActive == false))
130 {
131 faultInput->FaultCounter++;
132
133 if (faultInput->FaultCounter > faultInput->CounterSet)
134 {
135 faultInput->FaultLatch = true;
136
137 if (callback != NULL)
138 {
139 callback(); // Call Back function used to quickly shutdown system if needed when fault detected
140 }
141
142 faultInput->FaultActive = true;
143 faultInput->FaultCounter = 0U;
144 }
145 }
146 else if ((faultSource < (faultInput->Val1_Hysteresis)) && (faultInput->FaultActive == true))
147 {
148 faultInput->FaultCounter++;
149 if (faultInput->FaultCounter > faultInput->CounterReset)
150 {
151 faultInput->FaultCounter = 0U;
152 faultInput->FaultActive = false;
153 }
154 }
155 else
156 {
157 faultInput->FaultCounter = 0U;
158 }
159
160 return (faultInput->FaultActive);
161
162}
163
164
184 bool FAULT_CheckMin(FAULT_OBJ_T *faultInput, int16_t faultSource, FAULT_CALLBACK callback)
185{
186
187 if ((faultSource <= faultInput->Val1_Threshold) && (faultInput->FaultActive == false))
188 {
189 faultInput->FaultCounter++;
190 if (faultInput->FaultCounter > faultInput->CounterSet)
191 {
192 faultInput->FaultLatch = true;
193
194 if (callback != NULL)
195 {
196 callback(); // Call Back function used to quickly shutdown system if needed when fault detected
197 }
198
199 faultInput->FaultActive = true;
200 faultInput->FaultCounter = 0U;
201 }
202 }
203 else if ((faultSource > (faultInput->Val1_Hysteresis)) && (faultInput->FaultActive == true))
204 {
205 faultInput->FaultCounter++;
206 if (faultInput->FaultCounter > faultInput->CounterReset)
207 {
208 faultInput->FaultCounter = 0U;
209 faultInput->FaultActive = false;
210 }
211 }
212 else
213 {
214 faultInput->FaultCounter = 0U;
215 }
216
217 return (faultInput->FaultActive);
218
219}
220
221
236 bool FAULT_CheckBit(FAULT_OBJ_T *faultInput, bool faultBit, FAULT_CALLBACK callback)
237{
238 if ((faultBit) && (faultInput->FaultActive == false))
239 {
240 faultInput->FaultCounter++;
241
242 if (faultInput->FaultCounter > faultInput->CounterSet)
243 {
244 faultInput->FaultLatch = true;
245
246 if (callback != NULL)
247 {
248 callback(); // Call Back function used to quickly shutdown system if needed when fault detected
249 }
250
251 faultInput->FaultActive = true;
252 faultInput->FaultCounter = 0U;
253 }
254 }
255 else if ((!faultBit) && (faultInput->FaultActive == true))
256 {
257 faultInput->FaultCounter++;
258 if (faultInput->FaultCounter > faultInput->CounterReset)
259 {
260 faultInput->FaultCounter = 0U;
261 faultInput->FaultActive = false;
262 }
263 } else
264 {
265 faultInput->FaultCounter = 0U;
266 }
267
268 return (faultInput->FaultActive);
269}
270
271
287 bool FAULT_CheckRange(FAULT_OBJ_T *faultInput, int16_t inputValue, FAULT_CALLBACK callback)
288{
289 if (faultInput->FaultActive == false)
290 {
291 if ((inputValue <= faultInput->Val1_Threshold) ||
292 (inputValue >= faultInput->Val2_Threshold))
293 {
294 if (++faultInput->FaultCounter >= faultInput->CounterSet)
295 {
296 faultInput->FaultLatch = true;
297
298 if (callback != NULL)
299 {
300 callback(); // Call Back function used to quickly shutdown system if needed when fault detected
301 }
302 faultInput->FaultActive = true;
303 faultInput->FaultCounter = 0U;
304 }
305 }
306 else
307 {
308 faultInput->FaultCounter = 0U;
309 }
310 }
311 else
312 {
313 if ((inputValue > faultInput->Val1_Hysteresis) &&
314 (inputValue < faultInput->Val2_Hysteresis))
315 {
316 if (++faultInput->FaultCounter > faultInput->CounterReset)
317 {
318 faultInput->FaultCounter = 0U;
319 faultInput->FaultActive = false;
320 }
321 }
322 else
323 {
324 faultInput->FaultCounter = 0U;
325 }
326 }
327 return (faultInput->FaultActive);
328}
fault_common.h
Contains fault generic public functions.
FAULT_CALLBACK
void(* FAULT_CALLBACK)(void)
Definition fault_common.h:36
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_CheckRange
bool FAULT_CheckRange(FAULT_OBJ_T *faultInput, int16_t inputValue, FAULT_CALLBACK callback)
Definition fault_common.c:287
FAULT_CheckBit
bool FAULT_CheckBit(FAULT_OBJ_T *faultInput, bool faultBit, FAULT_CALLBACK callback)
Definition fault_common.c:236
FAULT_InitRange
void FAULT_InitRange(FAULT_OBJ_T *faultInput, int16_t thresholdMin, int16_t hysLimitMin, int16_t thresholdMax, int16_t hysLimitMax, 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:55
FAULT_SetCounters
void FAULT_SetCounters(FAULT_OBJ_T *faultInput, uint16_t fltThresholdCnt, uint32_t fltHysCnt)
This function initializes/sets the fault structure with the counter limits.
Definition fault_common.c:83
FAULT_SetThresholds
void FAULT_SetThresholds(FAULT_OBJ_T *faultInput, int16_t fltThreshold, int16_t fltHysLimit)
This function initializes/sets the fault structure with the threshold limits.
Definition fault_common.c:101
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
FAULT_OBJ_T
The Fault object data structure contains a list of elements/variables that are used to detect/check a...
Definition fault_common.h:23
FAULT_OBJ_T::FaultCounter
uint16_t FaultCounter
Internal counter for activating/removing fault.
Definition fault_common.h:30
FAULT_OBJ_T::FaultActive
uint8_t FaultActive
Set/Cleared inside flt check loop
Definition fault_common.h:32
FAULT_OBJ_T::Val1_Hysteresis
int16_t Val1_Hysteresis
Fault hysteresis limit. If hysteresis is not needed, fltThreshold = fltHysLimit.
Definition fault_common.h:25
FAULT_OBJ_T::FaultLatch
uint8_t FaultLatch
Flag indicating if FAULT has been tripped.
Definition fault_common.h:33
FAULT_OBJ_T::FaultCode
uint16_t FaultCode
Code that can be used to display fault (1st fault occurred) to global variable.
Definition fault_common.h:31
FAULT_OBJ_T::Val1_Threshold
int16_t Val1_Threshold
Fault threshold limit: Range of -32768 to 32767.
Definition fault_common.h:24
FAULT_OBJ_T::Val2_Hysteresis
int16_t Val2_Hysteresis
Fault hysteresis limit. If hysteresis is not needed, fltThreshold = fltHysLimit.
Definition fault_common.h:27
FAULT_OBJ_T::CounterReset
uint32_t CounterReset
Number of consecutive events when input outside hysteresis limit in order to remove fault,...
Definition fault_common.h:29
FAULT_OBJ_T::CounterSet
uint16_t CounterSet
Number of consecutive fault events before fault becomes active.
Definition fault_common.h:28
FAULT_OBJ_T::Val2_Threshold
int16_t Val2_Threshold
Fault threshold limit: Range of -32768 to 32767.
Definition fault_common.h:26