Digital Power Starter Kit 3 Firmware
dsPIC33C Boost Converter Voltage Mode Control Example
app_fault_config.c
1 /*
2  * File: app_fault_monitor_config.c
3  * Author: M91406
4  *
5  * Created on July 15, 2021, 4:06 PM
6  */
7 
8 
9 #include <xc.h> // include processor files - each processor file is guarded.
10 #include <stdint.h> // include standard integer data types
11 #include <stdbool.h> // include standard boolean data types
12 #include <stddef.h> // include standard definition data types
13 
14 #include "config/hal.h" // include hardware abstraction layer header file
15 #include "config/apps.h" // include application layer abstraction layer header file
16 
17 /********************************************************************
18  * @var struct FAULT_OBJECT_s fltobj_BoostUVLO
19  * @ingroup app-layer-fault-monitor-properties-public
20  * @brief Under Voltage Lock Out Fault Object
21  * @details
22  * This fault object monitors the input voltage of the power supply
23  * scanning for conditions violating the minimum required input
24  * voltage level for the specified amount of time.
25  *******************************************************************/
26 
27 volatile struct FAULT_OBJECT_s fltobj_BoostUVLO =
28 {
29  .Status.bits.FaultActive = true, // Set fault condition flag (must be cleared by fault check)
30  .Status.bits.FaultStatus = true, // Set fault flag (must be cleared by fault check)
31  .Status.bits.CompareType = FLTCMP_LESS_THAN, // Select Compare-Type
32  .Status.bits.Enabled = true, // Enable fault checks
33 
34  .SourceObject.ptrObject = &boost.data.v_in, // Set pointer to variable to monitor
35  .SourceObject.bitMask = 0xFFFF, // Compare all bits of SOURCE (no bit filter)
36  .ReferenceObject.ptrObject = NULL, // Clear pointer to "compare against" variable
37  .ReferenceObject.bitMask = 0xFFFF, // Clear pointer to "compare against" variable
38 
39  .TripResponse.compareThreshold = BOOST_VIN_UVLO_TRIP, // Set fault trip level
40  .TripResponse.eventThreshold = BOOST_UVLO_TDLY, // Set counter level at which a FAULT condition will be tripped
41  .TripResponse.ptrResponseFunction = &appPowerSupply_Suspend, // Set pointer to user-function which should be called when a FAULT is tripped
42 
43  .RecoveryResponse.compareThreshold = BOOST_VIN_UVLO_RELEASE, // Set fault recovery level
44  .RecoveryResponse.eventThreshold = BOOST_UVLO_RDLY, // Set counter level at which a FAULT condition will be cleared
45  .RecoveryResponse.ptrResponseFunction = NULL // Clear recovery function pointer
46 };
47 
48 /********************************************************************
49  * @var struct FAULT_OBJECT_s fltobj_BoostOVLO
50  * @ingroup app-layer-fault-monitor-properties-public
51  * @brief Over Voltage Lock Out Fault Object
52  * @details
53  * This fault object monitors the input voltage of the power supply
54  * scanning for conditions exceeding the maximum allowed input
55  * voltage level for the specified amount of time.
56  *******************************************************************/
57 volatile struct FAULT_OBJECT_s fltobj_BoostOVLO = {
58 
59  .SourceObject.ptrObject = &boost.data.v_in, // Set pointer to variable to monitor
60  .SourceObject.bitMask = 0xFFFF, // Compare all bits of SOURCE (no bit filter)
61  .ReferenceObject.ptrObject = NULL, // Clear pointer to "compare against" variable
62  .ReferenceObject.bitMask = 0xFFFF, // Compare all bits of SOURCE (no bit filter)
63  .Status.bits.CompareType = FLTCMP_GREATER_THAN, // Select Compare-Type
64 
65  .TripResponse.compareThreshold = BOOST_VIN_OVLO_TRIP, // Set fault trip level
66  .TripResponse.eventThreshold = BOOST_OVLO_TDLY, // Set counter level at which a FAULT condition will be tripped
67  .TripResponse.ptrResponseFunction = &appPowerSupply_Suspend, // Set pointer to user-function which should be called when a FAULT is tripped
68 
69  .RecoveryResponse.compareThreshold = BOOST_VIN_OVLO_RELEASE, // Set fault recovery level
70  .RecoveryResponse.eventThreshold = BOOST_OVLO_RDLY, // Set counter level at which a FAULT condition will be cleared
71  .RecoveryResponse.ptrResponseFunction = NULL, // Clear recovery function pointer
72 
73  .Counter = 0, // Clear fault event counter
74  .Status.bits.FaultActive = true, // Set fault condition flag (must be cleared by fault check)
75  .Status.bits.FaultStatus = true, // Set fault flag (must be cleared by fault check)
76 
77  .Status.bits.Enabled = true // Enable fault checks
78 
79 };
80 
81 /********************************************************************
82  * @var struct FAULT_OBJECT_s fltobj_BoostOCP
83  * @ingroup app-layer-fault-monitor-properties-public
84  * @brief Over Current Protection Fault Object
85  * @details
86  * This fault object monitors the average output current of the
87  * power supply scanning for conditions exceeding the maximum
88  * allowed output current level for the specified amount of time.
89  *******************************************************************/
90 volatile struct FAULT_OBJECT_s fltobj_BoostOCP = {
91 
92  .SourceObject.ptrObject = &boost.data.i_out, // Set pointer to variable to monitor
93  .SourceObject.bitMask = 0xFFFF, // Compare all bits of SOURCE (no bit filter)
94  .ReferenceObject.ptrObject = NULL, // Clear pointer to "compare against" variable
95  .ReferenceObject.bitMask = 0xFFFF, // Compare all bits of SOURCE (no bit filter)
96  .Status.bits.CompareType = FLTCMP_GREATER_THAN, // Select Compare-Type
97 
98  .TripResponse.compareThreshold = BOOST_ISNS_OCL, // Set fault trip level
99  .TripResponse.eventThreshold = BOOST_OCP_TDLY, // Set counter level at which a FAULT condition will be tripped
100  .TripResponse.ptrResponseFunction = &appPowerSupply_Suspend, // Set pointer to user-function which should be called when a FAULT is tripped
101 
102  .RecoveryResponse.compareThreshold = BOOST_ISNS_OCL_RELEASE, // Set fault recovery level
103  .RecoveryResponse.eventThreshold = BOOST_OCP_RDLY, // Set counter level at which a FAULT condition will be cleared
104  .RecoveryResponse.ptrResponseFunction = NULL, // Clear recovery function pointer
105 
106  .Counter = 0, // Clear fault event counter
107  .Status.bits.FaultActive = false, // Set fault condition flag (must be cleared by fault check)
108  .Status.bits.FaultStatus = false, // Set fault flag (must be cleared by fault check)
109 
110  .Status.bits.Enabled = false // Enable fault checks
111 
112 };
113 
114 /********************************************************************
115  * @var struct FAULT_OBJECT_s fltobj_BoostRegErr
116  * @ingroup app-layer-fault-monitor-properties-public
117  * @brief Regulation Error Fault Object
118  * @details
119  * This fault object monitors the deviation between voltage reference
120  * and most recent output voltage of the power supply scanning for
121  * conditions where a maximum allowed deviation is exceeded for the
122  * specified amount of time.
123  *******************************************************************/
124 volatile struct FAULT_OBJECT_s fltobj_BoostRegErr = {
125 
126  .SourceObject.ptrObject = &boost.data.v_out, // Set pointer to variable to monitor
127  .SourceObject.bitMask = 0xFFFF, // Compare all bits of SOURCE (no bit filter)
128  .ReferenceObject.ptrObject = &boost.set_values.v_ref, // Set pointer to "compare against" variable
129  .ReferenceObject.bitMask = 0xFFFF, // Compare all bits of Reference (no bit filter)
130  .Status.bits.CompareType = FLTCMP_GREATER_THAN, // Select Compare-Type
131 
132  .TripResponse.compareThreshold = BOOST_VOUT_DEV_TRIP, // Set fault trip level
133  .TripResponse.eventThreshold = BOOST_REGERR_TDLY, // Set counter level at which a FAULT condition will be tripped
134  .TripResponse.ptrResponseFunction = &appPowerSupply_Suspend, // Set pointer to user-function which should be called when a FAULT is tripped
135 
136  .RecoveryResponse.compareThreshold = BOOST_VOUT_DEV_RELEASE, // Set fault recovery level
137  .RecoveryResponse.eventThreshold = BOOST_REGERR_RDLY, // Set counter level at which a FAULT condition will be cleared
138  .RecoveryResponse.ptrResponseFunction = NULL, // Clear recovery function pointer
139 
140  .Counter = 0, // Clear fault event counter
141  .Status.bits.FaultActive = false, // Set fault condition flag (must be cleared by fault check)
142  .Status.bits.FaultStatus = false, // Set fault flag (must be cleared by fault check)
143 
144  .Status.bits.Enabled = false // Disable fault checks at startup
145 
146 };
147 
148 /*********************************************************************************
149  * @ingroup app-layer-fault-monitor-properties-public
150  * @var FaultObjectList
151  * @brief Fault object list
152  * @details
153  * This list is grouping all user defined fault objects in one list, which
154  * is used by the fault handler for initialization, disposal and scan for
155  * fault conditions.
156  **********************************************************************************/
157 
158 volatile struct FAULT_OBJECT_s* FaultObjectList[] = {
159  &fltobj_BoostUVLO,
160  &fltobj_BoostOVLO,
161  &fltobj_BoostOCP,
162  &fltobj_BoostRegErr
163 };
164 
165 /*********************************************************************************
166  * @ingroup app-layer-fault-monitor-properties-public
167  * @var FaultObjectList_size
168  * @brief Fault object list size
169  * @details
170  * This variable is used to determine the number of user specified fault objects.
171  * The size of the fault object list is required for all fault monitor function
172  * calls.
173  **********************************************************************************/
174 
175 volatile uint16_t FaultObjectList_size = (sizeof(FaultObjectList)/sizeof(FaultObjectList[0]));
176 
177 
178 // end of file
#define BOOST_VIN_OVLO_TRIP
Over Voltage LOck Out voltage.
#define BOOST_VIN_UVLO_TRIP
Under Voltage LOck Out voltage.
volatile uint16_t v_ref
User reference setting used to control the power converter controller.
#define BOOST_VIN_UVLO_RELEASE
Under Voltage LOck Out voltage.
#define BOOST_ISNS_OCL
Over Current Limit.
#define BOOST_VIN_OVLO_RELEASE
Over Voltage LOck Out voltage.
#define BOOST_OVLO_RDLY
over voltage lock out recovery delay conversion nacro
#define BOOST_VOUT_DEV_RELEASE
Macro calculating the integer number equivalent of the maximum allowed output voltage deviation given...
volatile struct FLT_OBJECT_STATUS_s Status
Status word of this fault object.
volatile uint16_t * ptrObject
Pointer to register or variable which should be monitored.
volatile uint16_t v_in
BOOST input voltage.
#define BOOST_REGERR_TDLY
regulation error trip delay conversion macro
volatile uint16_t i_out
BOOST common output current.
#define BOOST_REGERR_RDLY
regulation error recovery delay conversion macro
#define BOOST_VOUT_DEV_TRIP
Macro calculating the integer number equivalent of the maximum allowed output voltage deviation given...
#define BOOST_OCP_TDLY
over current protection trip Delay conversion macro
#define BOOST_UVLO_RDLY
under voltage lock out recovery delay conversion nacro
volatile struct BOOST_CONVERTER_DATA_s data
BOOST runtime data.
Generic fault object.
#define BOOST_OCP_RDLY
over current protection recovery delay conversion nacro
#define BOOST_OVLO_TDLY
over voltage lock out trip delay conversion nacro
volatile uint16_t v_out
BOOST output voltage.
#define BOOST_UVLO_TDLY
Conversion Macros of Fault Response Timing Settings.
volatile struct FLT_COMPARE_OBJECT_s SourceObject
Object which should be monitored.
volatile struct BOOST_CONVERTER_SETTINGS_s set_values
Control field for global access to references.
volatile bool FaultActive
Bit 1: Flag bit indicating if fault condition has been detected but FAULT has not been tripped yet.
#define BOOST_ISNS_OCL_RELEASE
Over Current Release Level.