MotorWare f2806x Module API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

float/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/float/hal_data.h"
22 #include "sw/modules/math/src/float/math.h"
23 #include "sw/modules/offset/src/float/offset.h"
24 #include "sw/modules/user/src/float/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 int_least32_t counter_state;
59 int_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 int_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 float_t CAL_getOffsetValue_I(CAL_Handle handle,
168 const uint_least8_t sensorNumber)
169 {
170 CAL_Obj *obj = (CAL_Obj *)handle;
171
172 float_t offset = OFFSET_getOffset(obj->offsetHandle_I[sensorNumber]);
173
174 return(offset);
175 } // end of CAL_getOffsetValue_I() function
176
177
182 static inline float_t CAL_getOffsetValue_V(CAL_Handle handle,
183 const uint_least8_t sensorNumber)
184 {
185 CAL_Obj *obj = (CAL_Obj *)handle;
186
187 float_t 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 int_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 int_least32_t count = obj->counter_state;
222
223 // increment the count
224 count++;
225
226 // limit to 0 to INT_LEAST32_MAX - 1
227 if(count == INT_LEAST32_MAX)
228 {
229 count = 0;
230 }
231
232 // save the count value
233 obj->counter_state = count;
234
235 return;
236 } // end of CAL_incrCounter_state() function
237
238
243 extern CAL_Handle CAL_init(void *pMemory,const size_t numBytes);
244
245
249 static inline bool CAL_isEnabled(CAL_Handle handle)
250 {
251 CAL_Obj *obj = (CAL_Obj *)handle;
252
253 return(obj->flag_enable);
254 } // end of CAL_isEnabled() function
255
256
260 static inline bool CAL_isError(CAL_Handle handle)
261 {
262 CAL_State_e calState = CAL_getState(handle);
263 bool state = false;
264
265
266 // check for controller errors
267 if(calState == CAL_State_Error)
268 {
269 state = true;
270 }
271
272 return(state);
273 } // end of CAL_isError() function
274
275
279 static inline bool CAL_isIdle(CAL_Handle handle)
280 {
281 CAL_State_e state = CAL_getState(handle);
282 bool result = false;
283
284 if(state == CAL_State_Idle)
285 {
286 result = true;
287 }
288
289 return(result);
290 } // end of CAL_isIdle() function
291
292
296 static inline bool CAL_isNotIdle(CAL_Handle handle)
297 {
298 CAL_State_e state = CAL_getState(handle);
299 bool result = true;
300
301 if(state == CAL_State_Idle)
302 {
303 result = false;
304 }
305
306 return(result);
307 } // end of CAL_isNotIdle() function
308
309
312 extern void CAL_reset(CAL_Handle handle);
313
314
317 static inline void CAL_resetCounter_state(CAL_Handle handle)
318 {
319 CAL_Obj *obj = (CAL_Obj *)handle;
320
321 obj->counter_state = 0;
322
323 return;
324 } // end of CAL_resetCounter_state() function
325
326
330 static inline void CAL_setCount_state(CAL_Handle handle,const int_least32_t count)
331 {
332 CAL_Obj *obj = (CAL_Obj *)handle;
333
334 obj->counter_state = count;
335
336 return;
337 } // end of CAL_setCount_state() function
338
339
343 static inline void CAL_setFlag_enable(CAL_Handle handle,const bool value)
344 {
345 CAL_Obj *obj = (CAL_Obj *)handle;
346
347 obj->flag_enable = value;
348
349 return;
350 } // end of CAL_setFlag_enable() function
351
352
356 static inline void CAL_setFlag_enableAdcOffset(CAL_Handle handle,const bool value)
357 {
358 CAL_Obj *obj = (CAL_Obj *)handle;
359
360 obj->flag_enableAdcOffset = value;
361
362 return;
363 } // end of CAL_setFlag_enableAdcOffset() function
364
365
369 extern void CAL_setParams(CAL_Handle handle,
370 const USER_Params *pUserParams);
371
372
376 static inline void CAL_setState(CAL_Handle handle,const CAL_State_e state)
377 {
378 CAL_Obj *obj = (CAL_Obj *)handle;
379
380 obj->state = state;
381
382 return;
383 } // end of CAL_setState() function
384
385
390 static inline void CAL_setWaitTime(CAL_Handle handle,const CAL_State_e state,const int_least32_t waitTime)
391 {
392 CAL_Obj *obj = (CAL_Obj *)handle;
393
394 obj->waitTimes[state] = waitTime;
395
396 return;
397 } // end of CAL_setWaitTime() function
398
399
403 extern void CAL_setWaitTimes(CAL_Handle handle,const int_least32_t *pWaitTimes);
404
405
408 static inline void CAL_setup(CAL_Handle handle)
409 {
410
411 return;
412 } // end of CAL_setup() function
413
414
417 static inline void CAL_run(CAL_Handle handle,const HAL_AdcData_t *pAdcData)
418 {
419 CAL_State_e state = CAL_getState(handle);
420
421
422 // compute the Adc offset
423 if(state == CAL_State_AdcOffset)
424 {
425 CAL_Obj *obj = (CAL_Obj *)handle;
426 uint_least8_t cnt;
427
428 // estimate the current offsets
429 for(cnt=0;cnt<USER_NUM_CURRENT_SENSORS;cnt++)
430 {
431 OFFSET_run(obj->offsetHandle_I[cnt],pAdcData->I_A.value[cnt]);
432 }
433
434
435 // estimate the voltage offsets
436 for(cnt=0;cnt<USER_NUM_VOLTAGE_SENSORS;cnt++)
437 {
438 OFFSET_run(obj->offsetHandle_V[cnt],pAdcData->V_V.value[cnt]);
439 }
440 }
441
442
443 // increment the state counter
444 CAL_incrCounter_state(handle);
445
446 return;
447 } // end of CAL_run() function
448
449
452 extern bool CAL_updateState(CAL_Handle handle);
453
454
455 #ifdef __cplusplus
456 }
457 #endif // extern "C"
458
460
461 #endif // end of _CAL_H_ definition
462
463
CAL_isEnabled
static bool CAL_isEnabled(CAL_Handle handle)
Returns a boolean value denoting if the module is enabled (true) or not (false)
Definition: float/cal.h:249
_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_getFlag_enable
static bool CAL_getFlag_enable(CAL_Handle handle)
Gets the value of the enable flag.
Definition: float/cal.h:122
CAL_getOffsetValue_I
static float_t CAL_getOffsetValue_I(CAL_Handle handle, const uint_least8_t sensorNumber)
Gets the current offset value.
Definition: float/cal.h:167
_CAL_Obj_::state
CAL_State_e state
the current state
Definition: 32b/cal.h:56
CAL_getOffsetHandleAddr_V
static OFFSET_Handle * CAL_getOffsetHandleAddr_V(CAL_Handle handle)
Gets the voltage offset handle address.
Definition: float/cal.h:155
math.h
Contains the public interface to the math (MATH) module routines.
_CAL_Obj_::counter_state
int_least32_t counter_state
the state counter
Definition: float/cal.h:58
_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: float/cal.h:356
CAL_getState
static CAL_State_e CAL_getState(CAL_Handle handle)
Gets the calibration state.
Definition: float/cal.h:196
CAL_disable
static void CAL_disable(CAL_Handle handle)
Disables the calibrator (CAL) module.
Definition: float/cal.h:86
CAL_run
static void CAL_run(CAL_Handle handle, const HAL_AdcData_t *pAdcData)
Runs the calibrator (CAL) module.
Definition: float/cal.h:417
_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_getOffsetValue_V
static float_t CAL_getOffsetValue_V(CAL_Handle handle, const uint_least8_t sensorNumber)
Gets the voltage offset value.
Definition: float/cal.h:182
CAL_setup
static void CAL_setup(CAL_Handle handle)
Sets up the calibrator (CAL) module.
Definition: float/cal.h:408
hal_data.h
Contains the HAL data structures.
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: float/cal.h:317
CAL_isIdle
static bool CAL_isIdle(CAL_Handle handle)
Determines if the calibrator is in the idle state.
Definition: float/cal.h:279
CAL_incrCounter_state
static void CAL_incrCounter_state(CAL_Handle handle)
Increments the state count value.
Definition: float/cal.h:218
CAL_setCount_state
static void CAL_setCount_state(CAL_Handle handle, const int_least32_t count)
Sets the state count value.
Definition: float/cal.h:330
CAL_getFlag_enableAdcOffset
static bool CAL_getFlag_enableAdcOffset(CAL_Handle handle)
Gets the value of the enable ADC offset flag.
Definition: float/cal.h:133
CAL_State_e
CAL_State_e
Defines the CAL states.
Definition: cal_states.h:46
CAL_enable
static void CAL_enable(CAL_Handle handle)
Enables the calibrator (CAL) module.
Definition: float/cal.h:98
CAL_reset
void CAL_reset(CAL_Handle handle)
Resets the calibrator.
Definition: 32b/cal.c:57
CAL_getOffsetHandleAddr_I
static OFFSET_Handle * CAL_getOffsetHandleAddr_I(CAL_Handle handle)
Gets the current offset handle address.
Definition: float/cal.h:144
OFFSET_Handle
struct _OFFSET_Obj_ * OFFSET_Handle
Defines the OFFSET handle.
Definition: 32b/offset.h:95
CAL_setFlag_enable
static void CAL_setFlag_enable(CAL_Handle handle, const bool value)
Sets the value of the enable flag.
Definition: float/cal.h:343
CAL_Obj
struct _CAL_Obj_ CAL_Obj
Defines the calibrator (CAL) object.
_HAL_AdcData_t_::I_A
MATH_vec3 I_A
the current values
Definition: float/hal_data.h:46
_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_Obj_::offset_V
OFFSET_Obj offset_V[USER_NUM_VOLTAGE_SENSORS]
the voltage offset objects
Definition: 32b/cal.h:65
CAL_setState
static void CAL_setState(CAL_Handle handle, const CAL_State_e state)
Sets the calibration state.
Definition: float/cal.h:376
_HAL_AdcData_t_::V_V
MATH_vec3 V_V
the voltage values
Definition: float/hal_data.h:48
_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_setWaitTime
static void CAL_setWaitTime(CAL_Handle handle, const CAL_State_e state, const int_least32_t waitTime)
Sets the wait time for a given state.
Definition: float/cal.h:390
CAL_init
CAL_Handle CAL_init(void *pMemory, const size_t numBytes)
Initializes the calibrator (CAL) module.
Definition: 32b/cal.c:21
_HAL_AdcData_t_
Defines the ADC data.
Definition: boostxldrv8301_revB/f28x/f2806x/src/hal_obj.h:88
CAL_isNotIdle
static bool CAL_isNotIdle(CAL_Handle handle)
Determines if the calibrator is not in the idle state.
Definition: float/cal.h:296
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_isError
static bool CAL_isError(CAL_Handle handle)
Determines if there is a calibrator error.
Definition: float/cal.h:260
CAL_updateState
bool CAL_updateState(CAL_Handle handle)
Updates the calibrator (CAL) state.
Definition: 32b/cal.c:117
userParams.h
Contains the user related definitions.
CAL_Handle
struct _CAL_Obj_ * CAL_Handle
Defines the CAL handle.
Definition: float/cal.h:74
_CAL_Obj_::counter_state
uint_least32_t counter_state
the state counter
Definition: 32b/cal.h:58
offset.h
Contains the public interface to the offset (OFFSET) module routines.
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
CAL_getCount_state
static int_least32_t CAL_getCount_state(CAL_Handle handle)
Gets the state count value.
Definition: float/cal.h:111
CAL_getWaitTime
static int_least32_t CAL_getWaitTime(CAL_Handle handle, const CAL_State_e state)
Gets the wait time for a given state.
Definition: float/cal.h:208
OFFSET_getOffset
static _iq OFFSET_getOffset(OFFSET_Handle handle)
Gets the offset value.
Definition: 32b/offset.h:115
float_t
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121
_OFFSET_
Defines the offset (OFFSET) object.
Definition: 32b/offset.h:82
CAL_setWaitTimes
void CAL_setWaitTimes(CAL_Handle handle, const int_least32_t *pWaitTimes)
Sets the wait times.
Definition: float/cal.c:104