MotorWare f2806x Module API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

32b/cal.h
Go to the documentation of this file.
1 #ifndef _CAL_H_
2 #define _CAL_H_
3
9
10
11 // **************************************************************************
12 // the includes
13
14
15 // drivers
16
17
18 // modules
19 #include "sw/modules/types/src/types.h"
20 #include "sw/modules/cal/src/cal_states.h"
21 #include "sw/modules/hal/src/32b/hal_data.h"
22 #include "sw/modules/math/src/32b/math.h"
23 #include "sw/modules/offset/src/32b/offset.h"
24 #include "sw/modules/user/src/32b/userParams.h"
25
26
27 // solutions
28 #include "user.h"
29
30
33
36
37
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43
44 // **************************************************************************
45 // the defines
46
47
48 // **************************************************************************
49 // the typedefs
50
51
54 typedef struct _CAL_Obj_
55 {
56 CAL_State_e state;
57
58 uint_least32_t counter_state;
59 uint_least32_t waitTimes[CAL_numStates];
60
61 OFFSET_Handle offsetHandle_I[USER_NUM_CURRENT_SENSORS];
62 OFFSET_Obj offset_I[USER_NUM_CURRENT_SENSORS];
63
64 OFFSET_Handle offsetHandle_V[USER_NUM_VOLTAGE_SENSORS];
65 OFFSET_Obj offset_V[USER_NUM_VOLTAGE_SENSORS];
66
67 bool flag_enable;
68 bool flag_enableAdcOffset;
69 } CAL_Obj;
70
71
74 typedef struct _CAL_Obj_ *CAL_Handle;
75
76
77 // **************************************************************************
78 // the globals
79
80
81 // **************************************************************************
82 // the function prototypes
83
86 static inline void CAL_disable(CAL_Handle handle)
87 {
88 CAL_Obj *obj = (CAL_Obj *)handle;
89
90 obj->flag_enable = false;
91
92 return;
93 } // end of CAL_disable() function
94
95
98 static inline void CAL_enable(CAL_Handle handle)
99 {
100 CAL_Obj *obj = (CAL_Obj *)handle;
101
102 obj->flag_enable = true;
103
104 return;
105 } // end of CAL_enable() function
106
107
111 static inline uint_least32_t CAL_getCount_state(CAL_Handle handle)
112 {
113 CAL_Obj *obj = (CAL_Obj *)handle;
114
115 return(obj->counter_state);
116 } // end of CAL_getCount_state() function
117
118
122 static inline bool CAL_getFlag_enable(CAL_Handle handle)
123 {
124 CAL_Obj *obj = (CAL_Obj *)handle;
125
126 return(obj->flag_enable);
127 } // end of CAL_getFlag_enable() function
128
129
133 static inline bool CAL_getFlag_enableAdcOffset(CAL_Handle handle)
134 {
135 CAL_Obj *obj = (CAL_Obj *)handle;
136
137 return(obj->flag_enableAdcOffset);
138 } // end of CAL_getFlag_enableAdcOffset() function
139
140
144 static inline OFFSET_Handle *CAL_getOffsetHandleAddr_I(CAL_Handle handle)
145 {
146 CAL_Obj *obj = (CAL_Obj *)handle;
147
148 return(&(obj->offsetHandle_I[0]));
149 } // end of CAL_getOffsetHandleAddr_I() function
150
151
155 static inline OFFSET_Handle *CAL_getOffsetHandleAddr_V(CAL_Handle handle)
156 {
157 CAL_Obj *obj = (CAL_Obj *)handle;
158
159 return(&(obj->offsetHandle_V[0]));
160 } // end of CAL_getOffsetHandleAddr_V() function
161
162
167 static inline _iq CAL_getOffsetValue_I(CAL_Handle handle,
168 const uint_least8_t sensorNumber)
169 {
170 CAL_Obj *obj = (CAL_Obj *)handle;
171
172 _iq offset = OFFSET_getOffset(obj->offsetHandle_I[sensorNumber]);
173
174 return(offset);
175 } // end of CAL_getOffsetValue_I() function
176
177
182 static inline _iq CAL_getOffsetValue_V(CAL_Handle handle,
183 const uint_least8_t sensorNumber)
184 {
185 CAL_Obj *obj = (CAL_Obj *)handle;
186
187 _iq offset = OFFSET_getOffset(obj->offsetHandle_V[sensorNumber]);
188
189 return(offset);
190 } // end of CAL_getOffsetValue_V() function
191
192
196 static inline CAL_State_e CAL_getState(CAL_Handle handle)
197 {
198 CAL_Obj *obj = (CAL_Obj *)handle;
199
200 return(obj->state);
201 } // end of CAL_getState() function
202
203
208 static inline uint_least32_t CAL_getWaitTime(CAL_Handle handle,const CAL_State_e state)
209 {
210 CAL_Obj *obj = (CAL_Obj *)handle;
211
212 return(obj->waitTimes[state]);
213 } // end of CAL_getWaitTime() function
214
215
218 static inline void CAL_incrCounter_state(CAL_Handle handle)
219 {
220 CAL_Obj *obj = (CAL_Obj *)handle;
221 uint_least32_t count = obj->counter_state;
222
223 count++;
224
225 obj->counter_state = count;
226
227 return;
228 } // end of CAL_incrCounter_state() function
229
230
235 extern CAL_Handle CAL_init(void *pMemory,const size_t numBytes);
236
237
241 static inline bool CAL_isEnabled(CAL_Handle handle)
242 {
243 CAL_Obj *obj = (CAL_Obj *)handle;
244
245 return(obj->flag_enable);
246 } // end of CAL_isEnabled() function
247
248
252 static inline bool CAL_isError(CAL_Handle handle)
253 {
254 CAL_State_e calState = CAL_getState(handle);
255 bool state = false;
256
257
258 // check for controller errors
259 if(calState == CAL_State_Error)
260 {
261 state = true;
262 }
263
264 return(state);
265 } // end of CAL_isError() function
266
267
271 static inline bool CAL_isIdle(CAL_Handle handle)
272 {
273 CAL_State_e state = CAL_getState(handle);
274 bool result = false;
275
276 if(state == CAL_State_Idle)
277 {
278 result = true;
279 }
280
281 return(result);
282 } // end of CAL_isIdle() function
283
284
288 static inline bool CAL_isNotIdle(CAL_Handle handle)
289 {
290 CAL_State_e state = CAL_getState(handle);
291 bool result = true;
292
293 if(state == CAL_State_Idle)
294 {
295 result = false;
296 }
297
298 return(result);
299 } // end of CAL_isNotIdle() function
300
301
304 extern void CAL_reset(CAL_Handle handle);
305
306
309 static inline void CAL_resetCounter_state(CAL_Handle handle)
310 {
311 CAL_Obj *obj = (CAL_Obj *)handle;
312
313 obj->counter_state = 0;
314
315 return;
316 } // end of CAL_resetCounter_state() function
317
318
322 static inline void CAL_setCount_state(CAL_Handle handle,const uint_least32_t count)
323 {
324 CAL_Obj *obj = (CAL_Obj *)handle;
325
326 obj->counter_state = count;
327
328 return;
329 } // end of CAL_setCount_state() function
330
331
335 static inline void CAL_setFlag_enable(CAL_Handle handle,const bool value)
336 {
337 CAL_Obj *obj = (CAL_Obj *)handle;
338
339 obj->flag_enable = value;
340
341 return;
342 } // end of CAL_setFlag_enable() function
343
344
348 static inline void CAL_setFlag_enableAdcOffset(CAL_Handle handle,const bool value)
349 {
350 CAL_Obj *obj = (CAL_Obj *)handle;
351
352 obj->flag_enableAdcOffset = value;
353
354 return;
355 } // end of CAL_setFlag_enableAdcOffset() function
356
357
361 extern void CAL_setParams(CAL_Handle handle,
362 const USER_Params *pUserParams);
363
364
368 static inline void CAL_setState(CAL_Handle handle,const CAL_State_e state)
369 {
370 CAL_Obj *obj = (CAL_Obj *)handle;
371
372 obj->state = state;
373
374 return;
375 } // end of CAL_setState() function
376
377
382 static inline void CAL_setWaitTime(CAL_Handle handle,const CAL_State_e state,const uint_least32_t waitTime)
383 {
384 CAL_Obj *obj = (CAL_Obj *)handle;
385
386 obj->waitTimes[state] = waitTime;
387
388 return;
389 } // end of CAL_setWaitTime() function
390
391
395 extern void CAL_setWaitTimes(CAL_Handle handle,const uint_least32_t *pWaitTimes);
396
397
400 static inline void CAL_setup(CAL_Handle handle)
401 {
402
403 return;
404 } // end of CAL_setup() function
405
406
409 static inline void CAL_run(CAL_Handle handle,const HAL_AdcData_t *pAdcData)
410 {
411 CAL_State_e state = CAL_getState(handle);
412
413
414 // compute the Adc offset
415 if(state == CAL_State_AdcOffset)
416 {
417 CAL_Obj *obj = (CAL_Obj *)handle;
418 uint_least8_t cnt;
419
420 // estimate the current offsets
421 for(cnt=0;cnt<USER_NUM_CURRENT_SENSORS;cnt++)
422 {
423 OFFSET_run(obj->offsetHandle_I[cnt],pAdcData->I_pu.value[cnt]);
424 }
425
426
427 // estimate the voltage offsets
428 for(cnt=0;cnt<USER_NUM_VOLTAGE_SENSORS;cnt++)
429 {
430 OFFSET_run(obj->offsetHandle_V[cnt],pAdcData->V_pu.value[cnt]);
431 }
432 }
433
434
435 // increment the state counter
436 CAL_incrCounter_state(handle);
437
438 return;
439 } // end of CAL_run() function
440
441
444 extern bool CAL_updateState(CAL_Handle handle);
445
446
447 #ifdef __cplusplus
448 }
449 #endif // extern "C"
450
452
453 #endif // end of _CAL_H_ definition
454
455
CAL_getFlag_enable
static bool CAL_getFlag_enable(CAL_Handle handle)
Gets the value of the enable flag.
Definition: 32b/cal.h:122
CAL_enable
static void CAL_enable(CAL_Handle handle)
Enables the calibrator (CAL) module.
Definition: 32b/cal.h:98
_CAL_Obj_::flag_enableAdcOffset
bool flag_enableAdcOffset
the enable ADC offset calibration flag
Definition: 32b/cal.h:68
_CAL_Obj_::offset_I
OFFSET_Obj offset_I[USER_NUM_CURRENT_SENSORS]
the current offset objects
Definition: 32b/cal.h:62
types.h
Contains the public interface to the types definitions.
CAL_run
static void CAL_run(CAL_Handle handle, const HAL_AdcData_t *pAdcData)
Runs the calibrator (CAL) module.
Definition: 32b/cal.h:409
_CAL_Obj_::state
CAL_State_e state
the current state
Definition: 32b/cal.h:56
offset.h
Contains the public interface to the offset (OFFSET) module routines.
_MATH_vec3_::value
_iq value[3]
Definition: 32b/math.h:261
CAL_setFlag_enableAdcOffset
static void CAL_setFlag_enableAdcOffset(CAL_Handle handle, const bool value)
Sets the value of the enable ADC offset flag.
Definition: 32b/cal.h:348
_USER_Params_
Defines a structure for the user parameters.
Definition: fast/src/32b/userParams.h:193
_CAL_Obj_::offsetHandle_V
OFFSET_Handle offsetHandle_V[USER_NUM_VOLTAGE_SENSORS]
the handles for the voltage offset estimators
Definition: 32b/cal.h:64
_CAL_Obj_
Defines the calibrator (CAL) object.
Definition: 32b/cal.h:54
CAL_State_Error
error state
Definition: cal_states.h:48
CAL_setParams
void CAL_setParams(CAL_Handle handle, const USER_Params *pUserParams)
Sets the parameters.
Definition: 32b/cal.c:67
CAL_resetCounter_state
static void CAL_resetCounter_state(CAL_Handle handle)
Resets the state count value.
Definition: 32b/cal.h:309
_iq
long _iq
Definition: 32b/IQmathLib.h:223
CAL_setCount_state
static void CAL_setCount_state(CAL_Handle handle, const uint_least32_t count)
Sets the state count value.
Definition: 32b/cal.h:322
CAL_isIdle
static bool CAL_isIdle(CAL_Handle handle)
Determines if the calibrator is in the idle state.
Definition: 32b/cal.h:271
CAL_isNotIdle
static bool CAL_isNotIdle(CAL_Handle handle)
Determines if the calibrator is not in the idle state.
Definition: 32b/cal.h:288
CAL_State_e
CAL_State_e
Defines the CAL states.
Definition: cal_states.h:46
CAL_incrCounter_state
static void CAL_incrCounter_state(CAL_Handle handle)
Increments the state count value.
Definition: 32b/cal.h:218
CAL_getFlag_enableAdcOffset
static bool CAL_getFlag_enableAdcOffset(CAL_Handle handle)
Gets the value of the enable ADC offset flag.
Definition: 32b/cal.h:133
CAL_reset
void CAL_reset(CAL_Handle handle)
Resets the calibrator.
Definition: 32b/cal.c:57
OFFSET_Handle
struct _OFFSET_Obj_ * OFFSET_Handle
Defines the OFFSET handle.
Definition: 32b/offset.h:95
math.h
Contains the public interface to the math (MATH) module routines.
CAL_Obj
struct _CAL_Obj_ CAL_Obj
Defines the calibrator (CAL) object.
CAL_disable
static void CAL_disable(CAL_Handle handle)
Disables the calibrator (CAL) module.
Definition: 32b/cal.h:86
_CAL_Obj_::flag_enable
bool flag_enable
the enable flag
Definition: 32b/cal.h:67
CAL_State_Idle
idle state
Definition: cal_states.h:49
_CAL_Obj_::offsetHandle_I
OFFSET_Handle offsetHandle_I[USER_NUM_CURRENT_SENSORS]
the handles for the current offset estimators
Definition: 32b/cal.h:61
CAL_setWaitTime
static void CAL_setWaitTime(CAL_Handle handle, const CAL_State_e state, const uint_least32_t waitTime)
Sets the wait time for a given state.
Definition: 32b/cal.h:382
hal_data.h
Contains the HAL data structures.
_CAL_Obj_::offset_V
OFFSET_Obj offset_V[USER_NUM_VOLTAGE_SENSORS]
the voltage offset objects
Definition: 32b/cal.h:65
CAL_getOffsetHandleAddr_I
static OFFSET_Handle * CAL_getOffsetHandleAddr_I(CAL_Handle handle)
Gets the current offset handle address.
Definition: 32b/cal.h:144
CAL_getOffsetValue_V
static _iq CAL_getOffsetValue_V(CAL_Handle handle, const uint_least8_t sensorNumber)
Gets the voltage offset value.
Definition: 32b/cal.h:182
CAL_setWaitTimes
void CAL_setWaitTimes(CAL_Handle handle, const uint_least32_t *pWaitTimes)
Sets the wait times.
Definition: 32b/cal.c:104
_CAL_Obj_::waitTimes
uint_least32_t waitTimes[CAL_numStates]
an array of wait times for each state, calibration clock counts
Definition: 32b/cal.h:59
CAL_isError
static bool CAL_isError(CAL_Handle handle)
Determines if there is a calibrator error.
Definition: 32b/cal.h:252
CAL_setup
static void CAL_setup(CAL_Handle handle)
Sets up the calibrator (CAL) module.
Definition: 32b/cal.h:400
CAL_setFlag_enable
static void CAL_setFlag_enable(CAL_Handle handle, const bool value)
Sets the value of the enable flag.
Definition: 32b/cal.h:335
CAL_getCount_state
static uint_least32_t CAL_getCount_state(CAL_Handle handle)
Gets the state count value.
Definition: 32b/cal.h:111
CAL_getState
static CAL_State_e CAL_getState(CAL_Handle handle)
Gets the calibration state.
Definition: 32b/cal.h:196
_HAL_AdcData_t_::V_pu
MATH_vec3 V_pu
the voltage values
Definition: 32b/hal_data.h:49
CAL_init
CAL_Handle CAL_init(void *pMemory, const size_t numBytes)
Initializes the calibrator (CAL) module.
Definition: 32b/cal.c:21
userParams.h
_HAL_AdcData_t_
Defines the ADC data.
Definition: boostxldrv8301_revB/f28x/f2806x/src/hal_obj.h:88
CAL_State_AdcOffset
ADC offset calibration state.
Definition: cal_states.h:50
cal_states.h
Contains the public interface to the calibration (CAL) module routines.
CAL_getOffsetValue_I
static _iq CAL_getOffsetValue_I(CAL_Handle handle, const uint_least8_t sensorNumber)
Gets the current offset value.
Definition: 32b/cal.h:167
CAL_updateState
bool CAL_updateState(CAL_Handle handle)
Updates the calibrator (CAL) state.
Definition: 32b/cal.c:117
CAL_isEnabled
static bool CAL_isEnabled(CAL_Handle handle)
Returns a boolean value denoting if the module is enabled (true) or not (false)
Definition: 32b/cal.h:241
CAL_setState
static void CAL_setState(CAL_Handle handle, const CAL_State_e state)
Sets the calibration state.
Definition: 32b/cal.h:368
CAL_Handle
struct _CAL_Obj_ * CAL_Handle
Defines the CAL handle.
Definition: 32b/cal.h:74
_CAL_Obj_::counter_state
uint_least32_t counter_state
the state counter
Definition: 32b/cal.h:58
OFFSET_run
static void OFFSET_run(OFFSET_Handle handle, const _iq inputValue)
Runs an offset filter of the form y[n] = beta*(x[n]+bias) + (1 - beta)*y[n-1] y -> The DC offset x ->...
Definition: 32b/offset.h:137
CAL_numStates
the total number of states
Definition: cal_states.h:52
_HAL_AdcData_t_::I_pu
MATH_vec3 I_pu
the current values
Definition: 32b/hal_data.h:47
OFFSET_getOffset
static _iq OFFSET_getOffset(OFFSET_Handle handle)
Gets the offset value.
Definition: 32b/offset.h:115
CAL_getWaitTime
static uint_least32_t CAL_getWaitTime(CAL_Handle handle, const CAL_State_e state)
Gets the wait time for a given state.
Definition: 32b/cal.h:208
_OFFSET_
Defines the offset (OFFSET) object.
Definition: 32b/offset.h:82
CAL_getOffsetHandleAddr_V
static OFFSET_Handle * CAL_getOffsetHandleAddr_V(CAL_Handle handle)
Gets the voltage offset handle address.
Definition: 32b/cal.h:155