instaspin_foc
fast_obs_im_pw_cal.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 CAL_State_e gCalState = CAL_State_Idle;
22 
23 EST_State_e gEstState = EST_State_Idle;
24 
25 volatile bool gFlag_enableSys = true;
26 
27 volatile bool gFlag_runCal = false;
28 
29 volatile bool gFlag_runOnLine = false;
30 
31 volatile bool gFlag_enableForceAngle = true;
32 
33 volatile bool gFlag_enablePowerWarp = false;
34 
35 MATH_vec2 gIdq_A = {0.0, 0.0};
36 
38 
40 
42 
44 
46 
48 
50 
52 
53 volatile float_t gSpeed_Kp = 0.01;
54 
55 volatile float_t gSpeed_Ki = 0.001;
56 
58 
59 uint16_t gCounter_speed = 0;
60 
62 
64 
66 
68 
70 
72 
74 
75 MATH_vec3 gOffsets_I_A = {0.0, 0.0, 0.0};
76 
77 MATH_vec3 gOffsets_V_V = {0.0, 0.0, 0.0};
78 
81 
84 
87 
90 
92 
95 
98 
101 
104 
107 
110 
113 
114 #ifdef DRV8301_SPI
115 // Watch window interface to the 8301 SPI
116 DRV_SPI_8301_Vars_t gDrvSpi8301Vars;
117 #endif
118 
124 
125 // **************************************************************************
126 // the functions
127 
128 void main(void)
129 {
130  uint_least8_t estNumber = 0;
131 
132  // initialize the user parameters
133  USER_setParams(&gUserParams);
134 
135  // initialize the user parameters
136  USER_setParams_priv(&gUserParams);
137 
138  // initialize the driver
139  halHandle = HAL_init(&hal,sizeof(hal));
140 
141  // set the driver parameters
142  HAL_setParams(halHandle,&gUserParams);
143 
144  // initialize the calibrator
145  calHandle = CAL_init(&cal,sizeof(cal));
146 
147  // set the default calibrator parameters
148  CAL_setParams(calHandle,&gUserParams);
149 
150  // initialize the Clarke modules
151  clarkeHandle_I = CLARKE_init(&clarke_I,sizeof(clarke_I));
152  clarkeHandle_V = CLARKE_init(&clarke_V,sizeof(clarke_V));
153 
154  // set the Clarke parameters
155  setupClarke_I(clarkeHandle_I,gUserParams.numCurrentSensors);
156  setupClarke_V(clarkeHandle_V,gUserParams.numVoltageSensors);
157 
158  // initialize the estimator
159  estHandle = EST_initEst(estNumber);
160 
161  // set the default estimator parameters
162  EST_setParams(estHandle,&gUserParams);
166 
167  // initialize the inverse Park module
168  iparkHandle = IPARK_init(&ipark,sizeof(ipark));
169 
170  // initialize the Park module
171  parkHandle = PARK_init(&park,sizeof(park));
172 
173  // initialize the PI controllers
174  piHandle_Id = PI_init(&pi_Id, sizeof(pi_Id));
175  piHandle_Iq = PI_init(&pi_Iq, sizeof(pi_Iq));
176  piHandle_spd = PI_init(&pi_spd,sizeof(pi_spd));
177 
178  // setup the controllers
180 
181  // initialize the space vector generator module
182  svgenHandle = SVGEN_init(&svgen,sizeof(svgen));
183 
184  // initialize the Id trajectory
185  trajHandle_Id = TRAJ_init(&traj_Id,sizeof(traj_Id));
186 
187  // configure the Id trajectory. Configure a 5 seconds ramp
188  TRAJ_setTargetValue(trajHandle_Id,gUserParams.IdRated_A);
189  TRAJ_setIntValue(trajHandle_Id,0.0);
190  TRAJ_setMinValue(trajHandle_Id,gUserParams.IdRated_A * 0.3);
191  TRAJ_setMaxValue(trajHandle_Id,gUserParams.IdRated_A);
192  TRAJ_setMaxDelta(trajHandle_Id,gUserParams.IdRated_A / gUserParams.estFreq_Hz);
193 
194  // initialize the CPU usage module
195  cpu_usageHandle = CPU_USAGE_init(&cpu_usage,sizeof(cpu_usage));
196  CPU_USAGE_setParams(cpu_usageHandle,
197  (uint32_t)USER_SYSTEM_FREQ_MHz * 1000000, // timer period, cnts
198  (uint32_t)USER_ISR_FREQ_Hz); // average over 1 second of ISRs
199 
200  // setup faults
201  HAL_setupFaults(halHandle);
202 
203  // initialize the interrupt vector table
204  HAL_initIntVectorTable(halHandle);
205 
206  // enable the ADC interrupts
207  HAL_enableAdcInts(halHandle);
208 
209  // enable global interrupts
210  HAL_enableGlobalInts(halHandle);
211 
212  // enable debug interrupts
213  HAL_enableDebugInt(halHandle);
214 
215  // disable the PWM
216  HAL_disablePwm(halHandle);
217 
218 #ifdef DRV8301_SPI
219  // turn on the DRV8301 if present
220  HAL_enableDrv(halHandle);
221  // initialize the DRV8301 interface
222  HAL_setupDrvSpi(halHandle,&gDrvSpi8301Vars);
223 #endif
224 
225  // Waiting for enable system flag to be set
226  while(!gFlag_enableSys);
227 
228  // loop while the enable system flag is true
229  while(gFlag_enableSys)
230  {
231  // set custom speed controller gains
232  PI_setGains(piHandle_spd,gSpeed_Kp,gSpeed_Ki);
233 
234  // enable or disable force angle
236 
237  // enable or disable PowerWarp
239 
241  {
242  float_t Id_target_A_pw = EST_runPowerWarp(estHandle,TRAJ_getIntValue(trajHandle_Id),gIdq_A.value[1]);
243  TRAJ_setTargetValue(trajHandle_Id,Id_target_A_pw);
244  }
245  else
246  {
247  TRAJ_setTargetValue(trajHandle_Id,gUserParams.IdRated_A);
248  }
249 
250  if((gFlag_runOnLine) && (!gFlag_runCal))
251  {
252  // disable the calibrator
253  CAL_disable(calHandle);
254 
255  // enable the estimator
257 
258  // enable the PWM
259  HAL_enablePwm(halHandle);
260  }
261  else if(gFlag_runCal)
262  {
263  // enable the calibrator
264  CAL_setFlag_enableAdcOffset(calHandle,true);
265 
266  // enable the calibrator
267  CAL_enable(calHandle);
268 
269  // disable the estimator
271 
272  // enable the PWM
273  HAL_enablePwm(halHandle);
274  }
275  else
276  {
277  // disable the calibrator
278  CAL_disable(calHandle);
279 
280  // disable the estimator
282 
283  // disable the PWM
284  HAL_disablePwm(halHandle);
285 
286  // clear integral outputs of the controllers
287  PI_setUi(piHandle_Id,0.0);
288  PI_setUi(piHandle_Iq,0.0);
289  PI_setUi(piHandle_spd,0.0);
290 
291  // clear current references
292  gIq_ref_A = 0.0;
293 
294  // clear the Id trajectory
295  TRAJ_setIntValue(trajHandle_Id,0.0);
296 
297  // clear PowerWarp enable flag
298  gFlag_enablePowerWarp = false;
299  }
300 
301  // update the estimator state
303 
304  // update the calibrator state
305  if(CAL_updateState(calHandle))
306  {
307  CAL_State_e calState = CAL_getState(calHandle);
308 
309  if(calState == CAL_State_Done)
310  {
311  // update the ADC offset values
312  gOffsets_I_A.value[0] = CAL_getOffsetValue_I(calHandle,0);
313  gOffsets_I_A.value[1] = CAL_getOffsetValue_I(calHandle,1);
314  gOffsets_I_A.value[2] = CAL_getOffsetValue_I(calHandle,2);
315  gOffsets_V_V.value[0] = CAL_getOffsetValue_V(calHandle,0);
316  gOffsets_V_V.value[1] = CAL_getOffsetValue_V(calHandle,1);
317  gOffsets_V_V.value[2] = CAL_getOffsetValue_V(calHandle,2);
318 
319  // clear the flag
320  gFlag_runCal = false;
321  }
322  }
323 
324  // update the global variables
326 
327  // update CPU usage
328  updateCPUusage();
329 
330 #ifdef DRV8301_SPI
331  HAL_writeDrvData(halHandle,&gDrvSpi8301Vars);
332 
333  HAL_readDrvData(halHandle,&gDrvSpi8301Vars);
334 #endif
335 
336  } // end of while() loop
337 
338  // disable the PWM
339  HAL_disablePwm(halHandle);
340 
341 } // end of main() function
342 
343 
344 interrupt void mainISR(void)
345 {
346  uint32_t timer1Cnt;
347  float_t angleDelta_rad;
348  float_t angleWithDelay_rad;
349  float_t outMax_V;
350  MATH_vec2 phasor;
351  MATH_vec2 Vab_out_V;
352  MATH_vec2 Vdq_out_V;
353  HAL_AdcData_t AdcDataWithOffset;
354 
355  // read the timer 1 value and update the CPU usage module
356  timer1Cnt = HAL_readTimerCnt(halHandle,1);
357  CPU_USAGE_updateCnts(cpu_usageHandle,timer1Cnt);
358 
359  // acknowledge the ADC interrupt
360  HAL_acqAdcInt(halHandle,ADC_IntNumber_6);
361 
362  // read the ADC data with offsets
363  HAL_readAdcDataWithOffsets(halHandle,&AdcDataWithOffset);
364 
365  // remove offsets
366  gAdcData.I_A.value[0] = AdcDataWithOffset.I_A.value[0] - gOffsets_I_A.value[0];
367  gAdcData.I_A.value[1] = AdcDataWithOffset.I_A.value[1] - gOffsets_I_A.value[1];
368  gAdcData.I_A.value[2] = AdcDataWithOffset.I_A.value[2] - gOffsets_I_A.value[2];
369  gAdcData.V_V.value[0] = AdcDataWithOffset.V_V.value[0] - gOffsets_V_V.value[0];
370  gAdcData.V_V.value[1] = AdcDataWithOffset.V_V.value[1] - gOffsets_V_V.value[1];
371  gAdcData.V_V.value[2] = AdcDataWithOffset.V_V.value[2] - gOffsets_V_V.value[2];
372  gAdcData.dcBus_V = AdcDataWithOffset.dcBus_V;
373 
374  // if enabled, run the calibrator
375  if(CAL_isEnabled(calHandle))
376  {
377  // run the calibrator
378  CAL_run(calHandle,&AdcDataWithOffset);
379  }
380 
381  // if enabled, run the estimator
383  {
384  // run Clarke transform on current
385  CLARKE_run(clarkeHandle_I,&(gAdcData.I_A),&(gEstInputData.Iab_A));
386 
387  // run Clarke transform on voltage
388  CLARKE_run(clarkeHandle_V,&(gAdcData.V_V),&(gEstInputData.Vab_V));
389 
390  // store the input data into a buffer
391  gEstInputData.dcBus_V = gAdcData.dcBus_V;
392  gEstInputData.speed_ref_Hz = gSpeed_ref_Hz;
393 
394  // run the estimator
395  EST_run(estHandle,&gEstInputData,&gEstOutputData);
396 
397  // run the speed controller
398  if(++gCounter_speed >= gUserParams.numCtrlTicksPerSpeedTick)
399  {
400  gCounter_speed = 0;
401 
402  PI_run_series(piHandle_spd,gEstInputData.speed_ref_Hz,gEstOutputData.fm_lp_rps * MATH_ONE_OVER_TWO_PI,0.0,&gIq_ref_A);
403  }
404 
405  // get Idq, reutilizing a Park transform used inside the estimator. This is optional, user's Park works as well
406  EST_getIdq_A(estHandle,&gIdq_A);
407 
408  // run a trajectory for Id, so magnetizing current is increased slowly
409  TRAJ_run(trajHandle_Id);
410 
411  // run the Id controller
412  PI_run_series(piHandle_Id,TRAJ_getIntValue(trajHandle_Id),gIdq_A.value[0],0.0,&(Vdq_out_V.value[0]));
413 
414  // calculate Iq controller limits, and run Iq controller using fast RTS function, callable assembly
415  outMax_V = sqrt_fastRTS((gUserParams.maxVsMag_V * gUserParams.maxVsMag_V) - (Vdq_out_V.value[0] * Vdq_out_V.value[0]));
416  PI_setMinMax(piHandle_Iq,-outMax_V,outMax_V);
417  PI_run_series(piHandle_Iq,gIq_ref_A,gIdq_A.value[1],0.0,&(Vdq_out_V.value[1]));
418 
419  // compute angle with delay compensation
420  angleDelta_rad = gUserParams.angleDelayed_sf_sec * gEstOutputData.fm_lp_rps;
421  angleWithDelay_rad = MATH_incrAngle(gEstOutputData.angle_rad, angleDelta_rad);
422 
423  // compute the sin/cos phasor using fast RTS function, callable assembly
424  sincos_fastRTS(angleWithDelay_rad, &(phasor.value[1]), &(phasor.value[0]));
425 
426  // set the phasor in the inverse Park transform
427  IPARK_setPhasor(iparkHandle,&phasor);
428 
429  // run the inverse Park module
430  IPARK_run(iparkHandle,&Vdq_out_V,&Vab_out_V);
431 
432  // setup the space vector generator (SVGEN) module
433  SVGEN_setup(svgenHandle,gEstOutputData.oneOverDcBus_invV);
434 
435  // run the space vector generator (SVGEN) module
436  SVGEN_run(svgenHandle,&Vab_out_V,&(gPwmData.Vabc_pu));
437  }
438  else
439  {
440  // create PWM data
441  gPwmData.Vabc_pu.value[0] = 0.0;
442  gPwmData.Vabc_pu.value[1] = 0.0;
443  gPwmData.Vabc_pu.value[2] = 0.0;
444  }
445 
446  // write the PWM compare values
447  HAL_writePwmData(halHandle,&gPwmData);
448 
449  // read the timer 1 value and update the CPU usage module
450  timer1Cnt = HAL_readTimerCnt(halHandle,1);
451  CPU_USAGE_updateCnts(cpu_usageHandle,timer1Cnt);
452 
453  // run the CPU usage module
454  CPU_USAGE_run(cpu_usageHandle);
455 
456  return;
457 } // end of mainISR() function
458 
459 
460 void setupClarke_I(CLARKE_Handle handle,const uint_least8_t numCurrentSensors)
461 {
462  float_t alpha_sf,beta_sf;
463 
464  // initialize the Clarke transform module for current
465  if(numCurrentSensors == 3)
466  {
467  alpha_sf = MATH_ONE_OVER_THREE;
468  beta_sf = MATH_ONE_OVER_SQRT_THREE;
469  }
470  else if(numCurrentSensors == 2)
471  {
472  alpha_sf = 1.0;
473  beta_sf = MATH_ONE_OVER_SQRT_THREE;
474  }
475  else
476  {
477  alpha_sf = 0.0;
478  beta_sf = 0.0;
479  }
480 
481  // set the parameters
482  CLARKE_setScaleFactors(handle,alpha_sf,beta_sf);
483  CLARKE_setNumSensors(handle,numCurrentSensors);
484 
485  return;
486 } // end of setupClarke_I() function
487 
488 
489 void setupClarke_V(CLARKE_Handle handle,const uint_least8_t numVoltageSensors)
490 {
491  float_t alpha_sf,beta_sf;
492 
493  // initialize the Clarke transform module for voltage
494  if(numVoltageSensors == 3)
495  {
496  alpha_sf = MATH_ONE_OVER_THREE;
497  beta_sf = MATH_ONE_OVER_SQRT_THREE;
498  }
499  else
500  {
501  alpha_sf = 0.0;
502  beta_sf = 0.0;
503  }
504 
505  // set the parameters
506  CLARKE_setScaleFactors(handle,alpha_sf,beta_sf);
507  CLARKE_setNumSensors(handle,numVoltageSensors);
508 
509  return;
510 } // end of setupClarke_V() function
511 
512 
514 {
515  float_t Ls_d_H = gUserParams.motor_Ls_d_H;
516  float_t Ls_q_H = gUserParams.motor_Ls_q_H;
517  float_t Rs_d_Ohm = gUserParams.motor_Rs_d_Ohm;
518  float_t Rs_q_Ohm = gUserParams.motor_Rs_q_Ohm;
519  float_t RdoverLd_rps = Rs_d_Ohm / Ls_d_H;
520  float_t RqoverLq_rps = Rs_q_Ohm / Ls_q_H;
521  float_t BWc_rps = gUserParams.BWc_rps;
522  float_t currentCtrlPeriod_sec = (float_t)gUserParams.numCtrlTicksPerCurrentTick / gUserParams.ctrlFreq_Hz;
523  float_t outMax_V = gUserParams.Vd_sf * gUserParams.maxVsMag_V;
524 
525  float_t Kp_Id = Ls_d_H * BWc_rps;
526  float_t Ki_Id = RdoverLd_rps * currentCtrlPeriod_sec;
527 
528  float_t Kp_Iq = Ls_q_H * BWc_rps;
529  float_t Ki_Iq = RqoverLq_rps * currentCtrlPeriod_sec;
530 
531  // set the Id controller
532  PI_setGains(piHandle_Id,Kp_Id,Ki_Id);
533  PI_setUi(piHandle_Id,0.0);
534  PI_setRefValue(piHandle_Id,0.0);
535  PI_setFbackValue(piHandle_Id,0.0);
536  PI_setFfwdValue(piHandle_Id,0.0);
537  PI_setMinMax(piHandle_Id,-outMax_V,outMax_V);
538 
539  // set the Iq controller
540  PI_setGains(piHandle_Iq,Kp_Iq,Ki_Iq);
541  PI_setUi(piHandle_Iq,0.0);
542  PI_setRefValue(piHandle_Iq,0.0);
543  PI_setFbackValue(piHandle_Iq,0.0);
544  PI_setFfwdValue(piHandle_Iq,0.0);
545  PI_setMinMax(piHandle_Iq,0.0,0.0);
546 
547  // set the speed controller
548  PI_setGains(piHandle_spd,gSpeed_Kp,gSpeed_Ki);
549  PI_setUi(piHandle_spd,0.0);
550  PI_setRefValue(piHandle_spd,0.0);
551  PI_setFbackValue(piHandle_spd,0.0);
552  PI_setFfwdValue(piHandle_spd,0.0);
553  PI_setMinMax(piHandle_spd,-gUserParams.maxCurrent_A,gUserParams.maxCurrent_A);
554 
555  return;
556 } // end of setupCurrentControllers() function
557 
558 
560 {
561  // get the states
562  gCalState = CAL_getState(calHandle);
563  gEstState = EST_getState(estHandle);
564 
565  // get the speed estimate
566  gSpeed_Hz = EST_getFm_lp_Hz(estHandle);
567 
568  // get the torque estimate
569  gTorque_Nm = EST_computeTorque_Nm(estHandle);
570 
571  // get the rotor resistance
572  gRr_Ohm = EST_getRr_d_Ohm(estHandle);
573 
574  // get the stator resistance
575  gRs_Ohm = EST_getRs_Ohm(estHandle);
576 
577  // get the stator inductance in the direct coordinate direction
578  gLs_d_H = EST_getLs_d_H(estHandle);
579 
580  // get the stator inductance in the quadrature coordinate direction
581  gLs_q_H = EST_getLs_q_H(estHandle);
582 
583  // get the IdRated value
584  gIdRated_A = EST_getIdRated_A(estHandle);
585 
586  // get the flux, Wb
587  gFlux_Wb = EST_getFlux_Wb(estHandle);
588 
589  return;
590 } // end of updateGlobalVariables_motor() function
591 
592 
593 void updateCPUusage(void)
594 {
595  uint32_t minDeltaCntObserved = CPU_USAGE_getMinDeltaCntObserved(cpu_usageHandle);
596  uint32_t avgDeltaCntObserved = CPU_USAGE_getAvgDeltaCntObserved(cpu_usageHandle);
597  uint32_t maxDeltaCntObserved = CPU_USAGE_getMaxDeltaCntObserved(cpu_usageHandle);
598  uint16_t pwmPeriod = HAL_readPwmPeriod(halHandle,PWM_Number_1);
599  float_t cpu_usage_den = (float_t)pwmPeriod * (float_t)USER_NUM_PWM_TICKS_PER_ISR_TICK * 2.0;
600 
601  // calculate the minimum cpu usage percentage
602  gCpuUsagePercentageMin = (float_t)minDeltaCntObserved / cpu_usage_den * 100.0;
603 
604  // calculate the average cpu usage percentage
605  gCpuUsagePercentageAvg = (float_t)avgDeltaCntObserved / cpu_usage_den * 100.0;
606 
607  // calculate the maximum cpu usage percentage
608  gCpuUsagePercentageMax = (float_t)maxDeltaCntObserved / cpu_usage_den * 100.0;
609 
610  return;
611 } // end of updateCPUusage() function
612 
613 
614 // end of file
615 
#define USER_SYSTEM_FREQ_MHz
CLOCKS & TIMERS.
Definition: user.h:140
EST_State_e gEstState
Global variable for the estimator state.
float_t angleDelayed_sf_sec
void EST_setFlag_enableForceAngle(EST_Handle handle, const bool state)
static void CAL_enable(CAL_Handle handle)
IPARK_Handle IPARK_init(void *pMemory, const size_t numBytes)
#define MATH_ONE_OVER_TWO_PI
static void TRAJ_setTargetValue(TRAJ_Handle handle, const _iq targetValue)
float_t gCpuUsagePercentageMin
float_t gSpeed_ref_Hz
void HAL_enableGlobalInts(HAL_Handle handle)
void HAL_enableAdcInts(HAL_Handle handle)
float_t EST_getFlux_Wb(EST_Handle handle)
void updateGlobalVariables_motor(EST_Handle estHandle)
Updates the global motor variables.
static void PI_setFfwdValue(PI_Handle handle, const _iq ffwdValue)
MATH_vec3 Vabc_pu
PARK_Handle parkHandle
the handle for the Park object
SVGEN_Obj svgen
the space vector generator object
static void HAL_readAdcDataWithOffsets(HAL_Handle handle, HAL_AdcData_t *pAdcData)
static void CAL_run(CAL_Handle handle, const HAL_AdcData_t *pAdcData)
float_t gSpeed_Hz
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.
float_t motor_Rs_d_Ohm
CAL_Handle calHandle
the handle for the calibrator
static _iq TRAJ_getIntValue(TRAJ_Handle handle)
float_t gIdRated_A
Global variable for the rated Id current current, A.
static void HAL_writePwmData(HAL_Handle handle, HAL_PwmData_t *pPwmData)
CPU_USAGE_Obj cpu_usage
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)
MATH_vec2 gIdq_A
static void HAL_acqAdcInt(HAL_Handle handle, const ADC_IntNumber_e intNumber)
float_t EST_getRr_d_Ohm(EST_Handle handle)
float_t motor_Rs_q_Ohm
static void CAL_setFlag_enableAdcOffset(CAL_Handle handle, const bool value)
uint_least8_t numCurrentSensors
bool EST_isEnabled(EST_Handle handle)
void CAL_setParams(CAL_Handle handle, const USER_Params *pUserParams)
void EST_setParams(EST_Handle handle, USER_Params *pUserParams)
PI_Handle piHandle_Id
the handle for the Id PI controller
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_enablePowerWarp
PI_Handle piHandle_Iq
the handle for the Iq PI controller
uint_least16_t numCtrlTicksPerCurrentTick
PI_Obj pi_spd
the speed PI controller object
#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.
CLARKE_Obj clarke_V
the voltage Clarke transform object
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)
SVGEN_Handle svgenHandle
the handle for the space vector generator
CLARKE_Handle clarkeHandle_I
the handle for the current Clarke transform
EST_InputData_t gEstInputData
TRAJ_Handle TRAJ_init(void *pMemory, const size_t numBytes)
CAL_State_e
void EST_enable(EST_Handle handle)
float_t maxVsMag_V
void HAL_setupFaults(HAL_Handle handle)
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)
volatile bool gFlag_enableForceAngle
MATH_vec3 gOffsets_I_A
USER_Params gUserParams
The user parameters.
void EST_getIdq_A(EST_Handle handle, MATH_vec2 *pIdq_A)
static void HAL_enablePwm(HAL_Handle handle)
void EST_setFlag_enablePowerWarp(EST_Handle handle, const bool state)
EST_State_e
IPARK_Obj ipark
the inverse Park transform object
void HAL_enableDrv(HAL_Handle handle)
_iq value[2]
volatile bool gFlag_runCal
EST_Handle EST_initEst(const uint_least8_t estNumber)
CAL_State_e gCalState
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)
EST_State_e EST_getState(EST_Handle handle)
static void CAL_disable(CAL_Handle handle)
void setupClarke_I(CLARKE_Handle handle, const uint_least8_t numCurrentSensors)
Sets the number of current sensors.
HAL_Obj hal
the hardware abstraction layer object
EST_OutputData_t gEstOutputData
float_t gRs_Ohm
PI_Obj pi_Iq
the Iq PI controller object
HAL_DacData_t gDacData
Defines the DAC data.
float_t gLs_q_H
Global variable for the stator inductance in the quadrature coordinate direction, Henry...
float_t gIq_ref_A
EST_Handle estHandle
the handle for the estimator
interrupt void mainISR(void)
The main interrupt service (ISR) routine.
volatile float_t gSpeed_Ki
CLARKE_Handle clarkeHandle_V
the handle for the voltage Clarke transform
static uint32_t HAL_readTimerCnt(HAL_Handle handle, const uint_least8_t timerNumber)
TRAJ_Handle trajHandle_Id
the handle for the Id trajectory
static _iq CAL_getOffsetValue_V(CAL_Handle handle, const uint_least8_t sensorNumber)
void main(void)
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)
PARK_Obj park
the Park transform object
#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)
CPU_USAGE_Handle CPU_USAGE_init(void *pMemory, const size_t numBytes)
static void HAL_disablePwm(HAL_Handle handle)
float_t EST_runPowerWarp(EST_Handle handle, const float_t Id_int_A, const float_t Iq_A)
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
void updateCPUusage(void)
Updates CPU usage.
static CAL_State_e CAL_getState(CAL_Handle handle)
PI_Handle piHandle_spd
the handle for the speed PI controller
float_t gFlux_Wb
Global variable for the rotor flux estimate, Wb.
MATH_vec2 Iab_A
PI_Obj pi_Id
the Id PI controller object
IPARK_Handle iparkHandle
the handle for the inverse Park transform
uint_least32_t ctrlFreq_Hz
CAL_Handle CAL_init(void *pMemory, const size_t numBytes)
void SVGEN_setup(SVGEN_Handle svgenHandle)
static void PI_setMinMax(PI_Handle handle, const _iq outMin, const _iq outMax)
float_t gRr_Ohm
static void PI_setRefValue(PI_Handle handle, const _iq refValue)
static void CPU_USAGE_updateCnts(CPU_USAGE_Handle handle, const uint32_t cnt)
void setupControllers(void)
Setups the controllers.
volatile bool gFlag_runOnLine
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.
MATH_vec2 Vab_V
static uint32_t CPU_USAGE_getMinDeltaCntObserved(CPU_USAGE_Handle handle)
#define MATH_ONE_OVER_SQRT_THREE
CPU_USAGE_Handle cpu_usageHandle
float_t gCpuUsagePercentageMax
CAL_Obj cal
the calibrator object
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)
float_t gCpuUsagePercentageAvg
HAL_PwmData_t gPwmData
Defines the PWM data.
TRAJ_Obj traj_Id
the Id trajectory object
bool EST_updateState(EST_Handle handle, const _iq Id_target_pu)
uint_least32_t estFreq_Hz
void EST_disable(EST_Handle handle)
static _iq CAL_getOffsetValue_I(CAL_Handle handle, const uint_least8_t sensorNumber)
void HAL_setParams(HAL_Handle handle, const USER_Params *pUserParams)
static void CPU_USAGE_run(CPU_USAGE_Handle handle)
bool CAL_updateState(CAL_Handle handle)
HAL_AdcData_t gAdcData
Defines the ADC data.
void HAL_readDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
static bool CAL_isEnabled(CAL_Handle handle)
CLARKE_Obj clarke_I
the current Clarke transform object
float_t IdRated_A
float_t gTorque_Nm
Global variable for the estimated torque, N*m.
static void TRAJ_run(TRAJ_Handle handle)
MATH_vec3 gOffsets_V_V
uint16_t gCounter_speed
volatile float_t gSpeed_Kp
float_t motor_Ls_d_H
float_t motor_Ls_q_H
SVGEN_Handle SVGEN_init(void *pMemory, const size_t numBytes)
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)
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