MotorWare f2806x Module API Documentation
float/cal.c
Go to the documentation of this file.
1 
7 
8 // **************************************************************************
9 // the includes
10 
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  float_t beta_lp_rps = 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_rps);
77  OFFSET_setInitCond(obj->offsetHandle_I[cnt],0.0);
78  OFFSET_setOffset(obj->offsetHandle_I[cnt],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_rps);
85  OFFSET_setInitCond(obj->offsetHandle_V[cnt],0.0);
86  OFFSET_setOffset(obj->offsetHandle_V[cnt],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 
99 
100  return;
101 } // end of CAL_setParams() function
102 
103 
104 void CAL_setWaitTimes(CAL_Handle handle,const int_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 
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  int_least32_t waitTime = CAL_getWaitTime(handle,state);
127  int_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  {
148  }
149  else
150  {
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
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
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
static bool CAL_getFlag_enable(CAL_Handle handle)
Gets the value of the enable flag.
Definition: 32b/cal.h:122
OFFSET_Obj offset_I[USER_NUM_CURRENT_SENSORS]
the current offset objects
Definition: 32b/cal.h:62
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
Defines a structure for the user parameters.
OFFSET_Handle offsetHandle_V[USER_NUM_VOLTAGE_SENSORS]
the handles for the voltage offset estimators
Definition: 32b/cal.h:64
Defines the calibrator (CAL) object.
Definition: 32b/cal.h:54
error state
Definition: cal_states.h:48
void CAL_setParams(CAL_Handle handle, const USER_Params *pUserParams)
Sets the parameters.
Definition: float/cal.c:67
static void CAL_resetCounter_state(CAL_Handle handle)
Resets the state count value.
Definition: 32b/cal.h:309
static void CAL_setCount_state(CAL_Handle handle, const uint_least32_t count)
Sets the state count value.
Definition: 32b/cal.h:322
static bool CAL_isNotIdle(CAL_Handle handle)
Determines if the calibrator is not in the idle state.
Definition: 32b/cal.h:288
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
Defines the CAL states.
Definition: cal_states.h:46
static bool CAL_getFlag_enableAdcOffset(CAL_Handle handle)
Gets the value of the enable ADC offset flag.
Definition: 32b/cal.h:133
void CAL_reset(CAL_Handle handle)
Resets the calibrator.
Definition: float/cal.c:57
void OFFSET_setOffset(OFFSET_Handle handle, _iq offsetValue)
Sets the offset value.
Definition: 32b/offset.c:113
float_t offsetPole_rps
Defines the pole location for the voltage and current offset estimation, rad/s.
idle state
Definition: cal_states.h:49
OFFSET_Handle offsetHandle_I[USER_NUM_CURRENT_SENSORS]
the handles for the current offset estimators
Definition: 32b/cal.h:61
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
OFFSET_Obj offset_V[USER_NUM_VOLTAGE_SENSORS]
the voltage offset objects
Definition: 32b/cal.h:65
void OFFSET_setBeta(OFFSET_Handle handle, const _iq beta)
Sets the beta offset filter coefficient.
Definition: 32b/offset.c:88
static void CAL_setFlag_enable(CAL_Handle handle, const bool value)
Sets the value of the enable flag.
Definition: 32b/cal.h:335
static uint_least32_t CAL_getCount_state(CAL_Handle handle)
Gets the state count value.
Definition: 32b/cal.h:111
Contains the public interface to the calibrator (CAL) module routines.
static CAL_State_e CAL_getState(CAL_Handle handle)
Gets the calibration state.
Definition: 32b/cal.h:196
uint_least32_t ctrlFreq_Hz
Defines the controller frequency, Hz.
CAL_Handle CAL_init(void *pMemory, const size_t numBytes)
Initializes the calibrator (CAL) module.
Definition: float/cal.c:21
ADC offset calibration state.
Definition: cal_states.h:50
done state
Definition: cal_states.h:51
OFFSET_Handle OFFSET_init(void *pMemory, const size_t numBytes)
Initializes the offset.
Definition: 32b/offset.c:70
bool CAL_updateState(CAL_Handle handle)
Updates the calibrator (CAL) state.
Definition: float/cal.c:117
static void CAL_setState(CAL_Handle handle, const CAL_State_e state)
Sets the calibration state.
Definition: 32b/cal.h:368
struct _CAL_Obj_ * CAL_Handle
Defines the CAL handle.
Definition: 32b/cal.h:74
the total number of states
Definition: cal_states.h:52
int_least32_t calWaitTime[CAL_numStates]
Defines the wait times for each calibrator state, isr ticks.
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 float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121
void CAL_setWaitTimes(CAL_Handle handle, const int_least32_t *pWaitTimes)
Sets the wait times.
Definition: float/cal.c:104