instaspin_foc
proj_enc_fast.c
Go to the documentation of this file.
1 
7 
8 // **************************************************************************
9 // the includes
10 
11 // system includes
12 #include <math.h>
13 
14 // drivers
15 
16 
17 // modules
18 #include "sw/modules/cal/src/float/cal.h"
19 #include "sw/modules/ipark/src/float/ipark.h"
20 #include "sw/modules/park/src/float/park.h"
22 #include "sw/modules/svgen/src/float/svgen.h"
23 #include "sw/drivers/qep/src/32b/f28x/f2806x/qep.h"
24 #include "dmc_enc/sw/modules/enc/src/float/enc.h"
25 #include "dmc_enc/sw/modules/enc_cal/src/float/enc_cal.h"
26 
28 
29 
30 // solutions
31 #include "main.h"
32 
33 
34 // **************************************************************************
35 // the defines
36 
37 
38 // **************************************************************************
39 // the globals
40 
41 int_least32_t gCounter_enableSys = 0;
42 
43 int_least32_t gCounter_isr = 0;
44 
45 int_least32_t gCounter_main = 0;
46 
47 CAL_State_e gCalState = CAL_State_Idle;
48 
49 CTRL_State_e gCtrlState = CTRL_State_Idle;
50 
51 ENC_CAL_State_e gEncCalState = ENC_CAL_State_Idle;
52 
53 EST_State_e gEstState = EST_State_Idle;
54 
55 EST_Traj_State_e gTrajState = EST_Traj_State_Idle;
56 
57 volatile bool gFlag_bypassLockRotor = false;
58 
59 volatile bool gFlag_enableSys = false;
60 
61 volatile bool gFlag_runCal = false;
62 
63 volatile bool gFlag_runIdentAndOnLine = false;
64 
65 volatile bool gFlag_enableForceAngle = true;
66 
67 volatile bool gFlag_enablePowerWarp = false;
68 
69 volatile bool gFlag_enableQueue = false;
70 
71 volatile bool gFlag_enableRsOnLine = false;
72 
73 volatile bool gFlag_enableRsRecalc = true;
74 
75 volatile bool gFlag_updateRs = false;
76 
77 volatile bool gFlag_runEncCal = true;
78 
79 volatile bool gFlag_runInSpeedMode = true;
80 
81 uint_least16_t gBufferIndex_est = 0;
82 
83 uint_least16_t gBufferIndex_setup = 0;
84 
86 
88 
90 
92 
94 
96 
98 
100 
102 
104 
106 
108 
110 
112 
114 
116 
118 
119 float_t gSpeedOutMax_A = USER_MOTOR_MAX_CURRENT_A;
120 
122 
124 
125 volatile float_t gSpeed_Kp = 0.1;
126 
127 volatile float_t gSpeed_Ki = 0.01;
128 
130 
132 
134 
136 
138 
139 volatile float_t gRsOnLineFreq_Hz = 0.2;
140 
141 volatile float_t gRsOnLineId_mag_A = 0.5;
142 
143 volatile float_t gRsOnLinePole_Hz = 0.2;
144 
146 
148 
150 
152 
155 
158 
159 ENC_CAL_Handle enc_calHandle;
160 ENC_CAL_Obj enc_cal;
161 
164 
167 
170 
173 
176 
178 
181 
184 
187 
190 
191 
192 volatile bool gflag_configCtrl_once = true;
193 
194 #ifdef DRV8301_SPI
195 // Watch window interface to the 8301 SPI
196 DRV_SPI_8301_Vars_t gDrvSpi8301Vars;
197 #endif
198 
199 
205 
206 // Graphing Variables
207 #define GRAPH_SIZE 100
211 volatile bool Graph_Flag_Enable_update = false;
212 uint16_t Graph_Counter = 0;
213 uint16_t Graph_Tick_Counter = 0;
214 volatile uint16_t Graph_Tick_Counter_Value = 10;
217 
218 // **************************************************************************
219 // the functions
220 
221 void main(void)
222 {
223  uint_least8_t ctrlNumber = 0;
224  uint_least8_t estNumber = 0;
225  uint_least8_t graphCounter = 0;
226 
227 
228  // initialize the user parameters
229  USER_setParams(&gUserParams);
230 
231 
232  // initialize the user parameters
233  USER_setParams_priv(&gUserParams);
234 
235 
236  // initialize the driver
237  halHandle = HAL_init(&hal,sizeof(hal));
238 
239 
240  // set the driver parameters
241  HAL_setParams(halHandle,&gUserParams);
242 
243 
244  // initialize the angle generator
245  angleHandle = ANGLE_init(&angle,sizeof(angle));
246 
247 
248  // set the default angle generator parameters
249  ANGLE_setParams(angleHandle,gUserParams.ctrlPeriod_sec,gUserParams.angleDelayed_sf_sec);
250 
251 
252  // initialize the calibrator
253  calHandle = CAL_init(&cal,sizeof(cal));
254 
255 
256  // set the default calibrator parameters
257  CAL_setParams(calHandle,&gUserParams);
258 
259 
260  // initialize the Clarke modules
261  clarkeHandle_I = CLARKE_init(&clarke_I,sizeof(clarke_I));
262  clarkeHandle_V = CLARKE_init(&clarke_V,sizeof(clarke_V));
263 
264 
265  // set the Clarke parameters
266  setupClarke_I(clarkeHandle_I,gUserParams.numCurrentSensors);
267  setupClarke_V(clarkeHandle_V,gUserParams.numVoltageSensors);
268 
269 
270  // initialize the controller
271  ctrlHandle = CTRL_init(&(ctrl[ctrlNumber]),sizeof(ctrl[ctrlNumber]));
272 
273 
274  // get the version number
275  CTRL_getVersion(ctrlHandle,&gVersion);
276 
277 
278  // set the default controller parameters
279  CTRL_setParams(ctrlHandle,&gUserParams);
280 
281 
282  // set custom speed controller gains
283  CTRL_setGains(ctrlHandle,CTRL_Type_PI_spd,0.3,0.05);
284 
285 
286  // initialize the Encoder module
287  encHandle = ENC_init(&enc,sizeof(enc));
288  ENC_setParams(encHandle,\
289  &gUserParams,\
290  1,\
291  32, \
292  1.0e-3, \
293  0.1, \
294  13.1338);
295 
296 
297  // initialize the Encoder Calibration module
298  enc_calHandle = ENC_CAL_init(&enc_cal,sizeof(enc_cal));
299  ENC_CAL_setParams(enc_calHandle,\
300  USER_MOTOR_MAX_CURRENT_A,\
301  0.0,\
302  (uint32_t)(2.0 / CTRL_getCurrentCtrlPeriod_sec(ctrlHandle)));
303 
304 
305  // enable the encoder calibration so that it happens immediately after the control is enabled
306  gFlag_runEncCal = true;
307 
308 
309  // initialize the estimator
310  estHandle = EST_initEst(estNumber);
311 
312 
313  // set the default estimator parameters
314  EST_setParams(estHandle,&gUserParams);
321 
322 
323  // if motor type is an induction motor, configure default state of PowerWarp
324  if(gUserParams.motor_type == MOTOR_Type_Induction)
325  {
328  }
329 
330 
331  // initialize the inverse Park module
332  iparkHandle = IPARK_init(&ipark,sizeof(ipark));
333 
334 
335  // initialize the Park module
336  parkHandle = PARK_init(&park,sizeof(park));
337 
338 
339  // initialize the queue
340  queueHandle = QUEUE_init(&queue,sizeof(queue));
341 
342 
343  // initialize the space vector generator module
344  svgenHandle = SVGEN_init(&svgen,sizeof(svgen));
345 
346 
347  // initialize the CPU usage module
348  cpu_usageHandle = CPU_USAGE_init(&cpu_usage,sizeof(cpu_usage));
349  CPU_USAGE_setParams(cpu_usageHandle,
350  (uint32_t)USER_SYSTEM_FREQ_MHz * 1000000, // timer period, cnts
351  (uint32_t)USER_ISR_FREQ_Hz); // average over 1 second of ISRs
352 
353 
354  // calculate the controller gains
355  calcGains(ctrlHandle,estHandle);
356 
357 
358  // setup faults
359  HAL_setupFaults(halHandle);
360 
361 
362  // initialize the interrupt vector table
363  HAL_initIntVectorTable(halHandle);
364 
365 
366  // enable the ADC interrupts
367  HAL_enableAdcInts(halHandle);
368 
369 
370  // enable global interrupts
371  HAL_enableGlobalInts(halHandle);
372 
373 
374  // enable debug interrupts
375  HAL_enableDebugInt(halHandle);
376 
377 
378  // disable the PWM
379  HAL_disablePwm(halHandle);
380 
381 
382  // initialize the Graph Variables
383  for(graphCounter=0; graphCounter<GRAPH_SIZE; graphCounter++)
384  {
385  Graph_Data1[graphCounter] = 0.0;
386  Graph_Data2[graphCounter] = 0.0;
387  Graph_Data3[graphCounter] = 0.0;
388  }
389 
390 
391 #ifdef DRV8301_SPI
392  // turn on the DRV8301 if present
393  HAL_enableDrv(halHandle);
394  // initialize the DRV8301 interface
395  HAL_setupDrvSpi(halHandle,&gDrvSpi8301Vars);
396 #endif
397 
398 
399  // Waiting for enable system flag to be set
400  while(!gFlag_enableSys)
401  {
403  }
404 
405 
406  // loop while the enable system flag is true
407  while(gFlag_enableSys)
408  {
409 
410  // increment counters
411  gCounter_main++;
412 
413  // enable or disable bypassLockRotor flag
414  if(gUserParams.motor_type == MOTOR_Type_Induction)
415  {
417  }
418 
420  {
421  // set custom speed controller gains
422  CTRL_setGains(ctrlHandle,CTRL_Type_PI_spd,gSpeed_Kp,gSpeed_Ki);
423 
424  // enable or disable force angle
426 
427  // enable or disable PowerWarp
428  if(gUserParams.motor_type == MOTOR_Type_Induction)
429  {
431  }
432 
433  // enable or disable RsOnLine
435 
436  // set slow rotating frequency for RsOnLine
438 
439  // set current amplitude for RsOnLine
441 
442  // set RsOnLine beta based on the desired filter pole
444 
445  // enable or disable Rs recalibration
447 
448  // set flag that updates Rs from RsOnLine value
450 
451  // set maximum acceleration
452  EST_setMaxDelta_spd(estHandle,gSpeed_ref_traj * ((float_t)1.0 / USER_TRAJ_FREQ_Hz));
453  }
454 
456  {
457  // disable the calibrator
458  CAL_disable(calHandle);
459 
460  // disable the controller
461  CTRL_disable(ctrlHandle);
462 
463  // disable the estimator
465 
466  // disable the trajectory generator
468 
469  // disable the PWM
470  HAL_disablePwm(halHandle);
471  }
472  else if(gFlag_runCal)
473  {
474  // enable the calibrator
475  CAL_setFlag_enableAdcOffset(calHandle,true);
476 
477  // enable the calibrator
478  CAL_enable(calHandle);
479 
480  // disable the controller
481  CTRL_disable(ctrlHandle);
482 
483  // disable the estimator
485 
486  // disable the trajectory generator
488 
489  // enable the PWM
490  HAL_enablePwm(halHandle);
491  }
492  else if(gFlag_runIdentAndOnLine)
493  {
494  CTRL_State_e ctrlState = CTRL_getState(ctrlHandle);
495 
496  // disable the calibrator
497  CAL_disable(calHandle);
498 
499  // enable the controller
500  CTRL_enable(ctrlHandle);
501 
502  // enable the estimator
504 
505  // enable the trajectory generator
507 
508  // enable the PWM
509  HAL_enablePwm(halHandle);
510 
511  if(gFlag_runEncCal && (ctrlState == CTRL_State_OnLine))
512  {
513  ENC_CAL_enable(enc_calHandle);
514  }
515  }
516 
517 
518  // check the calibrator
519  if(CAL_isError(calHandle))
520  {
521  // disable the PWM
522  HAL_disablePwm(halHandle);
523 
524  // set the enable system flag to false
525  gFlag_enableSys = false;
526  }
527  else
528  {
529  // update the calibrator state
530  bool flag_calStateChanged = CAL_updateState(calHandle);
531 
532  if(flag_calStateChanged)
533  {
534  CAL_State_e calState = CAL_getState(calHandle);
535 
536  if(calState == CAL_State_Done)
537  {
538  // update the ADC bias values
539  HAL_updateAdcBias(halHandle,
540  CAL_getOffsetHandleAddr_I(calHandle),
541  CAL_getOffsetHandleAddr_V(calHandle));
542 
543  // clear the flag
544  gFlag_runCal = false;
545  }
546  }
547  }
548 
549 
550  // Check the encoder calibration
551  if(ENC_CAL_isError(enc_calHandle))
552  {
553  // disable the PWM
554  HAL_disablePwm(halHandle);
555 
556  // set the enable system flag to false
557  gFlag_enableSys = false;
558  }
559  else
560  {
561  bool flag_EncCalStateChanged = ENC_CAL_updateState(enc_calHandle);
562 
563  if(flag_EncCalStateChanged)
564  {
565  ENC_CAL_State_e enc_calState = ENC_CAL_getState(enc_calHandle);
566 
567  if(enc_calState == ENC_CAL_State_Done)
568  {
569  gFlag_runEncCal = false;
570  }
571  }
572  }
573 
574 
575  // check the trajectory generator
577  {
578  // disable the PWM
579  HAL_disablePwm(halHandle);
580 
581  // set the enable system flag to false
582  gFlag_enableSys = false;
583  }
584  else
585  {
586  // update the trajectory generator state
587  bool flag_trajStateChanged = EST_updateTrajState(estHandle);
588 
589  if(flag_trajStateChanged)
590  {
592 
594  (state == EST_Traj_State_OnLine))
595  {
596  float_t spd_min_Hz = -1000.0;
597  float_t spd_max_Hz = 1000.0;
598  float_t spd_maxDelta_Hz = gSpeed_ref_traj / (float_t)gUserParams.trajFreq_Hz; //20.0 / (float_t)gUserParams.trajFreq_Hz;
599 
600  // setup the spd trajectory
601  EST_setMinValue_spd(estHandle,spd_min_Hz);
602  EST_setMaxValue_spd(estHandle,spd_max_Hz);
603  EST_setMaxDelta_spd(estHandle,spd_maxDelta_Hz);
604  }
605  }
606  }
607 
608 
609  // check the estimator
611  {
612  // disable the PWM
613  HAL_disablePwm(halHandle);
614 
615  // set the enable system flag to false
616  gFlag_enableSys = false;
617  }
618  else
619  {
620  // update the estimator state
621  float_t Id_target_A = EST_getIntValue_Id(estHandle);
622  bool flag_estStateChanged = EST_updateState(estHandle,Id_target_A);
623 
624  if(flag_estStateChanged)
625  {
626  // configure the controller
627  EST_configureCtrl(estHandle,ctrlHandle);
628 
629  // configure the trajectory generator
631 
632  if(EST_isLockRotor(estHandle) ||
634  {
635  // clear the flag
636  gFlag_runIdentAndOnLine = false;
637 
638  // clear RsOnLine enable flag
639  gFlag_enableRsOnLine = false;
640 
641  // clear PowerWarp enable flag
642  gFlag_enablePowerWarp = false;
643 
644  // clear Rs update flag
645  gFlag_updateRs = false;
646 
647  // reset the Id trajectory target value
648  gId_trajTarget_A = 0.0;
649  }
650  else if(EST_isOnLine(estHandle))
651  {
652  if(gUserParams.motor_type == MOTOR_Type_Induction)
653  {
654  // set the Id trajectory target value
656  }
657  }
658  }
659  }
660 
661 
662  // check the controller
663  if(CTRL_isError(ctrlHandle))
664  {
665  // disable the PWM
666  HAL_disablePwm(halHandle);
667 
668  // set the enable system flag to false
669  gFlag_enableSys = false;
670  }
671 
672 
673  // check the queue
674  while(QUEUE_isEvent(queueHandle))
675  {
676  // execute event
677  QUEUE_executeEvent(queueHandle);
678  }
679 
680 
681  // update the global variables
683 
684  // update CPU usage
685  updateCPUusage(ctrlHandle);
686 
687 #ifdef DRV8301_SPI
688  HAL_writeDrvData(halHandle,&gDrvSpi8301Vars);
689 
690  HAL_readDrvData(halHandle,&gDrvSpi8301Vars);
691 #endif
692 
693  } // end of while() loop
694 
695 
696  // disable the PWM
697  HAL_disablePwm(halHandle);
698 
699 } // end of main() function
700 
701 
703 {
704  float_t Ls_d_H = EST_getLs_d_H(estHandle);
705  float_t Ls_q_H = EST_getLs_q_H(estHandle);
706  float_t Rs_Ohm = EST_getRs_Ohm(estHandle);
707  float_t RoverLd_rps = Rs_Ohm / Ls_d_H;
708  float_t RoverLq_rps = Rs_Ohm / Ls_q_H;
709  float_t BWc_rps = CTRL_getBWc_rps(handle);
710 
711  float_t currentCtrlPeriod_sec = CTRL_getCurrentCtrlPeriod_sec(handle);
712  float_t Kp_Id = Ls_d_H * BWc_rps;
713  float_t Ki_Id = RoverLd_rps * currentCtrlPeriod_sec;
714 
715  float_t Kp_Iq = Ls_q_H * BWc_rps;
716  float_t Ki_Iq = RoverLq_rps * currentCtrlPeriod_sec;
717 
718 
719  // set the Id controller gains
720  CTRL_setGains(handle,CTRL_Type_PI_Id,Kp_Id,Ki_Id);
721 
722  // set the Iq controller gains
723  CTRL_setGains(handle,CTRL_Type_PI_Iq,Kp_Iq,Ki_Iq);
724 
725  return;
726 } // end of calcGains() function
727 
728 
729 interrupt void mainISR(void)
730 {
731  uint32_t timer1Cnt;
732  MATH_vec2 Iab_in_A;
733  MATH_vec2 Vab_in_V;
734 
735 
736  // read the timer 1 value and update the CPU usage module
737  timer1Cnt = HAL_readTimerCnt(halHandle,1);
738  CPU_USAGE_updateCnts(cpu_usageHandle,timer1Cnt);
739 
740 
741  // turn LED 3 on
742  HAL_turnLedOn(halHandle,(GPIO_Number_e)HAL_Gpio_LED3);
743 
744 
745  // acknowledge the ADC interrupt
746  HAL_acqAdcInt(halHandle,ADC_IntNumber_6);
747 
748 
749  // increment the ISR counter
750  incrCount_isr();
751 
752 
753  // increment the isr counters
754  CTRL_incrCounter_isr(ctrlHandle);
757 
758 
759  // convert the ADC data
760  HAL_readAdcData(halHandle,&gAdcData);
761 
762 
763  // run Clarke transform on current
764  CLARKE_run(clarkeHandle_I,&gAdcData.I_A,&Iab_in_A);
765 
766 
767  // run Clarke transform on voltage
768  CLARKE_run(clarkeHandle_V,&gAdcData.V_V,&Vab_in_V);
769 
770 
771  // if enabled, run the calibrator
772  if(CAL_isEnabled(calHandle))
773  {
774  // run the calibrator
775  CAL_run(calHandle,&gAdcData);
776  }
777 
778 
779  // if enabled, run the trajectory generator
781  {
782  int_least16_t count_traj = EST_getTrajCount_isr(estHandle);
783  int_least16_t numIsrTicksPerTrajTick = EST_getNumIsrTicksPerTrajTick(estHandle);
784 
785 
786  // as needed, run the trajectory generator
787  if(count_traj >= numIsrTicksPerTrajTick)
788  {
789  // reset the trajectory count
791 
792  // setup the trajectory generator
794  ctrlHandle,
797 
798  // run the trajectories
800  } // end of if(gFlag_traj) block
801  }
802 
803 
804  // if enabled, run the estimator
806  {
807  int_least16_t count_est = EST_getCount_isr(estHandle);
808  int_least16_t numIsrTicksPerEstTick = EST_getNumIsrTicksPerEstTick(estHandle);
809 
810 
811  // as needed, run the estimator
812  if(count_est >= numIsrTicksPerEstTick)
813  {
814  EVENT_ArgList argList;
815 
816  // reset the estimator count
818 
819  // store the input data into a buffer
820  gEstInputData[gBufferIndex_est].timeStamp = gCounter_isr;
821  gEstInputData[gBufferIndex_est].Iab_A.value[0] = Iab_in_A.value[0];
822  gEstInputData[gBufferIndex_est].Iab_A.value[1] = Iab_in_A.value[1];
823  gEstInputData[gBufferIndex_est].Vab_V.value[0] = Vab_in_V.value[0];
824  gEstInputData[gBufferIndex_est].Vab_V.value[1] = Vab_in_V.value[1];
825  gEstInputData[gBufferIndex_est].dcBus_V = gAdcData.dcBus_V;
826  gEstInputData[gBufferIndex_est].speed_ref_Hz = EST_getIntValue_spd(estHandle);
827 
828  if(gFlag_enableQueue == true)
829  {
830  // post the estimator to the queue
831  argList.arg[0] = estHandle;
832  argList.arg[1] = &gEstInputData[gBufferIndex_est];
833  argList.arg[2] = &gEstOutputData[gBufferIndex_est];
834  argList.arg[3] = NULL;
835  QUEUE_postEventLast(queueHandle,(EVENT_Fxn)EST_run,&argList,3);
836  }
837  else
838  {
839  // run the estimator
841  &gEstInputData[gBufferIndex_est],
842  &gEstOutputData[gBufferIndex_est]);
843  }
844 
845  // increment the estimator buffer index
847  }
848 
849 
850  // setup the angle module
852  {
853  ANGLE_setup(angleHandle,
854  gEstOutputData[gBufferIndex_setup].timeStamp,
855  gEstOutputData[gBufferIndex_setup].angle_rad,
856  gEstOutputData[gBufferIndex_setup].fm_lp_rps,
857  gEstOutputData[gBufferIndex_setup].fmDot_rps2);
858 
859  // increment the estimator buffer index
861 
862  // clear the flag
864  }
865  }
866  else
867  {
868  // reset the angle module but keep the angle fixed
869  ANGLE_setup(angleHandle,
870  gCounter_isr,
871  gEstOutputData[gBufferIndex_setup].angle_rad,
872  (float_t)0.0, // speed_rps
873  (float_t)0.0); // accel_rps2
874  }
875 
876 
877  // run the angle module
878  ANGLE_run(angleHandle,gCounter_isr);
879 
880 
881  // if enabled, run the controller
882  if(CTRL_isEnabled(ctrlHandle))
883  {
884  int_least16_t count_ctrl = CTRL_getCount_isr(ctrlHandle);
885  int_least16_t numIsrTicksPerCtrlTick = CTRL_getNumIsrTicksPerCtrlTick(ctrlHandle);
886 
887 
888  // as needed, run the controller
889  if(count_ctrl >= numIsrTicksPerCtrlTick)
890  {
891  bool flag_doSpeedCtrl= gFlag_runInSpeedMode;
892  bool flag_doCurrentCtrl = true;
893  bool flag_useZeroIq_ref = false;
894  float_t angleElec_rad = ENC_getAngleElec(encHandle); // Get the electrical angle from the encoder
895  float_t angleMech_rad = ENC_getAngleMech(encHandle); // Get the mechanical angle from the encoder
896  float_t oneOverDcBus_invV = 1/24.0; // EST_getOneOverDcBus_invV(estHandle);
897  float_t speed_ref_Hz = gSpeed_ref_Hz; // Get the speed reference
898  float_t speed_Hz = ENC_getSpeedMech(encHandle) * (float_t)USER_MOTOR_NUM_POLE_PAIRS; // Get the mechanical speed from the encoder
899  float_t angleWithDelay_rad;
900 
901  MATH_vec2 Idq_A;
902  MATH_vec2 Vdq_out_V;
903  MATH_vec2 Vab_out_V;
904  MATH_vec2 phasor;
905 
906  MATH_vec2 Idq_offset_A;
907  MATH_vec2 Vdq_offset_V;
908 
909  uint16_t flagQepInt = QEP_read_interrupt_flag(hal.qepHandle[0],QEINT_Uto);
910  uint32_t posCntReg = QEP_read_posn_count(hal.qepHandle[0]); // Get the position counter value
911 
912 
913  if(flagQepInt == QEINT_Uto)
914  {
915  uint16_t qepsts = QEP_read_status(hal.qepHandle[0]);
916  bool qepDirection = ((qepsts & QEP_QEPSTS_QDF) == QEP_QEPSTS_QDF); // Monitor the direction
917  bool qepCapOverflow = ((qepsts & QEP_QEPSTS_COEF) == QEP_QEPSTS_COEF); // Check for a QEP capture timer overflow
918  bool qepsts_upevent = ((qepsts & QEP_QEPSTS_UPEVNT) == QEP_QEPSTS_UPEVNT); // Check for an up event
919  uint32_t qepPosFreq = QEP_read_posn_latch(hal.qepHandle[0]);
920  uint16_t qepCapPrd = QEP_read_capture_period_latch(hal.qepHandle[0]);
921 
922  QEP_clear_interrupt_flag(hal.qepHandle[0],QEINT_Uto);
923 
924  if(qepsts_upevent)
925  {
926  QEP_reset_status(hal.qepHandle[0],UPEVNT);
927  if(qepCapOverflow)
928  QEP_reset_status(hal.qepHandle[0],COEF);
929  }
930 
931  ENC_setupSpeed(encHandle, \
932  qepCapPrd, \
933  qepPosFreq, \
934  qepDirection, \
935  qepCapOverflow);
936 
937  ENC_runSpeed(encHandle);
938  speed_Hz = ENC_getSpeedMech(encHandle) * (float_t)USER_MOTOR_NUM_POLE_PAIRS;
939  }
940 
941  // reset the isr count
942  CTRL_resetCounter_isr(ctrlHandle);
943 
944 
945 
946 
947  // setup the angle inputs for the encoder module
948  ENC_setupAngle(encHandle,posCntReg);
949  // calculate the angles
950  ENC_runAngle(encHandle);
951 
952 
953  // Initialize the QEP to the rotor's magnetic north pole
954  if(ENC_CAL_isEnabled(enc_calHandle))
955  {
956  QEP_clear_posn_counter(hal.qepHandle[0]);
957  angleElec_rad = ENC_CAL_getInitAngle(enc_calHandle);
958  Idq_offset_A.value[0] = ENC_CAL_getIdCurrent(enc_calHandle);
959  Idq_offset_A.value[1] = 0.0;
960 
961  flag_doSpeedCtrl = false;
962 
963  ENC_CAL_run(enc_calHandle);
964  }
965  else
966  {
967  // set the Idq offset values during normal operation
968  Idq_offset_A.value[0] = gId_A;
969  Idq_offset_A.value[1] = gIq_A;
970 
971  flag_doSpeedCtrl = gFlag_runInSpeedMode;
972 
973  // get the angle for t = n+1
974  angleElec_rad = ENC_getAngleElec(encHandle);
975  angleMech_rad = ENC_getAngleMech(encHandle);
976  }
977 
978  // set the Vdq offset values
979  Vdq_offset_V.value[0] = 0.0;
980  Vdq_offset_V.value[1] = 0.0;
981 
982 
983  // compute the sin/cos phasor
984  CTRL_computePhasor(angleElec_rad,&phasor);
985 
986 
987  // set the phasor in the Park transform
988  PARK_setPhasor(parkHandle,&phasor);
989 
990 
991  // run the Park transform
992  PARK_run(parkHandle,&Iab_in_A,&Idq_A);
993 
994  // set the maximum torque of the speed control
997 
998  // setup the controller
999  CTRL_setup(ctrlHandle,
1000  speed_ref_Hz,
1001  speed_Hz,
1002  &Idq_A,
1003  &Idq_offset_A,
1004  &Vdq_offset_V,
1005  flag_doSpeedCtrl,
1006  flag_doCurrentCtrl,
1007  flag_useZeroIq_ref);
1008 
1009 
1010  // run the controller
1011  CTRL_run(ctrlHandle,&Vdq_out_V);
1012 
1013 
1014  // store the Idq reference values used by the controller
1016 
1017 
1018  // get the angle estimate for time t = n+1+delay
1019  angleWithDelay_rad = angleElec_rad;
1020 
1021 
1022  // compute the sin/cos phasor
1023  CTRL_computePhasor(angleWithDelay_rad,&phasor);
1024 
1025 
1026  // set the phasor in the inverse Park transform
1027  IPARK_setPhasor(iparkHandle,&phasor);
1028 
1029 
1030  // run the inverse Park module
1031  IPARK_run(iparkHandle,&Vdq_out_V,&Vab_out_V);
1032 
1033 
1034  // setup the space vector generator (SVGEN) module
1035  SVGEN_setup(svgenHandle,oneOverDcBus_invV);
1036 
1037 
1038  // run the space vector generator (SVGEN) module
1039  SVGEN_run(svgenHandle,&Vab_out_V,&(gPwmData.Vabc_pu));
1040 
1041  }
1042  }
1043  else
1044  {
1045  // create PWM data
1046  gPwmData.Vabc_pu.value[0] = 0.0;
1047  gPwmData.Vabc_pu.value[1] = 0.0;
1048  gPwmData.Vabc_pu.value[2] = 0.0;
1049  }
1050 
1051 
1052  // write the PWM compare values
1053  HAL_writePwmData(halHandle,&gPwmData);
1054 
1055 
1056  // write the DAC data
1057  HAL_writeDacData(halHandle,&gDacData);
1058 
1059 
1060  // turn LED 3 off
1061  HAL_turnLedOff(halHandle,(GPIO_Number_e)HAL_Gpio_LED3);
1062 
1063 
1064  gAngle_enc = ENC_getAngleElec(encHandle);
1065 
1066 
1067  if(gAngle_enc > MATH_PI)
1068  {
1070  }
1071  else if(gAngle_enc < (-MATH_PI))
1072  {
1074  }
1075 
1076 
1077  gAngleError = gAngle_enc - ANGLE_getAngle_rad(angleHandle);
1078 
1079 
1080  if(gAngleError > MATH_PI)
1081  {
1083  }
1084  else if(gAngleError < (-MATH_PI))
1085  {
1087  }
1088 
1089 
1090  // store graph value
1092  {
1093  if(Graph_Counter >= GRAPH_SIZE)
1094  {
1095  Graph_Flag_Enable_update = false;
1096  Graph_Counter = 0;
1097  }
1098  else
1099  {
1100  if(Graph_Tick_Counter == 0)
1101  {
1104  Graph_Data3[Graph_Counter] = ANGLE_getAngle_rad(angleHandle) * ((float_t)180.0 / MATH_PI);
1105  Graph_Counter++;
1107  }
1108  else
1109  {
1111  }
1112  }
1113  }
1114 
1115 
1116  // read the timer 1 value and update the CPU usage module
1117  timer1Cnt = HAL_readTimerCnt(halHandle,1);
1118  CPU_USAGE_updateCnts(cpu_usageHandle,timer1Cnt);
1119 
1120 
1121  // run the CPU usage module
1122  CPU_USAGE_run(cpu_usageHandle);
1123 
1124 
1125  return;
1126 } // end of mainISR() function
1127 
1128 
1129 void setupClarke_I(CLARKE_Handle handle,const uint_least8_t numCurrentSensors)
1130 {
1131  float_t alpha_sf,beta_sf;
1132 
1133 
1134  // initialize the Clarke transform module for current
1135  if(numCurrentSensors == 3)
1136  {
1137  alpha_sf = MATH_ONE_OVER_THREE;
1138  beta_sf = MATH_ONE_OVER_SQRT_THREE;
1139  }
1140  else if(numCurrentSensors == 2)
1141  {
1142  alpha_sf = 1.0;
1143  beta_sf = MATH_ONE_OVER_SQRT_THREE;
1144  }
1145  else
1146  {
1147  alpha_sf = 0.0;
1148  beta_sf = 0.0;
1149  }
1150 
1151  // set the parameters
1152  CLARKE_setScaleFactors(handle,alpha_sf,beta_sf);
1153  CLARKE_setNumSensors(handle,numCurrentSensors);
1154 
1155  return;
1156 } // end of setupClarke_I() function
1157 
1158 
1159 void setupClarke_V(CLARKE_Handle handle,const uint_least8_t numVoltageSensors)
1160 {
1161  float_t alpha_sf,beta_sf;
1162 
1163 
1164  // initialize the Clarke transform module for voltage
1165  if(numVoltageSensors == 3)
1166  {
1167  alpha_sf = MATH_ONE_OVER_THREE;
1168  beta_sf = MATH_ONE_OVER_SQRT_THREE;
1169  }
1170  else
1171  {
1172  alpha_sf = 0.0;
1173  beta_sf = 0.0;
1174  }
1175 
1176  // set the parameters
1177  CLARKE_setScaleFactors(handle,alpha_sf,beta_sf);
1178  CLARKE_setNumSensors(handle,numVoltageSensors);
1179 
1180  return;
1181 } // end of setupClarke_V() function
1182 
1183 
1185 {
1186  float_t IdRated_indEst_A = EST_getIdRated_indEst_A(estHandle);
1187 
1188  // get the states
1189  gCalState = CAL_getState(calHandle);
1190  gCtrlState = CTRL_getState(ctrlHandle);
1191  gEstState = EST_getState(estHandle);
1192  gTrajState = EST_getTrajState(estHandle);
1193 
1194  // get R/L
1195  gRoverL_rps = EST_getRoverL_rps(estHandle);
1196 
1197  // get the speed estimate
1198  gSpeed_Hz = EST_getFe_Hz(estHandle);
1199 
1200  // get the torque estimate
1201  gTorque_Nm = EST_computeTorque_Nm(estHandle);
1202 
1203  // get the stator resistance estimate from RsOnLine
1204  gRsOnLine_Ohm = EST_getRsOnLine_Ohm(estHandle);
1205 
1206  // get the alpha stator resistance
1207  gRs_a_Ohm = EST_getRs_a_Ohm(estHandle);
1208 
1209  // get the beta stator resistance
1210  gRs_b_Ohm = EST_getRs_b_Ohm(estHandle);
1211 
1212  // get the direct stator resistance
1213  gRs_d_Ohm = EST_getRs_d_Ohm(estHandle);
1214 
1215  // get the quadrature stator resistance
1216  gRs_q_Ohm = EST_getRs_q_Ohm(estHandle);
1217 
1218  // get the direct rotor resistance
1219  gRr_d_Ohm = EST_getRr_d_Ohm(estHandle);
1220 
1221  // get the quadrature rotor resistance
1222  gRr_q_Ohm = EST_getRr_q_Ohm(estHandle);
1223 
1224  // get the stator inductance in the direct coordinate direction
1225  gLs_d_H = EST_getLs_d_H(estHandle);
1226 
1227  // get the stator inductance in the quadrature coordinate direction
1228  gLs_q_H = EST_getLs_q_H(estHandle);
1229 
1230  // get the magnetizing inductance
1231  gLmag_H = EST_computeLmag_H(estHandle,IdRated_indEst_A);
1232 
1233  // get the IdRated value
1234  gIdRated_A = EST_getIdRated_A(estHandle);
1235 
1236  // get the flux, Wb
1237  gFlux_Wb = EST_getFlux_Wb(estHandle);
1238 
1239  return;
1240 } // end of updateGlobalVariables_motor() function
1241 
1242 
1244 {
1245  uint32_t minDeltaCntObserved = CPU_USAGE_getMinDeltaCntObserved(cpu_usageHandle);
1246  uint32_t avgDeltaCntObserved = CPU_USAGE_getAvgDeltaCntObserved(cpu_usageHandle);
1247  uint32_t maxDeltaCntObserved = CPU_USAGE_getMaxDeltaCntObserved(cpu_usageHandle);
1248  uint16_t pwmPeriod = HAL_readPwmPeriod(halHandle,PWM_Number_1);
1249  float_t cpu_usage_den = (float_t)pwmPeriod * (float_t)USER_NUM_PWM_TICKS_PER_ISR_TICK * 2.0;
1250 
1251  // calculate the minimum cpu usage percentage
1252  gCpuUsagePercentageMin = (float_t)minDeltaCntObserved / cpu_usage_den * 100.0;
1253 
1254  // calculate the average cpu usage percentage
1255  gCpuUsagePercentageAvg = (float_t)avgDeltaCntObserved / cpu_usage_den * 100.0;
1256 
1257  // calculate the maximum cpu usage percentage
1258  gCpuUsagePercentageMax = (float_t)maxDeltaCntObserved / cpu_usage_den * 100.0;
1259 
1260  return;
1261 } // end of updateCPUusage() function
1262 
1263 
1264 // end of file
1265 
1266 
1267 
float_t gCpuUsagePercentageAvg
SVGEN_Obj svgen
the space vector generator object
#define USER_SYSTEM_FREQ_MHz
CLOCKS & TIMERS.
Definition: user.h:140
bool EST_isError(EST_Handle handle)
float_t EST_getRsOnLine_Ohm(EST_Handle handle)
void EST_enableTraj(EST_Handle handle)
void ANGLE_setup(ANGLE_Handle handle, const int_least32_t timeStamp, const float_t angle_rad, const float_t speed_rps, const float_t accel_rps2)
EST_State_e gEstState
Global variable for the estimator state.
Definition: proj_enc_fast.c:53
float_t angleDelayed_sf_sec
HAL_Obj hal
the hardware abstraction layer object
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)
void EST_resetTrajCounter_isr(EST_Handle handle)
EST_Traj_State_e gTrajState
Definition: proj_enc_fast.c:55
EST_Handle estHandle
the handle for the estimator
CPU_USAGE_Obj cpu_usage
void CTRL_incrCounter_isr(CTRL_Handle handle)
volatile float_t gRsOnLineId_mag_A
void HAL_enableGlobalInts(HAL_Handle handle)
void HAL_enableAdcInts(HAL_Handle handle)
bool EST_getFlag_estComplete(EST_Handle handle)
float_t EST_getFlux_Wb(EST_Handle handle)
static float_t CTRL_getCurrentCtrlPeriod_sec(CTRL_Handle handle)
void EST_incrTrajCounter_isr(EST_Handle handle)
void EST_setRsOnLineId_mag_A(EST_Handle handle, const float_t Id_mag_A)
void CTRL_run(CTRL_Handle handle, HAL_Handle halHandle, const HAL_AdcData_t *pAdcData, HAL_PwmData_t *pPwmData)
EST_OutputData_t gEstOutputData[NUM_EST_DATA_BUFFERS]
uint16_t Graph_Tick_Counter
MATH_vec3 Vabc_pu
void calcGains(CTRL_Handle handle, EST_Handle estHandle)
Calculates controller gains.
float_t EST_getRr_q_Ohm(EST_Handle handle)
static void CAL_run(CAL_Handle handle, const HAL_AdcData_t *pAdcData)
float_t gLs_d_H
Global variable for the stator inductance in the direct coordinate direction, Henry.
Definition: proj_enc_fast.c:91
PARK_Handle parkHandle
the handle for the Park object
static void PARK_setPhasor(PARK_Handle handle, const MATH_vec2 *pPhasor)
QUEUE_Handle QUEUE_init(void *pMemory, const size_t numBytes)
volatile bool gFlag_updateRs
Definition: proj_enc_fast.c:75
float_t gRs_b_Ohm
Global variable for the stator resistance in the beta coordinate direction, Ohm.
int_least32_t timeStamp
float_t EST_getRoverL_rps(EST_Handle handle)
float_t gIdRated_A
Global variable for the rated Id current current, A.
Definition: proj_enc_fast.c:89
void ANGLE_run(ANGLE_Handle handle, const int_least32_t timeStamp)
CAL_Obj cal
the calibrator object
float_t gRoverL_rps
Global variable for the R/L value used for the current controller.
Definition: proj_enc_fast.c:97
#define USER_EST_FREQ_Hz
Defines the estimator frequency, Hz.
Definition: user.h:219
int_least16_t EST_getCount_isr(EST_Handle handle)
static void HAL_writePwmData(HAL_Handle handle, HAL_PwmData_t *pPwmData)
bool EST_isOnLine(EST_Handle handle)
#define MATH_TWO_PI
static float_t CTRL_getBWc_rps(CTRL_Handle handle)
_iq value[3]
float_t ctrlPeriod_sec
struct _EST_Obj_ * EST_Handle
void HAL_writeDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
bool CTRL_isError(CTRL_Handle handle)
CTRL_Obj ctrl[CTRL_NUM_CONTROLLERS]
the controller object
uint_least16_t CTRL_getNumIsrTicksPerCtrlTick(CTRL_Handle handle)
void EST_incrCounter_isr(EST_Handle handle)
float_t Graph_Data3[GRAPH_SIZE]
volatile bool gFlag_enableRsRecalc
Definition: proj_enc_fast.c:73
float_t gRs_d_Ohm
Global variable for the stator resistance in the direct coordinate direction, Ohm.
#define GRAPH_SIZE
static void HAL_acqAdcInt(HAL_Handle handle, const ADC_IntNumber_e intNumber)
float_t EST_getRr_d_Ohm(EST_Handle handle)
static void CTRL_setSpeed_outMax_A(CTRL_Handle handle, const float_t speed_outMax_A)
void * arg[EVENT_MAX_NUM_ARGS]
static void CAL_setFlag_enableAdcOffset(CAL_Handle handle, const bool value)
float_t gCpuUsagePercentageMin
uint_least8_t numCurrentSensors
IPARK_Handle iparkHandle
the handle for the inverse Park transform
#define USER_MOTOR_NUM_POLE_PAIRS
Definition: user.h:398
bool EST_isEnabled(EST_Handle handle)
volatile bool gflag_configCtrl_once
void EST_setupTraj(EST_Handle handle, CTRL_Handle ctrlHandle, const float_t targetValue_spd_Hz, const float_t targetValue_Id_A)
void CAL_setParams(CAL_Handle handle, const USER_Params *pUserParams)
ENC_CAL_Obj enc_cal
the encoder calibration object
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)
static MATH_vec2 * CTRL_getIdq_ref_A_addr(CTRL_Handle handle)
static status QUEUE_postEventLast(QUEUE_Handle handle, const EVENT_Fxn eventFxn, const EVENT_ArgList *pArgList, const uint_least8_t numArgs)
void EST_configureTraj(EST_Handle handle)
#define MATH_PI
volatile float_t gSpeed_Kp
#define MATH_ONE_OVER_THREE
CAL_Handle calHandle
the handle for the calibrator
void USER_setParams(USER_Params *pUserParams)
Sets the user parameter values.
uint_least16_t CTRL_getCount_isr(CTRL_Handle handle)
void setupClarke_V(CLARKE_Handle handle, const uint_least8_t numVoltageSensors)
Sets the number of voltage sensors.
uint16_t Graph_Counter
void EST_setFlag_updateRs(EST_Handle handle, const bool state)
float_t gSpeed_ref_traj
float_t EST_computeTorque_Nm(EST_Handle handle)
bool EST_isTrajEnabled(EST_Handle handle)
void CTRL_setGains(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Kp, const _iq Ki, const _iq Kd)
float_t speed_ref_Hz
CLARKE_Obj clarke_V
the voltage Clarke transform object
static void CLARKE_setScaleFactors(CLARKE_Handle handle, const _iq alpha_sf, const _iq beta_sf)
CAL_State_e
void EST_enable(EST_Handle handle)
CTRL_Handle CTRL_init(void *pMemory, const size_t numBytes)
static void incrCount_isr(void)
Increments the ISR counter.
Definition: float/main.h:214
void HAL_setupFaults(HAL_Handle handle)
IPARK_Obj ipark
the inverse Park transform object
float_t EST_getLs_d_H(EST_Handle handle)
ENC_CAL_State_e gEncCalState
Definition: proj_enc_fast.c:51
void EST_setFlag_enableRsRecalc(EST_Handle handle, const bool state)
USER_Params gUserParams
The user parameters.
void updateCPUusage(CTRL_Handle handle)
Updates CPU usage.
static void incrBufferIndex_est(void)
Increments the estimation buffer index.
Definition: float/main.h:232
static void HAL_enablePwm(HAL_Handle handle)
void EST_configureCtrl(EST_Handle handle, CTRL_Handle ctrlHandle)
CTRL_Version gVersion
Global variable for the controller version.
void CTRL_setParams(CTRL_Handle handle, USER_Params *pUserParams)
void EST_setFlag_enablePowerWarp(EST_Handle handle, const bool state)
MOTOR_Type_e motor_type
EST_State_e
QUEUE_Obj queue
the queue object
int_least32_t gCounter_isr
A counter that is incremented by each call to the mainISR() function.
Definition: proj_enc_fast.c:43
CLARKE_Handle clarkeHandle_V
the handle for the voltage Clarke transform
void HAL_enableDrv(HAL_Handle handle)
void CTRL_resetCounter_isr(CTRL_Handle handle)
_iq value[2]
CAL_State_e gCalState
Definition: proj_enc_fast.c:47
void main(void)
EST_Handle EST_initEst(const uint_least8_t estNumber)
ANGLE_Handle ANGLE_init(void *pMemory, const size_t numBytes)
volatile bool gFlag_enableRsOnLine
Definition: proj_enc_fast.c:71
uint_least32_t trajFreq_Hz
float_t EST_getIdRated_A(EST_Handle handle)
void HAL_setupDrvSpi(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
volatile bool gFlag_enablePowerWarp
Definition: proj_enc_fast.c:67
uint_least8_t numVoltageSensors
float_t EST_getLs_q_H(EST_Handle handle)
EST_Traj_State_e
void HAL_enableDebugInt(HAL_Handle handle)
volatile float_t gRsOnLineFreq_Hz
CLARKE_Handle CLARKE_init(void *pMemory, const size_t numBytes)
int_least32_t gCounter_main
A counter that is incremented by each iteration of the main() function.
Definition: proj_enc_fast.c:45
void EST_disableTraj(EST_Handle handle)
CTRL_State_e CTRL_getState(CTRL_Handle handle)
volatile bool gFlag_runEncCal
Definition: proj_enc_fast.c:77
uint_least16_t gBufferIndex_setup
A counter that to denote the buffer index for the setup.
Definition: proj_enc_fast.c:83
static void IPARK_run(IPARK_Handle handle, const MATH_vec2 *pInVec, MATH_vec2 *pOutVec)
ENC_Handle ENC_init(void *pMemory, const size_t numBytes)
float_t EST_getRs_b_Ohm(EST_Handle handle)
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.
void CTRL_setup(CTRL_Handle handle)
void EST_setFlag_estComplete(EST_Handle handle, const bool state)
volatile bool gFlag_runInSpeedMode
Definition: proj_enc_fast.c:79
HAL_DacData_t gDacData
Defines the DAC data.
CTRL_State_e
float_t gLs_q_H
Global variable for the stator inductance in the quadrature coordinate direction, Henry...
Definition: proj_enc_fast.c:93
volatile uint16_t Graph_Tick_Counter_Value
float_t gRs_a_Ohm
Global variable for the stator resistance in the alpha coordinate direction, Ohm. ...
float_t EST_getRs_a_Ohm(EST_Handle handle)
static bool CTRL_isEnabled(CTRL_Handle handle)
float_t gSpeed_Hz
float_t gIq_A
void EST_setFlag_enableRsOnLine(EST_Handle handle, const bool state)
float_t gRr_q_Ohm
interrupt void mainISR(void)
The main interrupt service (ISR) routine.
float_t gId_A
float_t gCpuUsagePercentageMax
int_least16_t EST_getNumIsrTicksPerEstTick(EST_Handle handle)
static OFFSET_Handle * CAL_getOffsetHandleAddr_I(CAL_Handle handle)
static uint32_t HAL_readTimerCnt(HAL_Handle handle, const uint_least8_t timerNumber)
void EST_setIdq_ref_A(EST_Handle handle, const MATH_vec2 *pIdq_ref_A)
CPU_USAGE_Handle cpu_usageHandle
static void CLARKE_setNumSensors(CLARKE_Handle handle, const uint_least8_t numSensors)
volatile bool gFlag_enableQueue
Definition: proj_enc_fast.c:69
float_t EST_getRs_Ohm(EST_Handle handle)
float_t EST_computeLmag_H(EST_Handle handle, const float_t current_A)
float_t gRr_d_Ohm
Global variable for the rotor resistance in the direct coordinate direction, Ohm. ...
float_t gAngle_enc
float_t EST_getRs_q_Ohm(EST_Handle handle)
void updateGlobalVariables_motor(CTRL_Handle ctrlHandle, EST_Handle estHandle)
Updates the global motor variables.
void ANGLE_setParams(ANGLE_Handle handle, const float_t timeStampPeriod_sec, const float_t angleDelayed_sf_sec)
void CPU_USAGE_setParams(CPU_USAGE_Handle handle, const uint32_t timerPeriod_cnts, const uint32_t numDeltaCntsAvg)
void EST_runTraj(EST_Handle handle)
static bool CAL_isError(CAL_Handle handle)
#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)
ENC_Obj enc
the encoder object
CPU_USAGE_Handle CPU_USAGE_init(void *pMemory, const size_t numBytes)
volatile float_t gRsOnLinePole_Hz
float_t gRs_q_Ohm
Global variable for the stator resistance in the quadrature coordinate direction, Ohm...
static void HAL_disablePwm(HAL_Handle handle)
void EST_setRsOnLineAngleDelta_rad(EST_Handle handle, const float_t angleDelta_rad)
bool EST_isMotorIdentified(EST_Handle handle)
ENC_Handle encHandle
the handle for the encoder
float_t Graph_Data2[GRAPH_SIZE]
float_t EST_getRs_d_Ohm(EST_Handle handle)
HAL_Handle HAL_init(void *pMemory, const size_t numBytes)
bool EST_isLockRotor(EST_Handle handle)
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)
static void PARK_run(PARK_Handle handle, const MATH_vec2 *pInVec, MATH_vec2 *pOutVec)
volatile float_t gSpeed_Ki
static CAL_State_e CAL_getState(CAL_Handle handle)
static void CTRL_setSpeed_outMin_A(CTRL_Handle handle, const float_t speed_outMin_A)
float_t Graph_Data1[GRAPH_SIZE]
float_t gFlux_Wb
Global variable for the rotor flux estimate, Wb.
Definition: proj_enc_fast.c:85
#define NUM_EST_DATA_BUFFERS
Defines the number of estimator data buffers NOTE: Must be a multiple of two.
Definition: float/main.h:43
MATH_vec2 Iab_A
void(* EVENT_Fxn)()
static void HAL_readAdcData(HAL_Handle handle, HAL_AdcData_t *pAdcData)
CAL_Handle CAL_init(void *pMemory, const size_t numBytes)
#define USER_TRAJ_FREQ_Hz
Defines the trajectory frequency, Hz.
Definition: user.h:223
void SVGEN_setup(SVGEN_Handle svgenHandle)
QUEUE_Handle queueHandle
the handle for the queue
float_t gAngleError
uint_least16_t gBufferIndex_est
A counter that to denote the buffer index for the estimation.
Definition: proj_enc_fast.c:81
ENC_CAL_Handle enc_calHandle
the handle for the encoder calibration
CTRL_Handle ctrlHandle
the handle for the controller
PARK_Obj park
the Park transform object
bool EST_isIdle(EST_Handle handle)
volatile bool gFlag_bypassLockRotor
Definition: proj_enc_fast.c:57
static void CPU_USAGE_updateCnts(CPU_USAGE_Handle handle, const uint32_t cnt)
volatile bool gFlag_enableSys
Global flag to enable/disable the system.
Definition: proj_enc_fast.c:59
MATH_vec2 Vab_V
static uint32_t CPU_USAGE_getMinDeltaCntObserved(CPU_USAGE_Handle handle)
#define MATH_ONE_OVER_SQRT_THREE
bool EST_isTrajError(EST_Handle handle)
EST_Traj_State_e EST_getTrajState(EST_Handle handle)
float_t gLmag_H
Global variable for the magnetizing inductance, Henry.
Definition: proj_enc_fast.c:95
static void HAL_initIntVectorTable(HAL_Handle handle)
float_t gId_trajTarget_A
Definition: proj_enc_fast.c:87
#define HAL_turnLedOff
static void QUEUE_executeEvent(QUEUE_Handle handle)
static void HAL_updateAdcBias(HAL_Handle handle)
PARK_Handle PARK_init(void *pMemory, const size_t numBytes)
float_t EST_getIdRated_indEst_A(EST_Handle handle)
void CTRL_getVersion(CTRL_Handle handle, CTRL_Version *pVersion)
static uint16_t HAL_readPwmPeriod(HAL_Handle handle, const PWM_Number_e pwmNumber)
HAL_PwmData_t gPwmData
Defines the PWM data.
static bool QUEUE_isEvent(QUEUE_Handle handle)
static void CTRL_enable(CTRL_Handle handle)
bool EST_updateState(EST_Handle handle, const _iq Id_target_pu)
static void CTRL_disable(CTRL_Handle handle)
void CTRL_computePhasor(const _iq angle_pu, MATH_vec2 *pPhasor)
#define CTRL_NUM_CONTROLLERS
#define HAL_turnLedOn
void EST_disable(EST_Handle handle)
float_t gSpeed_ref_Hz
void HAL_setParams(HAL_Handle handle, const USER_Params *pUserParams)
static void CPU_USAGE_run(CPU_USAGE_Handle handle)
CLARKE_Handle clarkeHandle_I
the handle for the current Clarke transform
volatile bool gFlag_runCal
Definition: proj_enc_fast.c:61
bool CAL_updateState(CAL_Handle handle)
HAL_AdcData_t gAdcData
Defines the ADC data.
CTRL_State_e gCtrlState
Global variable for the controller state.
Definition: proj_enc_fast.c:49
float_t EST_getFe_Hz(EST_Handle handle)
void HAL_readDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
static bool CAL_isEnabled(CAL_Handle handle)
static float_t ANGLE_getAngle_rad(ANGLE_Handle handle)
ANGLE_Handle angleHandle
the handle for the angle generator
CLARKE_Obj clarke_I
the current Clarke transform object
float_t gRsOnLine_Ohm
Definition: proj_enc_fast.c:99
float_t gTorque_Nm
Global variable for the estimated torque, N*m.
static void incrBufferIndex_setup(void)
Increments the setup buffer index.
Definition: float/main.h:243
EST_InputData_t gEstInputData[NUM_EST_DATA_BUFFERS]
static void HAL_writeDacData(HAL_Handle handle, HAL_DacData_t *pDacData)
volatile bool gFlag_enableForceAngle
Definition: proj_enc_fast.c:65
float_t gSpeedOutMax_A
void EST_resetCounter_isr(EST_Handle handle)
volatile bool Graph_Flag_Enable_update
SVGEN_Handle SVGEN_init(void *pMemory, const size_t numBytes)
bool EST_updateTrajState(EST_Handle handle)
GPIO_Number_e
int_least32_t gCounter_enableSys
A counter that is incremented while waiting for the enable system flag to be set. ...
Definition: proj_enc_fast.c:41
void EST_setFlag_bypassLockRotor(EST_Handle handle, const bool state)
SVGEN_Handle svgenHandle
the handle for the space vector generator
float_t gMaxCurrentSlope
float float_t
ANGLE_Obj angle
the angle object
static OFFSET_Handle * CAL_getOffsetHandleAddr_V(CAL_Handle handle)
int_least16_t EST_getNumIsrTicksPerTrajTick(EST_Handle handle)
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
int_least16_t EST_getTrajCount_isr(EST_Handle handle)
volatile bool gFlag_runIdentAndOnLine
Definition: proj_enc_fast.c:63