instaspin_foc
fast_obs_im.c
Go to the documentation of this file.
1 
7 
8 // **************************************************************************
9 
10 // solutions
11 #include "fast_obs.h"
12 
13 
14 // **************************************************************************
15 // the defines
16 
17 
18 // **************************************************************************
19 // the globals
20 
21 EST_State_e gEstState = EST_State_Idle;
22 
23 volatile bool gFlag_enableSys = true;
24 
25 volatile bool gFlag_runOnLine = false;
26 
27 volatile bool gFlag_enableForceAngle = true;
28 
29 MATH_vec2 gIdq_A = {0.0, 0.0};
30 
32 
34 
36 
38 
40 
42 
44 
46 
47 volatile float_t gSpeed_Kp = 0.01;
48 
49 volatile float_t gSpeed_Ki = 0.001;
50 
52 
53 uint16_t gCounter_speed = 0;
54 
56 
58 
60 
62 
64 
66 
68 
69 MATH_vec3 gOffsets_I_A = {0.0, 0.0, 0.0};
70 
71 MATH_vec3 gOffsets_V_V = {0.0, 0.0, 0.0};
72 
75 
78 
81 
83 
86 
89 
92 
95 
98 
101 
104 
105 #ifdef DRV8301_SPI
106 // Watch window interface to the 8301 SPI
107 DRV_SPI_8301_Vars_t gDrvSpi8301Vars;
108 #endif
109 
115 
116 // **************************************************************************
117 // the functions
118 
119 void main(void)
120 {
121  uint_least8_t estNumber = 0;
122 
123  // initialize the user parameters
124  USER_setParams(&gUserParams);
125 
126  // initialize the user parameters
127  USER_setParams_priv(&gUserParams);
128 
129  // initialize the driver
130  halHandle = HAL_init(&hal,sizeof(hal));
131 
132  // set the driver parameters
133  HAL_setParams(halHandle,&gUserParams);
134 
135  // initialize the Clarke modules
136  clarkeHandle_I = CLARKE_init(&clarke_I,sizeof(clarke_I));
137  clarkeHandle_V = CLARKE_init(&clarke_V,sizeof(clarke_V));
138 
139  // set the Clarke parameters
140  setupClarke_I(clarkeHandle_I,gUserParams.numCurrentSensors);
141  setupClarke_V(clarkeHandle_V,gUserParams.numVoltageSensors);
142 
143  // initialize the estimator
144  estHandle = EST_initEst(estNumber);
145 
146  // set the default estimator parameters
147  EST_setParams(estHandle,&gUserParams);
150 
151  // initialize the inverse Park module
152  iparkHandle = IPARK_init(&ipark,sizeof(ipark));
153 
154  // initialize the Park module
155  parkHandle = PARK_init(&park,sizeof(park));
156 
157  // initialize the PI controllers
158  piHandle_Id = PI_init(&pi_Id, sizeof(pi_Id));
159  piHandle_Iq = PI_init(&pi_Iq, sizeof(pi_Iq));
160  piHandle_spd = PI_init(&pi_spd,sizeof(pi_spd));
161 
162  // setup the controllers
164 
165  // initialize the space vector generator module
166  svgenHandle = SVGEN_init(&svgen,sizeof(svgen));
167 
168  // initialize the Id trajectory
169  trajHandle_Id = TRAJ_init(&traj_Id,sizeof(traj_Id));
170 
171  // configure the Id trajectory. Configure a 5 seconds ramp
172  TRAJ_setTargetValue(trajHandle_Id,gUserParams.IdRated_A);
173  TRAJ_setIntValue(trajHandle_Id,0.0);
174  TRAJ_setMinValue(trajHandle_Id,gUserParams.IdRated_A * 0.3);
175  TRAJ_setMaxValue(trajHandle_Id,gUserParams.IdRated_A);
176  TRAJ_setMaxDelta(trajHandle_Id,gUserParams.IdRated_A / gUserParams.estFreq_Hz);
177 
178  // initialize the CPU usage module
179  cpu_usageHandle = CPU_USAGE_init(&cpu_usage,sizeof(cpu_usage));
180  CPU_USAGE_setParams(cpu_usageHandle,
181  (uint32_t)USER_SYSTEM_FREQ_MHz * 1000000, // timer period, cnts
182  (uint32_t)USER_ISR_FREQ_Hz); // average over 1 second of ISRs
183 
184  // setup faults
185  HAL_setupFaults(halHandle);
186 
187  // initialize the interrupt vector table
188  HAL_initIntVectorTable(halHandle);
189 
190  // enable the ADC interrupts
191  HAL_enableAdcInts(halHandle);
192 
193  // disable global interrupts
194  HAL_disableGlobalInts(halHandle);
195 
196  // enable debug interrupts
197  HAL_enableDebugInt(halHandle);
198 
199  // disable the PWM
200  HAL_disablePwm(halHandle);
201 
202  // set adcBias values
203  gOffsets_I_A.value[0] = IA_OFFSET_A;
204  gOffsets_I_A.value[1] = IB_OFFSET_A;
205  gOffsets_I_A.value[2] = IC_OFFSET_A;
206  gOffsets_V_V.value[0] = VA_OFFSET_V;
207  gOffsets_V_V.value[1] = VB_OFFSET_V;
208  gOffsets_V_V.value[2] = VC_OFFSET_V;
209 
210 #ifdef DRV8301_SPI
211  // turn on the DRV8301 if present
212  HAL_enableDrv(halHandle);
213  // initialize the DRV8301 interface
214  HAL_setupDrvSpi(halHandle,&gDrvSpi8301Vars);
215 #endif
216 
217  // Waiting for enable system flag to be set
218  while(!gFlag_enableSys);
219 
220  // loop while the enable system flag is true
221  while(gFlag_enableSys)
222  {
223  // set custom speed controller gains
224  PI_setGains(piHandle_spd,gSpeed_Kp,gSpeed_Ki);
225 
226  // enable or disable force angle
228 
229  if(gFlag_runOnLine)
230  {
231  // enable the estimator
233 
234  // enable the PWM
235  HAL_enablePwm(halHandle);
236 
237  // enable global interrupts
238  HAL_enableGlobalInts(halHandle);
239  }
240  else
241  {
242  // disable the estimator
244 
245  // disable the PWM
246  HAL_disablePwm(halHandle);
247 
248  // disable global interrupts
249  HAL_disableGlobalInts(halHandle);
250 
251  // acknowledge the ADC interrupt to clear any possible pending interrupts
252  HAL_acqAdcInt(halHandle,ADC_IntNumber_6);
253 
254  // clear integral outputs of the controllers
255  PI_setUi(piHandle_Id,0.0);
256  PI_setUi(piHandle_Iq,0.0);
257  PI_setUi(piHandle_spd,0.0);
258 
259  // clear current references
260  gIq_ref_A = 0.0;
261 
262  // clear the Id trajectory
263  TRAJ_setIntValue(trajHandle_Id,0.0);
264 
265  // clear PWM data
266  gPwmData.Vabc_pu.value[0] = 0.0;
267  gPwmData.Vabc_pu.value[1] = 0.0;
268  gPwmData.Vabc_pu.value[2] = 0.0;
269  }
270 
271  // update the estimator state
273 
274  // update the global variables
276 
277  // update CPU usage
278  updateCPUusage();
279 
280 #ifdef DRV8301_SPI
281  HAL_writeDrvData(halHandle,&gDrvSpi8301Vars);
282 
283  HAL_readDrvData(halHandle,&gDrvSpi8301Vars);
284 #endif
285 
286  } // end of while() loop
287 
288  // disable the PWM
289  HAL_disablePwm(halHandle);
290 
291 } // end of main() function
292 
293 
294 interrupt void mainISR(void)
295 {
296  uint32_t timer1Cnt;
297  float_t angleDelta_rad;
298  float_t angleWithDelay_rad;
299  float_t outMax_V;
300  MATH_vec2 phasor;
301  MATH_vec2 Vab_out_V;
302  MATH_vec2 Vdq_out_V;
303  HAL_AdcData_t AdcDataWithOffset;
304 
305  // read the timer 1 value and update the CPU usage module
306  timer1Cnt = HAL_readTimerCnt(halHandle,1);
307  CPU_USAGE_updateCnts(cpu_usageHandle,timer1Cnt);
308 
309  // acknowledge the ADC interrupt
310  HAL_acqAdcInt(halHandle,ADC_IntNumber_6);
311 
312  // read the ADC data with offsets
313  HAL_readAdcDataWithOffsets(halHandle,&AdcDataWithOffset);
314 
315  // remove offsets
316  gAdcData.I_A.value[0] = AdcDataWithOffset.I_A.value[0] - gOffsets_I_A.value[0];
317  gAdcData.I_A.value[1] = AdcDataWithOffset.I_A.value[1] - gOffsets_I_A.value[1];
318  gAdcData.I_A.value[2] = AdcDataWithOffset.I_A.value[2] - gOffsets_I_A.value[2];
319  gAdcData.V_V.value[0] = AdcDataWithOffset.V_V.value[0] - gOffsets_V_V.value[0];
320  gAdcData.V_V.value[1] = AdcDataWithOffset.V_V.value[1] - gOffsets_V_V.value[1];
321  gAdcData.V_V.value[2] = AdcDataWithOffset.V_V.value[2] - gOffsets_V_V.value[2];
322  gAdcData.dcBus_V = AdcDataWithOffset.dcBus_V;
323 
324  // run Clarke transform on current
325  CLARKE_run(clarkeHandle_I,&(gAdcData.I_A),&(gEstInputData.Iab_A));
326 
327  // run Clarke transform on voltage
328  CLARKE_run(clarkeHandle_V,&(gAdcData.V_V),&(gEstInputData.Vab_V));
329 
330  // store the input data into a buffer
331  gEstInputData.dcBus_V = gAdcData.dcBus_V;
332  gEstInputData.speed_ref_Hz = gSpeed_ref_Hz;
333 
334  // run the estimator
335  EST_run(estHandle,&gEstInputData,&gEstOutputData);
336 
337  // run the speed controller
338  if(++gCounter_speed >= gUserParams.numCtrlTicksPerSpeedTick)
339  {
340  gCounter_speed = 0;
341 
342  PI_run_series(piHandle_spd,gEstInputData.speed_ref_Hz,gEstOutputData.fm_lp_rps * MATH_ONE_OVER_TWO_PI,0.0,&gIq_ref_A);
343  }
344 
345  // get Idq, reutilizing a Park transform used inside the estimator. This is optional, user's Park works as well
346  EST_getIdq_A(estHandle,&gIdq_A);
347 
348  // run a trajectory for Id, so magnetizing current is increased slowly
349  TRAJ_run(trajHandle_Id);
350 
351  // run the Id controller
352  PI_run_series(piHandle_Id,TRAJ_getIntValue(trajHandle_Id),gIdq_A.value[0],0.0,&(Vdq_out_V.value[0]));
353 
354  // calculate Iq controller limits, and run Iq controller using fast RTS function, callable assembly
355  outMax_V = sqrt_fastRTS((gUserParams.maxVsMag_V * gUserParams.maxVsMag_V) - (Vdq_out_V.value[0] * Vdq_out_V.value[0]));
356  PI_setMinMax(piHandle_Iq,-outMax_V,outMax_V);
357  PI_run_series(piHandle_Iq,gIq_ref_A,gIdq_A.value[1],0.0,&(Vdq_out_V.value[1]));
358 
359  // compute angle with delay compensation
360  angleDelta_rad = gUserParams.angleDelayed_sf_sec * gEstOutputData.fm_lp_rps;
361  angleWithDelay_rad = MATH_incrAngle(gEstOutputData.angle_rad, angleDelta_rad);
362 
363  // compute the sin/cos phasor using fast RTS function, callable assembly
364  sincos_fastRTS(angleWithDelay_rad, &(phasor.value[1]), &(phasor.value[0]));
365 
366  // set the phasor in the inverse Park transform
367  IPARK_setPhasor(iparkHandle,&phasor);
368 
369  // run the inverse Park module
370  IPARK_run(iparkHandle,&Vdq_out_V,&Vab_out_V);
371 
372  // setup the space vector generator (SVGEN) module
373  SVGEN_setup(svgenHandle,gEstOutputData.oneOverDcBus_invV);
374 
375  // run the space vector generator (SVGEN) module
376  SVGEN_run(svgenHandle,&Vab_out_V,&(gPwmData.Vabc_pu));
377 
378  // write the PWM compare values
379  HAL_writePwmData(halHandle,&gPwmData);
380 
381  // read the timer 1 value and update the CPU usage module
382  timer1Cnt = HAL_readTimerCnt(halHandle,1);
383  CPU_USAGE_updateCnts(cpu_usageHandle,timer1Cnt);
384 
385  // run the CPU usage module
386  CPU_USAGE_run(cpu_usageHandle);
387 
388  return;
389 } // end of mainISR() function
390 
391 
392 void setupClarke_I(CLARKE_Handle handle,const uint_least8_t numCurrentSensors)
393 {
394  float_t alpha_sf,beta_sf;
395 
396  // initialize the Clarke transform module for current
397  if(numCurrentSensors == 3)
398  {
399  alpha_sf = MATH_ONE_OVER_THREE;
400  beta_sf = MATH_ONE_OVER_SQRT_THREE;
401  }
402  else if(numCurrentSensors == 2)
403  {
404  alpha_sf = 1.0;
405  beta_sf = MATH_ONE_OVER_SQRT_THREE;
406  }
407  else
408  {
409  alpha_sf = 0.0;
410  beta_sf = 0.0;
411  }
412 
413  // set the parameters
414  CLARKE_setScaleFactors(handle,alpha_sf,beta_sf);
415  CLARKE_setNumSensors(handle,numCurrentSensors);
416 
417  return;
418 } // end of setupClarke_I() function
419 
420 
421 void setupClarke_V(CLARKE_Handle handle,const uint_least8_t numVoltageSensors)
422 {
423  float_t alpha_sf,beta_sf;
424 
425  // initialize the Clarke transform module for voltage
426  if(numVoltageSensors == 3)
427  {
428  alpha_sf = MATH_ONE_OVER_THREE;
429  beta_sf = MATH_ONE_OVER_SQRT_THREE;
430  }
431  else
432  {
433  alpha_sf = 0.0;
434  beta_sf = 0.0;
435  }
436 
437  // set the parameters
438  CLARKE_setScaleFactors(handle,alpha_sf,beta_sf);
439  CLARKE_setNumSensors(handle,numVoltageSensors);
440 
441  return;
442 } // end of setupClarke_V() function
443 
444 
446 {
447  float_t Ls_d_H = gUserParams.motor_Ls_d_H;
448  float_t Ls_q_H = gUserParams.motor_Ls_q_H;
449  float_t Rs_d_Ohm = gUserParams.motor_Rs_d_Ohm;
450  float_t Rs_q_Ohm = gUserParams.motor_Rs_q_Ohm;
451  float_t RdoverLd_rps = Rs_d_Ohm / Ls_d_H;
452  float_t RqoverLq_rps = Rs_q_Ohm / Ls_q_H;
453  float_t BWc_rps = gUserParams.BWc_rps;
454  float_t currentCtrlPeriod_sec = (float_t)gUserParams.numCtrlTicksPerCurrentTick / gUserParams.ctrlFreq_Hz;
455  float_t outMax_V = gUserParams.Vd_sf * gUserParams.maxVsMag_V;
456 
457  float_t Kp_Id = Ls_d_H * BWc_rps;
458  float_t Ki_Id = RdoverLd_rps * currentCtrlPeriod_sec;
459 
460  float_t Kp_Iq = Ls_q_H * BWc_rps;
461  float_t Ki_Iq = RqoverLq_rps * currentCtrlPeriod_sec;
462 
463  // set the Id controller
464  PI_setGains(piHandle_Id,Kp_Id,Ki_Id);
465  PI_setUi(piHandle_Id,0.0);
466  PI_setRefValue(piHandle_Id,0.0);
467  PI_setFbackValue(piHandle_Id,0.0);
468  PI_setFfwdValue(piHandle_Id,0.0);
469  PI_setMinMax(piHandle_Id,-outMax_V,outMax_V);
470 
471  // set the Iq controller
472  PI_setGains(piHandle_Iq,Kp_Iq,Ki_Iq);
473  PI_setUi(piHandle_Iq,0.0);
474  PI_setRefValue(piHandle_Iq,0.0);
475  PI_setFbackValue(piHandle_Iq,0.0);
476  PI_setFfwdValue(piHandle_Iq,0.0);
477  PI_setMinMax(piHandle_Iq,0.0,0.0);
478 
479  // set the speed controller
480  PI_setGains(piHandle_spd,gSpeed_Kp,gSpeed_Ki);
481  PI_setUi(piHandle_spd,0.0);
482  PI_setRefValue(piHandle_spd,0.0);
483  PI_setFbackValue(piHandle_spd,0.0);
484  PI_setFfwdValue(piHandle_spd,0.0);
485  PI_setMinMax(piHandle_spd,-gUserParams.maxCurrent_A,gUserParams.maxCurrent_A);
486 
487  return;
488 } // end of setupCurrentControllers() function
489 
490 
492 {
493  // get the states
494  gEstState = EST_getState(estHandle);
495 
496  // get the speed estimate
497  gSpeed_Hz = EST_getFm_lp_Hz(estHandle);
498 
499  // get the torque estimate
500  gTorque_Nm = EST_computeTorque_Nm(estHandle);
501 
502  // get the rotor resistance
503  gRr_Ohm = EST_getRr_d_Ohm(estHandle);
504 
505  // get the stator resistance
506  gRs_Ohm = EST_getRs_Ohm(estHandle);
507 
508  // get the stator inductance in the direct coordinate direction
509  gLs_d_H = EST_getLs_d_H(estHandle);
510 
511  // get the stator inductance in the quadrature coordinate direction
512  gLs_q_H = EST_getLs_q_H(estHandle);
513 
514  // get the IdRated value
515  gIdRated_A = EST_getIdRated_A(estHandle);
516 
517  // get the flux, Wb
518  gFlux_Wb = EST_getFlux_Wb(estHandle);
519 
520  return;
521 } // end of updateGlobalVariables_motor() function
522 
523 
524 void updateCPUusage(void)
525 {
526  uint32_t minDeltaCntObserved = CPU_USAGE_getMinDeltaCntObserved(cpu_usageHandle);
527  uint32_t avgDeltaCntObserved = CPU_USAGE_getAvgDeltaCntObserved(cpu_usageHandle);
528  uint32_t maxDeltaCntObserved = CPU_USAGE_getMaxDeltaCntObserved(cpu_usageHandle);
529  uint16_t pwmPeriod = HAL_readPwmPeriod(halHandle,PWM_Number_1);
530  float_t cpu_usage_den = (float_t)pwmPeriod * (float_t)USER_NUM_PWM_TICKS_PER_ISR_TICK * 2.0;
531 
532  // calculate the minimum cpu usage percentage
533  gCpuUsagePercentageMin = (float_t)minDeltaCntObserved / cpu_usage_den * 100.0;
534 
535  // calculate the average cpu usage percentage
536  gCpuUsagePercentageAvg = (float_t)avgDeltaCntObserved / cpu_usage_den * 100.0;
537 
538  // calculate the maximum cpu usage percentage
539  gCpuUsagePercentageMax = (float_t)maxDeltaCntObserved / cpu_usage_den * 100.0;
540 
541  return;
542 } // end of updateCPUusage() function
543 
544 
545 // end of file
546 
#define USER_SYSTEM_FREQ_MHz
CLOCKS & TIMERS.
Definition: user.h:140
EST_State_e gEstState
Global variable for the estimator state.
Definition: fast_obs_im.c:21
float_t angleDelayed_sf_sec
void EST_setFlag_enableForceAngle(EST_Handle handle, const bool state)
IPARK_Handle IPARK_init(void *pMemory, const size_t numBytes)
void main(void)
Definition: fast_obs_im.c:119
float_t gIq_ref_A
Definition: fast_obs_im.c:51
#define MATH_ONE_OVER_TWO_PI
static void TRAJ_setTargetValue(TRAJ_Handle handle, const _iq targetValue)
volatile float_t gSpeed_Kp
Definition: fast_obs_im.c:47
void HAL_enableGlobalInts(HAL_Handle handle)
void HAL_enableAdcInts(HAL_Handle handle)
float_t EST_getFlux_Wb(EST_Handle handle)
PI_Obj pi_Iq
the Iq PI controller object
Definition: fast_obs_im.c:94
CPU_USAGE_Handle cpu_usageHandle
Definition: fast_obs_im.c:110
void updateGlobalVariables_motor(EST_Handle estHandle)
Updates the global motor variables.
Definition: fast_obs_im.c:491
static void PI_setFfwdValue(PI_Handle handle, const _iq ffwdValue)
void HAL_disableGlobalInts(HAL_Handle handle)
MATH_vec3 Vabc_pu
static void HAL_readAdcDataWithOffsets(HAL_Handle handle, HAL_AdcData_t *pAdcData)
static void TRAJ_setMaxDelta(TRAJ_Handle handle, const _iq maxDelta)
float_t gLs_d_H
Global variable for the stator inductance in the direct coordinate direction, Henry.
Definition: fast_obs_im.c:35
IPARK_Handle iparkHandle
the handle for the inverse Park transform
Definition: fast_obs_im.c:84
float_t motor_Rs_d_Ohm
CLARKE_Obj clarke_V
the voltage Clarke transform object
Definition: fast_obs_im.c:77
static _iq TRAJ_getIntValue(TRAJ_Handle handle)
float_t gIdRated_A
Global variable for the rated Id current current, A.
Definition: fast_obs_im.c:31
float_t gCpuUsagePercentageAvg
Definition: fast_obs_im.c:113
static void HAL_writePwmData(HAL_Handle handle, HAL_PwmData_t *pPwmData)
float_t BWc_rps
_iq value[3]
struct _EST_Obj_ * EST_Handle
float_t maxCurrent_A
void HAL_writeDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
static void PI_setUi(PI_Handle handle, const _iq Ui)
PI_Handle piHandle_Iq
the handle for the Iq PI controller
Definition: fast_obs_im.c:93
static void HAL_acqAdcInt(HAL_Handle handle, const ADC_IntNumber_e intNumber)
float_t EST_getRr_d_Ohm(EST_Handle handle)
float_t gCpuUsagePercentageMin
Definition: fast_obs_im.c:112
float_t motor_Rs_q_Ohm
PARK_Handle parkHandle
the handle for the Park object
Definition: fast_obs_im.c:87
CPU_USAGE_Obj cpu_usage
Definition: fast_obs_im.c:111
uint_least8_t numCurrentSensors
MATH_vec3 gOffsets_V_V
Definition: fast_obs_im.c:71
PI_Obj pi_spd
the speed PI controller object
Definition: fast_obs_im.c:97
TRAJ_Obj traj_Id
the Id trajectory object
Definition: fast_obs_im.c:103
void EST_setParams(EST_Handle handle, USER_Params *pUserParams)
static void SVGEN_run(SVGEN_Handle handle, const MATH_vec2 *pVab, MATH_vec3 *pT)
static uint32_t CPU_USAGE_getAvgDeltaCntObserved(CPU_USAGE_Handle handle)
volatile bool gFlag_runOnLine
Definition: fast_obs_im.c:25
uint_least16_t numCtrlTicksPerCurrentTick
#define MATH_ONE_OVER_THREE
void USER_setParams(USER_Params *pUserParams)
Sets the user parameter values.
void setupClarke_V(CLARKE_Handle handle, const uint_least8_t numVoltageSensors)
Sets the number of voltage sensors.
Definition: fast_obs_im.c:421
float_t EST_computeTorque_Nm(EST_Handle handle)
float_t speed_ref_Hz
static void CLARKE_setScaleFactors(CLARKE_Handle handle, const _iq alpha_sf, const _iq beta_sf)
float_t EST_getFm_lp_Hz(EST_Handle handle)
TRAJ_Handle TRAJ_init(void *pMemory, const size_t numBytes)
void EST_enable(EST_Handle handle)
PI_Handle piHandle_spd
the handle for the speed PI controller
Definition: fast_obs_im.c:96
float_t maxVsMag_V
void HAL_setupFaults(HAL_Handle handle)
PI_Handle piHandle_Id
the handle for the Id PI controller
Definition: fast_obs_im.c:90
float_t EST_getLs_d_H(EST_Handle handle)
void EST_setFlag_enableRsRecalc(EST_Handle handle, const bool state)
static void TRAJ_setIntValue(TRAJ_Handle handle, const _iq intValue)
USER_Params gUserParams
The user parameters.
Definition: fast_obs_im.c:67
void EST_getIdq_A(EST_Handle handle, MATH_vec2 *pIdq_A)
static void HAL_enablePwm(HAL_Handle handle)
MATH_vec2 gIdq_A
Definition: fast_obs_im.c:29
EST_State_e
void HAL_enableDrv(HAL_Handle handle)
TRAJ_Handle trajHandle_Id
the handle for the Id trajectory
Definition: fast_obs_im.c:102
_iq value[2]
EST_Handle EST_initEst(const uint_least8_t estNumber)
volatile bool gFlag_enableForceAngle
Definition: fast_obs_im.c:27
float_t EST_getIdRated_A(EST_Handle handle)
PI_Handle PI_init(void *pMemory, const size_t numBytes)
void HAL_setupDrvSpi(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
uint_least8_t numVoltageSensors
float_t EST_getLs_q_H(EST_Handle handle)
void HAL_enableDebugInt(HAL_Handle handle)
CLARKE_Handle CLARKE_init(void *pMemory, const size_t numBytes)
float_t oneOverDcBus_invV
void sincos_fastRTS(float_t angle_rad, float_t *pSin, float_t *pCos)
Calculates sine and cosine in a single function call, using callable assembly, fast RTS...
static void IPARK_run(IPARK_Handle handle, const MATH_vec2 *pInVec, MATH_vec2 *pOutVec)
MATH_vec3 gOffsets_I_A
Definition: fast_obs_im.c:69
EST_State_e EST_getState(EST_Handle handle)
void setupClarke_I(CLARKE_Handle handle, const uint_least8_t numCurrentSensors)
Sets the number of current sensors.
Definition: fast_obs_im.c:392
EST_OutputData_t gEstOutputData
Definition: fast_obs_im.c:63
HAL_DacData_t gDacData
Defines the DAC data.
Definition: fast_obs_im.c:57
CLARKE_Handle clarkeHandle_V
the handle for the voltage Clarke transform
Definition: fast_obs_im.c:76
PI_Obj pi_Id
the Id PI controller object
Definition: fast_obs_im.c:91
float_t gLs_q_H
Global variable for the stator inductance in the quadrature coordinate direction, Henry...
Definition: fast_obs_im.c:37
float_t gRr_Ohm
Definition: fast_obs_im.c:39
interrupt void mainISR(void)
The main interrupt service (ISR) routine.
Definition: fast_obs_im.c:294
HAL_Obj hal
the hardware abstraction layer object
Definition: fast_obs_im.c:80
float_t gSpeed_ref_Hz
Definition: fast_obs_im.c:45
IPARK_Obj ipark
the inverse Park transform object
Definition: fast_obs_im.c:85
static uint32_t HAL_readTimerCnt(HAL_Handle handle, const uint_least8_t timerNumber)
static void CLARKE_setNumSensors(CLARKE_Handle handle, const uint_least8_t numSensors)
float_t EST_getRs_Ohm(EST_Handle handle)
uint_least16_t numCtrlTicksPerSpeedTick
void CPU_USAGE_setParams(CPU_USAGE_Handle handle, const uint32_t timerPeriod_cnts, const uint32_t numDeltaCntsAvg)
#define USER_ISR_FREQ_Hz
Defines the Interrupt Service Routine (ISR) frequency, Hz.
Definition: user.h:173
static void IPARK_setPhasor(IPARK_Handle handle, const MATH_vec2 *pPhasor)
volatile float_t gSpeed_Ki
Definition: fast_obs_im.c:49
CPU_USAGE_Handle CPU_USAGE_init(void *pMemory, const size_t numBytes)
static void HAL_disablePwm(HAL_Handle handle)
static void TRAJ_setMaxValue(TRAJ_Handle handle, const _iq maxValue)
HAL_Handle HAL_init(void *pMemory, const size_t numBytes)
static void CLARKE_run(CLARKE_Handle handle, const MATH_vec3 *pInVec, MATH_vec2 *pOutVec)
static uint32_t CPU_USAGE_getMaxDeltaCntObserved(CPU_USAGE_Handle handle)
HAL_Handle halHandle
the handle for the hardware abstraction layer
Definition: fast_obs_im.c:79
void updateCPUusage(void)
Updates CPU usage.
Definition: fast_obs_im.c:524
float_t gFlux_Wb
Global variable for the rotor flux estimate, Wb.
Definition: fast_obs_im.c:33
MATH_vec2 Iab_A
float_t gSpeed_Hz
Definition: fast_obs_im.c:43
uint_least32_t ctrlFreq_Hz
void SVGEN_setup(SVGEN_Handle svgenHandle)
float_t gCpuUsagePercentageMax
Definition: fast_obs_im.c:114
static void PI_setMinMax(PI_Handle handle, const _iq outMin, const _iq outMax)
static void PI_setRefValue(PI_Handle handle, const _iq refValue)
PARK_Obj park
the Park transform object
Definition: fast_obs_im.c:88
static void CPU_USAGE_updateCnts(CPU_USAGE_Handle handle, const uint32_t cnt)
CLARKE_Handle clarkeHandle_I
the handle for the current Clarke transform
Definition: fast_obs_im.c:73
void setupControllers(void)
Setups the controllers.
Definition: fast_obs_im.c:445
float_t sqrt_fastRTS(float_t x)
Calculates square root using callable assembly, fast RTS.
volatile bool gFlag_enableSys
Global flag to enable/disable the system.
Definition: fast_obs_im.c:23
EST_Handle estHandle
the handle for the estimator
Definition: fast_obs_im.c:82
MATH_vec2 Vab_V
static uint32_t CPU_USAGE_getMinDeltaCntObserved(CPU_USAGE_Handle handle)
#define MATH_ONE_OVER_SQRT_THREE
static void HAL_initIntVectorTable(HAL_Handle handle)
static float_t MATH_incrAngle(const float_t angle_rad, const float_t angleDelta_rad)
PARK_Handle PARK_init(void *pMemory, const size_t numBytes)
static void PI_setFbackValue(PI_Handle handle, const _iq fbackValue)
static uint16_t HAL_readPwmPeriod(HAL_Handle handle, const PWM_Number_e pwmNumber)
CLARKE_Obj clarke_I
the current Clarke transform object
Definition: fast_obs_im.c:74
HAL_PwmData_t gPwmData
Defines the PWM data.
Definition: fast_obs_im.c:59
bool EST_updateState(EST_Handle handle, const _iq Id_target_pu)
float_t gRs_Ohm
Definition: fast_obs_im.c:41
uint_least32_t estFreq_Hz
void EST_disable(EST_Handle handle)
void HAL_setParams(HAL_Handle handle, const USER_Params *pUserParams)
static void CPU_USAGE_run(CPU_USAGE_Handle handle)
HAL_AdcData_t gAdcData
Defines the ADC data.
Definition: fast_obs_im.c:55
void HAL_readDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
float_t IdRated_A
float_t gTorque_Nm
Global variable for the estimated torque, N*m.
Definition: fast_obs_im.c:65
static void TRAJ_run(TRAJ_Handle handle)
uint16_t gCounter_speed
Definition: fast_obs_im.c:53
float_t motor_Ls_d_H
float_t motor_Ls_q_H
SVGEN_Handle SVGEN_init(void *pMemory, const size_t numBytes)
SVGEN_Handle svgenHandle
the handle for the space vector generator
Definition: fast_obs_im.c:99
static void PI_setGains(PI_Handle handle, const _iq Kp, const _iq Ki)
static void PI_run_series(PI_Handle handle, const _iq refValue, const _iq fbackValue, const _iq ffwdValue, _iq *pOutValue)
EST_InputData_t gEstInputData
Definition: fast_obs_im.c:61
float float_t
static void TRAJ_setMinValue(TRAJ_Handle handle, const _iq minValue)
void EST_run(EST_Handle handle, const MATH_vec2 *pIab_pu, const MATH_vec2 *pVab_pu, const _iq dcBus_pu, const _iq speed_ref_pu)
#define USER_NUM_PWM_TICKS_PER_ISR_TICK
DECIMATION.
Definition: user.h:184
SVGEN_Obj svgen
the space vector generator object
Definition: fast_obs_im.c:100