Bar Logo 4kW dsPIC33C PSFB DC-DC DA (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
27void 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
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
83void FAULT_SetCounters(FAULT_OBJ_T *faultInput, uint16_t fltThresholdCnt, uint32_t fltHysCnt)
84{
85 faultInput->CounterSet = fltThresholdCnt;
86 faultInput->CounterReset = fltHysCnt;
87}
88
89
101void 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
126bool 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
184bool 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
236bool 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
287bool 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}
Contains fault generic public functions.
void(* FAULT_CALLBACK)(void)
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_CheckRange(FAULT_OBJ_T *faultInput, int16_t inputValue, FAULT_CALLBACK callback)
bool FAULT_CheckBit(FAULT_OBJ_T *faultInput, bool faultBit, FAULT_CALLBACK callback)
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...
void FAULT_SetCounters(FAULT_OBJ_T *faultInput, uint16_t fltThresholdCnt, uint32_t fltHysCnt)
This function initializes/sets the fault structure with the counter limits.
void FAULT_SetThresholds(FAULT_OBJ_T *faultInput, int16_t fltThreshold, int16_t fltHysLimit)
This function initializes/sets the fault structure with the threshold limits.
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...
The Fault object data structure contains a list of elements/variables that are used to detect/check a...
uint16_t FaultCounter
Internal counter for activating/removing fault.
uint8_t FaultActive
Set/Cleared inside flt check loop
int16_t Val1_Hysteresis
Fault hysteresis limit. If hysteresis is not needed, fltThreshold = fltHysLimit.
uint8_t FaultLatch
Flag indicating if FAULT has been tripped.
uint16_t FaultCode
Code that can be used to display fault (1st fault occurred) to global variable.
int16_t Val1_Threshold
Fault threshold limit: Range of -32768 to 32767.
int16_t Val2_Hysteresis
Fault hysteresis limit. If hysteresis is not needed, fltThreshold = fltHysLimit.
uint32_t CounterReset
Number of consecutive events when input outside hysteresis limit in order to remove fault,...
uint16_t CounterSet
Number of consecutive fault events before fault becomes active.
int16_t Val2_Threshold
Fault threshold limit: Range of -32768 to 32767.