instaspin_foc
fast_obs_pm_cal_rs_rsol_traj.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_enableRsRecalc = true;
34 
35 volatile bool gFlag_enableRsOnLine = false;
36 
37 volatile bool gFlag_updateRs = false;
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 
57 volatile float_t gId_ref_A = 0.0;
58 
60 
62 
63 uint16_t gCounter_speed = 0;
64 
66 
68 
70 
72 
74 
75 volatile float_t gRsOnLineFreq_Hz = 0.2;
76 
77 volatile float_t gRsOnLineId_mag_A = 0.5;
78 
79 volatile float_t gRsOnLinePole_Hz = 0.2;
80 
82 
84 
85 MATH_vec3 gOffsets_I_A = {0.0, 0.0, 0.0};
86 
87 MATH_vec3 gOffsets_V_V = {0.0, 0.0, 0.0};
88 
91 
94 
97 
100 
102 
105 
108 
111 
114 
117 
120 
123 
126 
127 #ifdef DRV8301_SPI
128 // Watch window interface to the 8301 SPI
129 DRV_SPI_8301_Vars_t gDrvSpi8301Vars;
130 #endif
131 
137 
138 // **************************************************************************
139 // the functions
140 
141 void main(void)
142 {
143  uint_least8_t estNumber = 0;
144 
145  // initialize the user parameters
146  USER_setParams(&gUserParams);
147 
148  // initialize the user parameters
149  USER_setParams_priv(&gUserParams);
150 
151  // initialize the driver
152  halHandle = HAL_init(&hal,sizeof(hal));
153 
154  // set the driver parameters
155  HAL_setParams(halHandle,&gUserParams);
156 
157  // initialize the calibrator
158  calHandle = CAL_init(&cal,sizeof(cal));
159 
160  // set the default calibrator parameters
161  CAL_setParams(calHandle,&gUserParams);
162 
163  // initialize the Clarke modules
164  clarkeHandle_I = CLARKE_init(&clarke_I,sizeof(clarke_I));
165  clarkeHandle_V = CLARKE_init(&clarke_V,sizeof(clarke_V));
166 
167  // set the Clarke parameters
168  setupClarke_I(clarkeHandle_I,gUserParams.numCurrentSensors);
169  setupClarke_V(clarkeHandle_V,gUserParams.numVoltageSensors);
170 
171  // initialize the estimator
172  estHandle = EST_initEst(estNumber);
173 
174  // set the default estimator parameters
175  EST_setParams(estHandle,&gUserParams);
182 
183  // initialize the inverse Park module
184  iparkHandle = IPARK_init(&ipark,sizeof(ipark));
185 
186  // initialize the Park module
187  parkHandle = PARK_init(&park,sizeof(park));
188 
189  // initialize the PI controllers
190  piHandle_Id = PI_init(&pi_Id, sizeof(pi_Id));
191  piHandle_Iq = PI_init(&pi_Iq, sizeof(pi_Iq));
192  piHandle_spd = PI_init(&pi_spd,sizeof(pi_spd));
193 
194  // setup the controllers
196 
197  // initialize the space vector generator module
198  svgenHandle = SVGEN_init(&svgen,sizeof(svgen));
199 
200  // initialize the Id trajectory
201  trajHandle_Id = TRAJ_init(&traj_Id,sizeof(traj_Id));
202 
203  // configure the Id trajectory
204  TRAJ_setTargetValue(trajHandle_Id,0.0);
205  TRAJ_setIntValue(trajHandle_Id,0.0);
206  TRAJ_setMinValue(trajHandle_Id,-gUserParams.maxCurrent_A);
207  TRAJ_setMaxValue(trajHandle_Id,gUserParams.maxCurrent_A);
208  TRAJ_setMaxDelta(trajHandle_Id,gUserParams.maxCurrent_resEst_A / gUserParams.estFreq_Hz);
209 
210  // initialize the speed trajectory
211  trajHandle_spd = TRAJ_init(&traj_spd,sizeof(traj_spd));
212 
213  // configure the Id trajectory
214  TRAJ_setTargetValue(trajHandle_spd,0.0);
215  TRAJ_setIntValue(trajHandle_spd,0.0);
216  TRAJ_setMinValue(trajHandle_spd,-3000.0);
217  TRAJ_setMaxValue(trajHandle_spd,3000.0);
218  TRAJ_setMaxDelta(trajHandle_spd,gUserParams.maxAccel_Hzps / gUserParams.estFreq_Hz);
219 
220  // initialize the CPU usage module
221  cpu_usageHandle = CPU_USAGE_init(&cpu_usage,sizeof(cpu_usage));
222  CPU_USAGE_setParams(cpu_usageHandle,
223  (uint32_t)USER_SYSTEM_FREQ_MHz * 1000000, // timer period, cnts
224  (uint32_t)USER_ISR_FREQ_Hz); // average over 1 second of ISRs
225 
226  // setup faults
227  HAL_setupFaults(halHandle);
228 
229  // initialize the interrupt vector table
230  HAL_initIntVectorTable(halHandle);
231 
232  // enable the ADC interrupts
233  HAL_enableAdcInts(halHandle);
234 
235  // enable global interrupts
236  HAL_enableGlobalInts(halHandle);
237 
238  // enable debug interrupts
239  HAL_enableDebugInt(halHandle);
240 
241  // disable the PWM
242  HAL_disablePwm(halHandle);
243 
244 #ifdef DRV8301_SPI
245  // turn on the DRV8301 if present
246  HAL_enableDrv(halHandle);
247  // initialize the DRV8301 interface
248  HAL_setupDrvSpi(halHandle,&gDrvSpi8301Vars);
249 #endif
250 
251  // Waiting for enable system flag to be set
252  while(!gFlag_enableSys);
253 
254  // loop while the enable system flag is true
255  while(gFlag_enableSys)
256  {
257  // set custom speed controller gains
258  PI_setGains(piHandle_spd,gSpeed_Kp,gSpeed_Ki);
259 
260  // enable or disable force angle
262 
263  // enable or disable Rs recalibration
265 
266  // enable or disable RsOnLine
268 
269  // set slow rotating frequency for RsOnLine
271 
272  // set current amplitude for RsOnLine
274 
275  // set RsOnLine beta based on the desired filter pole
277 
278  // set flag that updates Rs from RsOnLine value
280 
281  if((gFlag_runOnLine) && (!gFlag_runCal))
282  {
283  // set trajectory target for Id
285 
286  // set trajectory target for speed
287  TRAJ_setTargetValue(trajHandle_spd,gSpeed_ref_Hz);
288 
289  // disable the calibrator
290  CAL_disable(calHandle);
291 
292  // enable the estimator
294 
295  // enable the PWM
296  HAL_enablePwm(halHandle);
297  }
298  else if(gFlag_runCal)
299  {
300  // enable the calibrator
301  CAL_setFlag_enableAdcOffset(calHandle,true);
302 
303  // enable the calibrator
304  CAL_enable(calHandle);
305 
306  // disable the estimator
308 
309  // enable the PWM
310  HAL_enablePwm(halHandle);
311  }
312  else
313  {
314  // disable the calibrator
315  CAL_disable(calHandle);
316 
317  // disable the estimator
319 
320  // disable the PWM
321  HAL_disablePwm(halHandle);
322 
323  // clear integral outputs of the controllers
324  PI_setUi(piHandle_Id,0.0);
325  PI_setUi(piHandle_Iq,0.0);
326  PI_setUi(piHandle_spd,0.0);
327 
328  // clear current references
329  gId_ref_A = 0.0;
330  gIq_ref_A = 0.0;
331 
332  // disable RsOnLine flags
333  gFlag_enableRsOnLine = false;
334  gFlag_updateRs = false;
335 
336  // clear the Id trajectory
337  TRAJ_setTargetValue(trajHandle_Id,0.0);
338  TRAJ_setIntValue(trajHandle_Id,0.0);
339 
340  // clear the speed trajectory
341  TRAJ_setTargetValue(trajHandle_spd,0.0);
342  TRAJ_setIntValue(trajHandle_spd,0.0);
343  }
344 
345  // update the estimator state
347 
348  // update the calibrator state
349  if(CAL_updateState(calHandle))
350  {
351  CAL_State_e calState = CAL_getState(calHandle);
352 
353  if(calState == CAL_State_Done)
354  {
355  // update the ADC offset values
356  gOffsets_I_A.value[0] = CAL_getOffsetValue_I(calHandle,0);
357  gOffsets_I_A.value[1] = CAL_getOffsetValue_I(calHandle,1);
358  gOffsets_I_A.value[2] = CAL_getOffsetValue_I(calHandle,2);
359  gOffsets_V_V.value[0] = CAL_getOffsetValue_V(calHandle,0);
360  gOffsets_V_V.value[1] = CAL_getOffsetValue_V(calHandle,1);
361  gOffsets_V_V.value[2] = CAL_getOffsetValue_V(calHandle,2);
362 
363  // clear the flag
364  gFlag_runCal = false;
365  }
366  }
367 
368  // update the global variables
370 
371  // update CPU usage
372  updateCPUusage();
373 
374 #ifdef DRV8301_SPI
375  HAL_writeDrvData(halHandle,&gDrvSpi8301Vars);
376 
377  HAL_readDrvData(halHandle,&gDrvSpi8301Vars);
378 #endif
379 
380  } // end of while() loop
381 
382  // disable the PWM
383  HAL_disablePwm(halHandle);
384 
385 } // end of main() function
386 
387 
388 interrupt void mainISR(void)
389 {
390  uint32_t timer1Cnt;
391  float_t angleDelta_rad;
392  float_t angleWithDelay_rad;
393  MATH_vec2 Idq_A;
394  float_t outMax_V;
395  MATH_vec2 phasor;
396  MATH_vec2 Vab_out_V;
397  MATH_vec2 Vdq_out_V;
398  HAL_AdcData_t AdcDataWithOffset;
399 
400  // read the timer 1 value and update the CPU usage module
401  timer1Cnt = HAL_readTimerCnt(halHandle,1);
402  CPU_USAGE_updateCnts(cpu_usageHandle,timer1Cnt);
403 
404  // acknowledge the ADC interrupt
405  HAL_acqAdcInt(halHandle,ADC_IntNumber_6);
406 
407  // read the ADC data with offsets
408  HAL_readAdcDataWithOffsets(halHandle,&AdcDataWithOffset);
409 
410  // remove offsets
411  gAdcData.I_A.value[0] = AdcDataWithOffset.I_A.value[0] - gOffsets_I_A.value[0];
412  gAdcData.I_A.value[1] = AdcDataWithOffset.I_A.value[1] - gOffsets_I_A.value[1];
413  gAdcData.I_A.value[2] = AdcDataWithOffset.I_A.value[2] - gOffsets_I_A.value[2];
414  gAdcData.V_V.value[0] = AdcDataWithOffset.V_V.value[0] - gOffsets_V_V.value[0];
415  gAdcData.V_V.value[1] = AdcDataWithOffset.V_V.value[1] - gOffsets_V_V.value[1];
416  gAdcData.V_V.value[2] = AdcDataWithOffset.V_V.value[2] - gOffsets_V_V.value[2];
417  gAdcData.dcBus_V = AdcDataWithOffset.dcBus_V;
418 
419  // if enabled, run the calibrator
420  if(CAL_isEnabled(calHandle))
421  {
422  // run the calibrator
423  CAL_run(calHandle,&AdcDataWithOffset);
424  }
425 
426  // if enabled, run the estimator
428  {
429  // run Clarke transform on current
430  CLARKE_run(clarkeHandle_I,&(gAdcData.I_A),&(gEstInputData.Iab_A));
431 
432  // run Clarke transform on voltage
433  CLARKE_run(clarkeHandle_V,&(gAdcData.V_V),&(gEstInputData.Vab_V));
434 
435  // store the input data into a buffer
436  gEstInputData.dcBus_V = gAdcData.dcBus_V;
437 
438  // modify references if running Rs recalibration
439  if(EST_getState(estHandle) == EST_State_Rs)
440  {
441  gEstInputData.speed_ref_Hz = 0.0;
443  }
444  else
445  {
446  // run a trajectory for speed, so the reference changes with a ramp instead of a step
447  TRAJ_run(trajHandle_spd);
448 
449  gEstInputData.speed_ref_Hz = TRAJ_getIntValue(trajHandle_spd);
450  gId_rs_recalc_ref_A = 0.0;
451  }
452 
453  // run the estimator
454  EST_run(estHandle,&gEstInputData,&gEstOutputData);
455 
456  // run the speed controller
457  if(++gCounter_speed >= gUserParams.numCtrlTicksPerSpeedTick)
458  {
459  gCounter_speed = 0;
460 
461  PI_run_series(piHandle_spd,gEstInputData.speed_ref_Hz,gEstOutputData.fm_lp_rps * MATH_ONE_OVER_TWO_PI,0.0,&gIq_ref_A);
462  }
463 
464  // get Idq, reutilizing a Park transform used inside the estimator. This is optional, user's Park works as well
465  EST_getIdq_A(estHandle,&Idq_A);
466 
467  // run a trajectory for Id, so the reference changes with a ramp instead of a step
468  TRAJ_run(trajHandle_Id);
469 
470  // run the Id controller
471  PI_run_series(piHandle_Id,TRAJ_getIntValue(trajHandle_Id) + EST_getRsOnLineId_A(estHandle),Idq_A.value[0],0.0,&(Vdq_out_V.value[0]));
472 
473  // calculate Iq controller limits, and run Iq controller using fast RTS function, callable assembly
474  outMax_V = sqrt_fastRTS((gUserParams.maxVsMag_V * gUserParams.maxVsMag_V) - (Vdq_out_V.value[0] * Vdq_out_V.value[0]));
475  PI_setMinMax(piHandle_Iq,-outMax_V,outMax_V);
476  PI_run_series(piHandle_Iq,gIq_ref_A,Idq_A.value[1],0.0,&(Vdq_out_V.value[1]));
477 
478  // compute angle with delay compensation
479  angleDelta_rad = gUserParams.angleDelayed_sf_sec * gEstOutputData.fm_lp_rps;
480  angleWithDelay_rad = MATH_incrAngle(gEstOutputData.angle_rad, angleDelta_rad);
481 
482  // compute the sin/cos phasor using fast RTS function, callable assembly
483  sincos_fastRTS(angleWithDelay_rad, &(phasor.value[1]), &(phasor.value[0]));
484 
485  // set the phasor in the inverse Park transform
486  IPARK_setPhasor(iparkHandle,&phasor);
487 
488  // run the inverse Park module
489  IPARK_run(iparkHandle,&Vdq_out_V,&Vab_out_V);
490 
491  // setup the space vector generator (SVGEN) module
492  SVGEN_setup(svgenHandle,gEstOutputData.oneOverDcBus_invV);
493 
494  // run the space vector generator (SVGEN) module
495  SVGEN_run(svgenHandle,&Vab_out_V,&(gPwmData.Vabc_pu));
496  }
497  else
498  {
499  // create PWM data
500  gPwmData.Vabc_pu.value[0] = 0.0;
501  gPwmData.Vabc_pu.value[1] = 0.0;
502  gPwmData.Vabc_pu.value[2] = 0.0;
503  }
504 
505  // write the PWM compare values
506  HAL_writePwmData(halHandle,&gPwmData);
507 
508  // read the timer 1 value and update the CPU usage module
509  timer1Cnt = HAL_readTimerCnt(halHandle,1);
510  CPU_USAGE_updateCnts(cpu_usageHandle,timer1Cnt);
511 
512  // run the CPU usage module
513  CPU_USAGE_run(cpu_usageHandle);
514 
515  return;
516 } // end of mainISR() function
517 
518 
519 void setupClarke_I(CLARKE_Handle handle,const uint_least8_t numCurrentSensors)
520 {
521  float_t alpha_sf,beta_sf;
522 
523  // initialize the Clarke transform module for current
524  if(numCurrentSensors == 3)
525  {
526  alpha_sf = MATH_ONE_OVER_THREE;
527  beta_sf = MATH_ONE_OVER_SQRT_THREE;
528  }
529  else if(numCurrentSensors == 2)
530  {
531  alpha_sf = 1.0;
532  beta_sf = MATH_ONE_OVER_SQRT_THREE;
533  }
534  else
535  {
536  alpha_sf = 0.0;
537  beta_sf = 0.0;
538  }
539 
540  // set the parameters
541  CLARKE_setScaleFactors(handle,alpha_sf,beta_sf);
542  CLARKE_setNumSensors(handle,numCurrentSensors);
543 
544  return;
545 } // end of setupClarke_I() function
546 
547 
548 void setupClarke_V(CLARKE_Handle handle,const uint_least8_t numVoltageSensors)
549 {
550  float_t alpha_sf,beta_sf;
551 
552  // initialize the Clarke transform module for voltage
553  if(numVoltageSensors == 3)
554  {
555  alpha_sf = MATH_ONE_OVER_THREE;
556  beta_sf = MATH_ONE_OVER_SQRT_THREE;
557  }
558  else
559  {
560  alpha_sf = 0.0;
561  beta_sf = 0.0;
562  }
563 
564  // set the parameters
565  CLARKE_setScaleFactors(handle,alpha_sf,beta_sf);
566  CLARKE_setNumSensors(handle,numVoltageSensors);
567 
568  return;
569 } // end of setupClarke_V() function
570 
571 
573 {
574  float_t Ls_d_H = gUserParams.motor_Ls_d_H;
575  float_t Ls_q_H = gUserParams.motor_Ls_q_H;
576  float_t Rs_d_Ohm = gUserParams.motor_Rs_d_Ohm;
577  float_t Rs_q_Ohm = gUserParams.motor_Rs_q_Ohm;
578  float_t RdoverLd_rps = Rs_d_Ohm / Ls_d_H;
579  float_t RqoverLq_rps = Rs_q_Ohm / Ls_q_H;
580  float_t BWc_rps = gUserParams.BWc_rps;
581  float_t currentCtrlPeriod_sec = (float_t)gUserParams.numCtrlTicksPerCurrentTick / gUserParams.ctrlFreq_Hz;
582  float_t outMax_V = gUserParams.Vd_sf * gUserParams.maxVsMag_V;
583 
584  float_t Kp_Id = Ls_d_H * BWc_rps;
585  float_t Ki_Id = RdoverLd_rps * currentCtrlPeriod_sec;
586 
587  float_t Kp_Iq = Ls_q_H * BWc_rps;
588  float_t Ki_Iq = RqoverLq_rps * currentCtrlPeriod_sec;
589 
590  // set the Id controller
591  PI_setGains(piHandle_Id,Kp_Id,Ki_Id);
592  PI_setUi(piHandle_Id,0.0);
593  PI_setRefValue(piHandle_Id,0.0);
594  PI_setFbackValue(piHandle_Id,0.0);
595  PI_setFfwdValue(piHandle_Id,0.0);
596  PI_setMinMax(piHandle_Id,-outMax_V,outMax_V);
597 
598  // set the Iq controller
599  PI_setGains(piHandle_Iq,Kp_Iq,Ki_Iq);
600  PI_setUi(piHandle_Iq,0.0);
601  PI_setRefValue(piHandle_Iq,0.0);
602  PI_setFbackValue(piHandle_Iq,0.0);
603  PI_setFfwdValue(piHandle_Iq,0.0);
604  PI_setMinMax(piHandle_Iq,0.0,0.0);
605 
606  // set the speed controller
607  PI_setGains(piHandle_spd,gSpeed_Kp,gSpeed_Ki);
608  PI_setUi(piHandle_spd,0.0);
609  PI_setRefValue(piHandle_spd,0.0);
610  PI_setFbackValue(piHandle_spd,0.0);
611  PI_setFfwdValue(piHandle_spd,0.0);
612  PI_setMinMax(piHandle_spd,-gUserParams.maxCurrent_A,gUserParams.maxCurrent_A);
613 
614  return;
615 } // end of setupCurrentControllers() function
616 
617 
619 {
620  // get the states
621  gCalState = CAL_getState(calHandle);
622  gEstState = EST_getState(estHandle);
623 
624  // get the speed estimate
625  gSpeed_Hz = EST_getFe_Hz(estHandle);
626 
627  // get the torque estimate
628  gTorque_Nm = EST_computeTorque_Nm(estHandle);
629 
630  // get the stator resistance estimate from RsOnLine
631  gRsOnLine_Ohm = EST_getRsOnLine_Ohm(estHandle);
632 
633  // get the stator resistance
634  gRs_Ohm = EST_getRs_Ohm(estHandle);
635 
636  // get the stator inductance in the direct coordinate direction
637  gLs_d_H = EST_getLs_d_H(estHandle);
638 
639  // get the stator inductance in the quadrature coordinate direction
640  gLs_q_H = EST_getLs_q_H(estHandle);
641 
642  // get the flux, Wb
643  gFlux_Wb = EST_getFlux_Wb(estHandle);
644 
645  return;
646 } // end of updateGlobalVariables_motor() function
647 
648 
649 void updateCPUusage(void)
650 {
651  uint32_t minDeltaCntObserved = CPU_USAGE_getMinDeltaCntObserved(cpu_usageHandle);
652  uint32_t avgDeltaCntObserved = CPU_USAGE_getAvgDeltaCntObserved(cpu_usageHandle);
653  uint32_t maxDeltaCntObserved = CPU_USAGE_getMaxDeltaCntObserved(cpu_usageHandle);
654  uint16_t pwmPeriod = HAL_readPwmPeriod(halHandle,PWM_Number_1);
655  float_t cpu_usage_den = (float_t)pwmPeriod * (float_t)USER_NUM_PWM_TICKS_PER_ISR_TICK * 2.0;
656 
657  // calculate the minimum cpu usage percentage
658  gCpuUsagePercentageMin = (float_t)minDeltaCntObserved / cpu_usage_den * 100.0;
659 
660  // calculate the average cpu usage percentage
661  gCpuUsagePercentageAvg = (float_t)avgDeltaCntObserved / cpu_usage_den * 100.0;
662 
663  // calculate the maximum cpu usage percentage
664  gCpuUsagePercentageMax = (float_t)maxDeltaCntObserved / cpu_usage_den * 100.0;
665 
666  return;
667 } // end of updateCPUusage() function
668 
669 
670 // end of file
671 
#define USER_SYSTEM_FREQ_MHz
CLOCKS & TIMERS.
Definition: user.h:140
PI_Obj pi_Id
the Id PI controller object
float_t EST_getRsOnLine_Ohm(EST_Handle handle)
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 gCpuUsagePercentageAvg
float_t gRs_Ohm
void HAL_enableGlobalInts(HAL_Handle handle)
void HAL_enableAdcInts(HAL_Handle handle)
volatile bool gFlag_runOnLine
SVGEN_Handle svgenHandle
the handle for the space vector generator
float_t EST_getFlux_Wb(EST_Handle handle)
IPARK_Handle iparkHandle
the handle for the inverse Park transform
void updateGlobalVariables_motor(EST_Handle estHandle)
Updates the global motor variables.
void EST_setRsOnLineId_mag_A(EST_Handle handle, const float_t Id_mag_A)
static void PI_setFfwdValue(PI_Handle handle, const _iq ffwdValue)
MATH_vec3 Vabc_pu
static void HAL_readAdcDataWithOffsets(HAL_Handle handle, HAL_AdcData_t *pAdcData)
static void CAL_run(CAL_Handle handle, const HAL_AdcData_t *pAdcData)
static void TRAJ_setMaxDelta(TRAJ_Handle handle, const _iq maxDelta)
volatile bool gFlag_enableForceAngle
float_t gLs_d_H
Global variable for the stator inductance in the direct coordinate direction, Henry.
float_t motor_Rs_d_Ohm
PI_Obj pi_spd
the speed PI controller object
void main(void)
static _iq TRAJ_getIntValue(TRAJ_Handle handle)
PARK_Handle parkHandle
the handle for the Park object
float_t maxAccel_Hzps
#define USER_EST_FREQ_Hz
Defines the estimator frequency, Hz.
Definition: user.h:219
CAL_State_e gCalState
static void HAL_writePwmData(HAL_Handle handle, HAL_PwmData_t *pPwmData)
#define MATH_TWO_PI
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)
MATH_vec3 gOffsets_I_A
static void PI_setUi(PI_Handle handle, const _iq Ui)
static void HAL_acqAdcInt(HAL_Handle handle, const ADC_IntNumber_e intNumber)
float_t motor_Rs_q_Ohm
TRAJ_Handle trajHandle_spd
the handle for the speed trajectory
static void CAL_setFlag_enableAdcOffset(CAL_Handle handle, const bool value)
uint_least8_t numCurrentSensors
volatile float_t gRsOnLinePole_Hz
bool EST_isEnabled(EST_Handle handle)
volatile float_t gRsOnLineId_mag_A
void CAL_setParams(CAL_Handle handle, const USER_Params *pUserParams)
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)
EST_Handle estHandle
the handle for the estimator
TRAJ_Handle trajHandle_Id
the handle for the Id trajectory
uint_least16_t numCtrlTicksPerCurrentTick
float_t gRsOnLine_Ohm
#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.
void EST_setFlag_updateRs(EST_Handle handle, const bool state)
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)
volatile bool gFlag_enableRsOnLine
CLARKE_Handle clarkeHandle_I
the handle for the current Clarke transform
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)
PARK_Obj park
the Park transform object
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.
void EST_getIdq_A(EST_Handle handle, MATH_vec2 *pIdq_A)
static void HAL_enablePwm(HAL_Handle handle)
EST_State_e
CPU_USAGE_Obj cpu_usage
volatile float_t gRsOnLineFreq_Hz
float_t gId_rs_recalc_ref_A
IPARK_Obj ipark
the inverse Park transform object
volatile float_t gSpeed_Ki
PI_Handle piHandle_Id
the handle for the Id PI controller
void HAL_enableDrv(HAL_Handle handle)
_iq value[2]
EST_Handle EST_initEst(const uint_least8_t estNumber)
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)
PI_Handle piHandle_spd
the handle for the speed PI controller
void HAL_enableDebugInt(HAL_Handle handle)
CAL_Handle calHandle
the handle for the calibrator
CLARKE_Handle CLARKE_init(void *pMemory, const size_t numBytes)
CLARKE_Obj clarke_I
the current Clarke transform object
CPU_USAGE_Handle cpu_usageHandle
float_t oneOverDcBus_invV
TRAJ_Obj traj_spd
the speed trajectory object
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)
float_t gSpeed_ref_Hz
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.
uint16_t gCounter_speed
volatile float_t gId_ref_A
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
void EST_setFlag_enableRsOnLine(EST_Handle handle, const bool state)
volatile bool gFlag_updateRs
float_t gSpeed_Hz
interrupt void mainISR(void)
The main interrupt service (ISR) routine.
PI_Obj pi_Iq
the Iq PI controller object
static uint32_t HAL_readTimerCnt(HAL_Handle handle, const uint_least8_t timerNumber)
static _iq CAL_getOffsetValue_V(CAL_Handle handle, const uint_least8_t sensorNumber)
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)
EST_InputData_t gEstInputData
CPU_USAGE_Handle CPU_USAGE_init(void *pMemory, const size_t numBytes)
static void HAL_disablePwm(HAL_Handle handle)
void EST_setRsOnLineAngleDelta_rad(EST_Handle handle, const float_t angleDelta_rad)
static void TRAJ_setMaxValue(TRAJ_Handle handle, const _iq maxValue)
SVGEN_Obj svgen
the space vector generator object
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 EST_setRsOnLine_beta_rad(EST_Handle handle, const float_t beta_rad)
float_t gCpuUsagePercentageMin
void updateCPUusage(void)
Updates CPU usage.
static CAL_State_e CAL_getState(CAL_Handle handle)
MATH_vec3 gOffsets_V_V
float_t EST_getRsOnLineId_A(EST_Handle handle)
float_t gFlux_Wb
Global variable for the rotor flux estimate, Wb.
MATH_vec2 Iab_A
uint_least32_t ctrlFreq_Hz
CAL_Handle CAL_init(void *pMemory, const size_t numBytes)
EST_OutputData_t gEstOutputData
void SVGEN_setup(SVGEN_Handle svgenHandle)
static void PI_setMinMax(PI_Handle handle, const _iq outMin, const _iq outMax)
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.
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.
CAL_Obj cal
the calibrator object
MATH_vec2 Vab_V
static uint32_t CPU_USAGE_getMinDeltaCntObserved(CPU_USAGE_Handle handle)
#define MATH_ONE_OVER_SQRT_THREE
TRAJ_Obj traj_Id
the Id trajectory 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)
HAL_PwmData_t gPwmData
Defines the PWM data.
volatile bool gFlag_runCal
bool EST_updateState(EST_Handle handle, const _iq Id_target_pu)
uint_least32_t estFreq_Hz
CLARKE_Handle clarkeHandle_V
the handle for the voltage Clarke transform
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.
float_t EST_getFe_Hz(EST_Handle handle)
void HAL_readDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
float_t maxCurrent_resEst_A
static bool CAL_isEnabled(CAL_Handle handle)
volatile float_t gSpeed_Kp
float_t gTorque_Nm
Global variable for the estimated torque, N*m.
static void TRAJ_run(TRAJ_Handle handle)
float_t motor_Ls_d_H
volatile bool gFlag_enableRsRecalc
float_t motor_Ls_q_H
CLARKE_Obj clarke_V
the voltage Clarke transform object
SVGEN_Handle SVGEN_init(void *pMemory, const size_t numBytes)
float_t gCpuUsagePercentageMax
HAL_Obj hal
the hardware abstraction layer object
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
PI_Handle piHandle_Iq
the handle for the Iq PI controller
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