MotorWare f2806x Module API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

32b/cal.c
Go to the documentation of this file.
1
7
8 // **************************************************************************
9 // the includes
10
11 #include "sw/modules/cal/src/32b/cal.h"
12
13
14 // **************************************************************************
15 // the globals
16
17
18 // **************************************************************************
19 // the functions
20
21 CAL_Handle CAL_init(void *pMemory,const size_t numBytes)
22 {
23 uint_least8_t cnt;
24 CAL_Handle handle;
25 CAL_Obj *obj;
26
27
28 if(numBytes < sizeof(CAL_Obj))
29 return((CAL_Handle)NULL);
30
31
32 // assign the handle
33 handle = (CAL_Handle)pMemory;
34
35
36 // assign the object
37 obj = (CAL_Obj *)handle;
38
39
40 // initialize the current offset estimator handles
41 for(cnt=0;cnt<USER_NUM_CURRENT_SENSORS;cnt++)
42 {
43 obj->offsetHandle_I[cnt] = OFFSET_init(&obj->offset_I[cnt],sizeof(obj->offset_I[cnt]));
44 }
45
46
47 // initialize the voltage offset estimator handles
48 for(cnt=0;cnt<USER_NUM_VOLTAGE_SENSORS;cnt++)
49 {
50 obj->offsetHandle_V[cnt] = OFFSET_init(&obj->offset_V[cnt],sizeof(obj->offset_V[cnt]));
51 }
52
53 return(handle);
54 } // end of CAL_init() function
55
56
57 void CAL_reset(CAL_Handle handle)
58 {
59 // CAL_Obj *obj = (CAL_Obj *)handle;
60
61 // could reset the offset values here
62
63 return;
64 } // end of CAL_reset() function
65
66
67 void CAL_setParams(CAL_Handle handle,const USER_Params *pUserParams)
68 {
69 CAL_Obj *obj = (CAL_Obj *)handle;
70 _iq beta_lp_pu = _IQ(pUserParams->offsetPole_rps/(float_t)pUserParams->ctrlFreq_Hz);
71 uint_least8_t cnt;
72
73
74 for(cnt=0;cnt<USER_NUM_CURRENT_SENSORS;cnt++)
75 {
76 OFFSET_setBeta(obj->offsetHandle_I[cnt],beta_lp_pu);
77 OFFSET_setInitCond(obj->offsetHandle_I[cnt],_IQ(0.0));
78 OFFSET_setOffset(obj->offsetHandle_I[cnt],_IQ(0.0));
79 }
80
81
82 for(cnt=0;cnt<USER_NUM_VOLTAGE_SENSORS;cnt++)
83 {
84 OFFSET_setBeta(obj->offsetHandle_V[cnt],beta_lp_pu);
85 OFFSET_setInitCond(obj->offsetHandle_V[cnt],_IQ(0.0));
86 OFFSET_setOffset(obj->offsetHandle_V[cnt],_IQ(0.0));
87 }
88
89
90 // set the wait times for each state
91 CAL_setWaitTimes(handle,&(pUserParams->calWaitTime[0]));
92
93 CAL_setCount_state(handle,0);
94
95 CAL_setFlag_enable(handle,false);
96 CAL_setFlag_enableAdcOffset(handle,true);
97
98 CAL_setState(handle,CAL_State_Idle);
99
100 return;
101 } // end of CAL_setParams() function
102
103
104 void CAL_setWaitTimes(CAL_Handle handle,const uint_least32_t *pWaitTimes)
105 {
106 uint_least8_t cnt;
107
108 for(cnt=0;cnt<CAL_numStates;cnt++)
109 {
110 CAL_setWaitTime(handle,(CAL_State_e)cnt,pWaitTimes[cnt]);
111 }
112
113 return;
114 } // end of CAL_setWaitTimes() function
115
116
117 bool CAL_updateState(CAL_Handle handle)
118 {
119 CAL_State_e state = CAL_getState(handle);
120 bool flag_enable = CAL_getFlag_enable(handle);
121 bool stateChanged = false;
122
123
124 if(flag_enable)
125 {
126 uint_least32_t waitTime = CAL_getWaitTime(handle,state);
127 uint_least32_t count_state = CAL_getCount_state(handle);
128
129
130 // check for errors
131 // NOTHING FOR NOW
132
133
134 // check count
135 if(count_state >= waitTime)
136 {
137
138 // reset the state counter
139 CAL_resetCounter_state(handle);
140
141
142 if(state == CAL_State_Idle)
143 {
144 // set the next state
145 if(CAL_getFlag_enableAdcOffset(handle))
146 {
147 CAL_setState(handle,CAL_State_AdcOffset);
148 }
149 else
150 {
151 CAL_setState(handle,CAL_State_Done);
152 }
153 }
154 else if(state == CAL_State_AdcOffset)
155 {
156 // clear the flag
157 CAL_setFlag_enableAdcOffset(handle,false);
158
159 // set the next state
160 CAL_setState(handle,CAL_State_Done);
161 }
162 }
163 }
164 else if(state != CAL_State_Error)
165 {
166 if(CAL_isNotIdle(handle))
167 {
168 // reset the calibrator
169 CAL_reset(handle);
170
171 // set the next state
172 CAL_setState(handle,CAL_State_Idle);
173 }
174 }
175
176
177 // check and see if the state changed
178 if(state != CAL_getState(handle))
179 {
180 stateChanged = true;
181 }
182
183 return(stateChanged);
184 } // end of CAL_updateState() function
185
186
187 // end of file
CAL_getFlag_enable
static bool CAL_getFlag_enable(CAL_Handle handle)
Gets the value of the enable flag.
Definition: 32b/cal.h:122
_CAL_Obj_::offset_I
OFFSET_Obj offset_I[USER_NUM_CURRENT_SENSORS]
the current offset objects
Definition: 32b/cal.h:62
_IQ
#define _IQ(A)
Definition: 32b/IQmathLib.h:319
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_isNotIdle
static bool CAL_isNotIdle(CAL_Handle handle)
Determines if the calibrator is not in the idle state.
Definition: 32b/cal.h:288
OFFSET_setInitCond
void OFFSET_setInitCond(OFFSET_Handle handle, const _iq initCond)
Set the initial condition of the integrator or the value of y[n-1].
Definition: 32b/offset.c:102
CAL_State_e
CAL_State_e
Defines the CAL states.
Definition: cal_states.h:46
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_setOffset
void OFFSET_setOffset(OFFSET_Handle handle, _iq offsetValue)
Sets the offset value.
Definition: 32b/offset.c:113
_USER_Params_::offsetPole_rps
float_t offsetPole_rps
Defines the pole location for the voltage and current offset estimation, rad/s.
Definition: fast/src/32b/userParams.h:207
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
_CAL_Obj_::offset_V
OFFSET_Obj offset_V[USER_NUM_VOLTAGE_SENSORS]
the voltage offset objects
Definition: 32b/cal.h:65
CAL_setWaitTimes
void CAL_setWaitTimes(CAL_Handle handle, const uint_least32_t *pWaitTimes)
Sets the wait times.
Definition: 32b/cal.c:104
OFFSET_setBeta
void OFFSET_setBeta(OFFSET_Handle handle, const _iq beta)
Sets the beta offset filter coefficient.
Definition: 32b/offset.c:88
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
_USER_Params_::ctrlFreq_Hz
uint_least32_t ctrlFreq_Hz
Defines the controller frequency, Hz.
Definition: fast/src/32b/userParams.h:253
CAL_init
CAL_Handle CAL_init(void *pMemory, const size_t numBytes)
Initializes the calibrator (CAL) module.
Definition: 32b/cal.c:21
CAL_State_AdcOffset
ADC offset calibration state.
Definition: cal_states.h:50
CAL_State_Done
done state
Definition: cal_states.h:51
OFFSET_init
OFFSET_Handle OFFSET_init(void *pMemory, const size_t numBytes)
Initializes the offset.
Definition: 32b/offset.c:70
cal.h
Contains the public interface to the calibrator (CAL) module routines.
CAL_updateState
bool CAL_updateState(CAL_Handle handle)
Updates the calibrator (CAL) state.
Definition: 32b/cal.c:117
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_numStates
the total number of states
Definition: cal_states.h:52
_USER_Params_::calWaitTime
int_least32_t calWaitTime[CAL_numStates]
Defines the wait times for each calibrator state, isr ticks.
Definition: user/src/float/userParams.h:117
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
float_t
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121