instaspin_foc
proj_lab21.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2012, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
36 
38 
39 
44 
45 // **************************************************************************
46 // the includes
47 
48 // system includes
49 #include <math.h>
50 #include "main.h"
51 
55 
56 #ifdef FLASH
57 #pragma CODE_SECTION(mainISR,"ramfuncs");
58 #endif
59 
60 // Include header files used in the main function
61 
62 
63 // **************************************************************************
64 // the defines
65 
66 
67 #define LED_BLINK_FREQ_Hz 5
68 
69 
70 // **************************************************************************
71 // the globals
72 
73 uint_least16_t gCounter_updateGlobals = 0;
74 
76 
80 
83 
86 
88 
91 
94 
97 
99 
101 
103 
106 
108 
110 
111 HAL_PwmData_t gPwmData = {_IQ(0.0), _IQ(0.0), _IQ(0.0)};
112 
114 
116 
117 #ifdef FAST_ROM_V1p6
119 #else
120 CTRL_Obj ctrl; //v1p7 format
121 #endif
122 
123 uint16_t gLEDcnt = 0;
124 
126 
127 #ifdef FLASH
128 // Used for running BackGround in flash, and ISR in RAM
129 extern uint16_t *RamfuncsLoadStart, *RamfuncsLoadEnd, *RamfuncsRunStart;
130 #endif
131 
132 
133 #ifdef DRV8301_SPI
134 // Watch window interface to the 8301 SPI
135 DRV_SPI_8301_Vars_t gDrvSpi8301Vars;
136 #endif
137 
139 
141 
143 
145 
146 _iq gUi = _IQ(0.0);
148 
149 bool flag_update_ipd = false;
150 
151 
152 // **************************************************************************
153 // the functions
154 
155 void main(void)
156 {
157  uint_least8_t estNumber = 0;
158 
159 #ifdef FAST_ROM_V1p6
160  uint_least8_t ctrlNumber = 0;
161 #endif
162 
163  // Only used if running from FLASH
164  // Note that the variable FLASH is defined by the project
165  #ifdef FLASH
166  // Copy time critical code and Flash setup code to RAM
167  // The RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart
168  // symbols are created by the linker. Refer to the linker files.
169  memCopy((uint16_t *)&RamfuncsLoadStart,(uint16_t *)&RamfuncsLoadEnd,(uint16_t *)&RamfuncsRunStart);
170  #endif
171 
172  // initialize the hardware abstraction layer
173  halHandle = HAL_init(&hal,sizeof(hal));
174 
175 
176  // check for errors in user parameters
177  USER_checkForErrors(&gUserParams);
178 
179 
180  // store user parameter error in global variable
181  gMotorVars.UserErrorCode = USER_getErrorCode(&gUserParams);
182 
183 
184  // do not allow code execution if there is a user parameter error
185  if(gMotorVars.UserErrorCode != USER_ErrorCode_NoError)
186  {
187  for(;;)
188  {
189  gMotorVars.Flag_enableSys = false;
190  }
191  }
192 
193 
194  // initialize the user parameters
195  USER_setParams(&gUserParams);
196 
197 
198  // set the hardware abstraction layer parameters
199  HAL_setParams(halHandle,&gUserParams);
200 
201 
202  // initialize the controller
203 #ifdef FAST_ROM_V1p6
204  ctrlHandle = CTRL_initCtrl(ctrlNumber, estNumber); //v1p6 format (06xF and 06xM devices)
205  controller_obj = (CTRL_Obj *)ctrlHandle;
206 #else
207  ctrlHandle = CTRL_initCtrl(estNumber,&ctrl,sizeof(ctrl)); //v1p7 format default
208 #endif
209 
210 
211  {
212  CTRL_Version version;
213 
214  // get the version number
215  CTRL_getVersion(ctrlHandle,&version);
216 
217  gMotorVars.CtrlVersion = version;
218  }
219 
220 
221  // set the default controller parameters
222  CTRL_setParams(ctrlHandle,&gUserParams);
223 
224 
225  // initialize the Clarke modules
226  clarkeHandle_I = CLARKE_init(&clarke_I,sizeof(clarke_I));
227  clarkeHandle_V = CLARKE_init(&clarke_V,sizeof(clarke_V));
228 
229 
230  // set the number of current sensors
231  setupClarke_I(clarkeHandle_I,gUserParams.numCurrentSensors);
232 
233 
234  // set the number of voltage sensors
235  setupClarke_V(clarkeHandle_V,gUserParams.numVoltageSensors);
236 
237 
238 #ifdef FAST_ROM_V1p6
239  estHandle = controller_obj->estHandle;
240 #else
241  estHandle = ctrl.estHandle;
242 #endif
243 
244 
245  // initialize the inverse Park module
246  iparkHandle = IPARK_init(&ipark,sizeof(ipark));
247 
248 
249  // initialize the Park module
250  parkHandle = PARK_init(&park,sizeof(park));
251 
252 
253  // initialize the space vector generator module
254  svgenHandle = SVGEN_init(&svgen,sizeof(svgen));
255 
256 
257  trajHandle_Iq = TRAJ_init(&traj_Iq,sizeof(traj_Iq));
258  TRAJ_setMaxValue(trajHandle_Iq,_IQ(1.0));
259  TRAJ_setMinValue(trajHandle_Iq,_IQ(0.0));
260  TRAJ_setIntValue(trajHandle_Iq,_IQ(0.0));
261  TRAJ_setMaxDelta(trajHandle_Iq,_IQ((float)(1.0/0.5/15.0e3)));
262 
263 
264  // initialize the IPD module library file
266 
267 
268  // Set the IPD_HFI parameters
270  USER_ISR_FREQ_Hz, // estimation frequency, Hz
271  IPD_HFI_EXC_FREQ_HZ, // excitation frequency, Hz
272  IPD_HFI_LP_SPD_FILT_HZ, // lowpass filter cutoff frequency, Hz
273  IPD_HFI_HP_IQ_FILT_HZ, // highpass filter cutoff frequency, Hz
274  gUserParams.iqFullScaleFreq_Hz, // IQ full scale frequency, Hz
275  IPD_HFI_KSPD, // the speed gain value
276  IPD_HFI_EXC_MAG_COARSE_PU, // coarse IPD excitation magnitude, pu
277  IPD_HFI_EXC_MAG_FINE_PU, // fine IPD excitation magnitude, pu
278  IPD_HFI_EXC_TIME_COARSE_S, // coarse wait time, sec max 0.64
279  IPD_HFI_EXC_TIME_FINE_S); // fine wait time, sec max 0.4
280 
281  // Initialize the global motor variables
282  gMotorVars.ipd_excFreq_Hz = IPD_HFI_EXC_FREQ_HZ;
283  gMotorVars.ipd_Kspd = _IQ(IPD_HFI_KSPD);
284  gMotorVars.ipd_excMag_coarse_pu = _IQ(IPD_HFI_EXC_MAG_COARSE_PU);
285  gMotorVars.ipd_excMag_fine_pu = _IQ(IPD_HFI_EXC_MAG_FINE_PU);
286  gMotorVars.ipd_waitTime_coarse_sec = IPD_HFI_EXC_TIME_COARSE_S;
287  gMotorVars.ipd_waitTime_fine_sec = IPD_HFI_EXC_TIME_FINE_S;
288 
289 
291 
292  // Set the AFSEL parameters
294  AFSEL_MAX_IQ_REF_HFI,
295  AFSEL_MAX_IQ_REF_EST,
296  AFSEL_IQ_SLOPE_HFI,
297  AFSEL_IQ_SLOPE_EST,
298  AFSEL_FREQ_LOW_PU,
299  AFSEL_FREQ_HIGH_PU,
300  ipdHandle,
301  estHandle);
302 
303 
304 // gFlux_pu_VpHz_sf = USER_computeFlux_pu_to_VpHz_sf();
305 
306 
307  // initialize the Flying Start module
309 
310  {
311  float_t maxFlux_VpHz = (USER_MOTOR_RATED_FLUX*((USER_MOTOR_TYPE==MOTOR_Type_Induction)?0.05:0.7));
312 
313 
318  maxFlux_VpHz);
319  }
320 
321  // disable the forced angle flag
322  gMotorVars.Flag_enableForceAngle = false;
323 
324 
325  // setup faults
326  HAL_setupFaults(halHandle);
327 
328 
329  // initialize the interrupt vector table
330  HAL_initIntVectorTable(halHandle);
331 
332 
333  // enable the ADC interrupts
334  HAL_enableAdcInts(halHandle);
335 
336 
337  // enable global interrupts
338  HAL_enableGlobalInts(halHandle);
339 
340 
341  // enable debug interrupts
342  HAL_enableDebugInt(halHandle);
343 
344 
345  // disable the PWM
346  HAL_disablePwm(halHandle);
347 
348 
349 #ifdef DRV8301_SPI
350  // turn on the DRV8301 if present
351  HAL_enableDrv(halHandle);
352  // initialize the DRV8301 interface
353  HAL_setupDrvSpi(halHandle,&gDrvSpi8301Vars);
354 #endif
355 
356 
357  // enable DC bus compensation
358  CTRL_setFlag_enableDcBusComp(ctrlHandle, true);
359 
360 
361  // compute scaling factors for flux and torque calculations
366 
367 
368  for(;;)
369  {
370  // Waiting for enable system flag to be set
371  while(!(gMotorVars.Flag_enableSys));
372 
373  // Enable the Library internal PI. Iq is referenced by the speed PI now
374  CTRL_setFlag_enableSpeedCtrl(ctrlHandle, true);
375 
376  // loop while the enable system flag is true
377  while(gMotorVars.Flag_enableSys)
378  {
379  CTRL_Obj *obj = (CTRL_Obj *)ctrlHandle;
380 
381  // increment counters
383 
384  // enable/disable the use of motor parameters being loaded from user.h
386 
387  // enable/disable Rs recalibration during motor startup
389 
390  // enable/disable automatic calculation of bias values
391  CTRL_setFlag_enableOffset(ctrlHandle,gMotorVars.Flag_enableOffsetcalc);
392 
393 
394  if(CTRL_isError(ctrlHandle))
395  {
396  // set the enable controller flag to false
397  CTRL_setFlag_enableCtrl(ctrlHandle,false);
398 
399  // set the enable system flag to false
400  gMotorVars.Flag_enableSys = false;
401 
402  // IPD disable
404 
405  // disable the PWM
406  HAL_disablePwm(halHandle);
407  }
408  else
409  {
410  // update the controller state
411  bool flag_ctrlStateChanged = CTRL_updateState(ctrlHandle);
412 
413  // enable or disable the control
414  CTRL_setFlag_enableCtrl(ctrlHandle, gMotorVars.Flag_Run_Identify);
415 
416  if(flag_ctrlStateChanged)
417  {
418  CTRL_State_e ctrlState = CTRL_getState(ctrlHandle);
419 
420  if(ctrlState == CTRL_State_OffLine)
421  {
422  // enable the PWM
423  HAL_enablePwm(halHandle);
424  }
425  else if(ctrlState == CTRL_State_OnLine)
426  {
427  if(gMotorVars.Flag_enableOffsetcalc == true)
428  {
429  uint_least16_t cnt;
430 
431  // update the ADC bias values
432  HAL_updateAdcBias(halHandle);
433 
434  // record the current bias
435  for(cnt=0;cnt<3;cnt++)
436  gAdcBiasI.value[cnt] = HAL_getBias(halHandle,HAL_SensorType_Current,cnt);
437 
438  // record the voltage bias
439  for(cnt=0;cnt<3;cnt++)
440  gAdcBiasV.value[cnt] = HAL_getBias(halHandle,HAL_SensorType_Voltage,cnt);
441 
442  gMotorVars.Flag_enableOffsetcalc = false;
443  }
444  else
445  {
446  uint_least16_t cnt;
447 
448  // set the current bias
449  for(cnt=0;cnt<3;cnt++)
450  HAL_setBias(halHandle,HAL_SensorType_Current,cnt,gAdcBiasI.value[cnt]);
451 
452  // set the voltage bias
453  for(cnt=0;cnt<3;cnt++)
454  HAL_setBias(halHandle,HAL_SensorType_Voltage,cnt,gAdcBiasV.value[cnt]);
455  }
456 
458 
460 
461  // enable the PWM
462  HAL_enablePwm(halHandle);
463  }
464  else if(ctrlState == CTRL_State_Idle)
465  {
466  // disable the PWM
467  HAL_disablePwm(halHandle);
468 
469  // IPD disable
471 
473 
474  gMotorVars.Flag_Run_Identify = false;
475  }
476 
477  if((CTRL_getFlag_enableUserMotorParams(ctrlHandle) == true) &&
478  (ctrlState > CTRL_State_Idle) &&
479  (gMotorVars.CtrlVersion.minor == 6))
480  {
481  // call this function to fix 1p6
482  USER_softwareUpdate1p6(ctrlHandle);
483  }
484  }
485  }
486 
487 
489  {
490  // set the current ramp
492  gMotorVars.Flag_MotorIdentified = true;
493 
494  // set the speed reference
495  CTRL_setSpd_ref_krpm(ctrlHandle,gMotorVars.SpeedRef_krpm);
496 
497  // set the speed acceleration
500  {
502 
503  USER_calcPIgains(ctrlHandle);
504 
505  // initialize the watch window kp and ki current values with pre-calculated values
506  gMotorVars.Kp_Idq = CTRL_getKp(ctrlHandle,CTRL_Type_PID_Id);
507  gMotorVars.Ki_Idq = CTRL_getKi(ctrlHandle,CTRL_Type_PID_Id);
508 
509  // initialize the watch window kp and ki values with pre-calculated values
510  gMotorVars.Kp_spd = CTRL_getKp(ctrlHandle,CTRL_Type_PID_spd);
511  gMotorVars.Ki_spd = CTRL_getKi(ctrlHandle,CTRL_Type_PID_spd);
512  }
513 
514  }
515  else
516  {
518 
519  // the estimator sets the maximum current slope during identification
521  }
522 
523 
524  // when appropriate, update the global variables
526  {
527  // reset the counter
529 
530  updateGlobalVariables_motor(ctrlHandle);
531 
532  // Update the IPD parameters in real time when flag_update_ipd is true
533  if(flag_update_ipd)
534  {
535  {
536  uint_least32_t period = (uint_least32_t)(USER_ISR_FREQ_Hz / (2.0 * gMotorVars.ipd_excFreq_Hz));
537  uint_least32_t Periods[IPD_HFI_TRAJ_State_NumStates] = {0,0};
538 
539  Periods[IPD_HFI_TRAJ_State_Coarse] = period;
540  Periods[IPD_HFI_TRAJ_State_Fine] = period;
541 
543  }
544 
545 
547 
548  {
549  _iq Mags[4] = {0,0,0,0};
550 
551  Mags[IPD_HFI_TRAJ_State_Coarse] = gMotorVars.ipd_excMag_coarse_pu;
552  Mags[IPD_HFI_TRAJ_State_Fine] = gMotorVars.ipd_excMag_fine_pu;
553 
555  }
556 
557  {
558  uint_least32_t coarse_s = (uint_least32_t)(gMotorVars.ipd_waitTime_coarse_sec * USER_ISR_FREQ_Hz);
559  uint_least32_t fine_s = (uint_least32_t)(gMotorVars.ipd_waitTime_fine_sec * USER_ISR_FREQ_Hz);
560  uint_least32_t WaitTimes[5] = {0,0,0,0,0};
561 
562  WaitTimes[IPD_HFI_State_Coarse] = coarse_s;
563  WaitTimes[IPD_HFI_State_Fine] = fine_s;
564 
565  IPD_HFI_setWaitTimes(ipdHandle,WaitTimes);
566  }
567 
568  flag_update_ipd = false;
569  }
570  }
571 
572 
573  // update Kp and Ki gains
574  updateKpKiGains(ctrlHandle);
575 
576 
577  // calculate the throttle position and output as a torque command
578  {
579  _iq IqSlope = AFSEL_getIqSlope(afselHandle);
580  _iq IqMax = AFSEL_getIqMax(afselHandle);
581 
585 
586 
587  // set slope for Iq reference
588  TRAJ_setMaxDelta(trajHandle_Iq, IqSlope);
589  // set maximum Iq reference
590  TRAJ_setMaxValue(trajHandle_Iq, IqMax);
591  // set target Iq reference
592  TRAJ_setTargetValue(trajHandle_Iq, gThrottle_Result);
593  }
594 
595  // enable/disable the forced angle
597 
598  // update the afsel state
600 
601  // update the IPD state
603 
604  // enable or disable power warp
605  CTRL_setFlag_enablePowerWarp(ctrlHandle,gMotorVars.Flag_enablePowerWarp);
606 
607 #ifdef DRV8301_SPI
608  HAL_writeDrvData(halHandle,&gDrvSpi8301Vars);
609 
610  HAL_readDrvData(halHandle,&gDrvSpi8301Vars);
611 #endif
612 
613  } // end of while(gFlag_enableSys) loop
614 
615 
616  // disable the PWM
617  HAL_disablePwm(halHandle);
618 
619  // IPD disable
621 
622  // reset the IPD estimator
625 
626  // set the default controller parameters (Reset the control to re-identify the motor)
627  CTRL_setParams(ctrlHandle,&gUserParams);
628 
629  gMotorVars.Flag_Run_Identify = false;
630 
631  } // end of for(;;) loop
632 
633 } // end of main() function
634 
635 
636 interrupt void mainISR(void)
637 {
638  _iq angle_pu,angle_hfi_pu,angle_est_pu;
639  _iq speed_pu,speed_hfi_pu,speed_est_pu;
640  _iq speed_ref_pu = TRAJ_getIntValue(((CTRL_Obj *)ctrlHandle)->trajHandle_spd);
641  _iq speed_outMax_pu = TRAJ_getIntValue(((CTRL_Obj *)ctrlHandle)->trajHandle_spdMax);
642 
643  MATH_vec2 Iab_pu;
644  MATH_vec2 Vab_pu;
645  MATH_vec2 Vdq_out_pu;
646  MATH_vec2 Vab_out_pu;
647  MATH_vec2 phasor;
648 
649 
650  // toggle status LED
651  if(gLEDcnt++ > (uint_least32_t)(USER_ISR_FREQ_Hz / LED_BLINK_FREQ_Hz))
652  {
653  HAL_toggleLed(halHandle,(GPIO_Number_e)HAL_Gpio_LED2);
654  gLEDcnt = 0;
655  }
656 
657 
658  // acknowledge the ADC interrupt
659  HAL_acqAdcInt(halHandle,ADC_IntNumber_1);
660 
661 
662  // convert the ADC data
663  HAL_readAdcData(halHandle,&gAdcData);
664 
665  {
666  uint_least16_t count_isr = CTRL_getCount_isr(ctrlHandle);
667  uint_least16_t numIsrTicksPerCtrlTick = CTRL_getNumIsrTicksPerCtrlTick(ctrlHandle);
668 
669  // if needed, run the controller
670  if(count_isr >= numIsrTicksPerCtrlTick)
671  {
672  CTRL_State_e ctrlState = CTRL_getState(ctrlHandle);
673 
674  bool flag_enableSpeedCtrl;
675  bool flag_enableCurrentCtrl;
676 
677  MATH_vec2 Idq_offset_pu;
678  MATH_vec2 Vdq_offset_pu;
679 
680  // reset the isr count
681  CTRL_resetCounter_isr(ctrlHandle);
682 
683  // run Clarke transform on current
684  CLARKE_run(clarkeHandle_I,&gAdcData.I,&Iab_pu);
685 
686  // run Clarke transform on voltage
687  CLARKE_run(clarkeHandle_V,&gAdcData.V,&Vab_pu);
688 
689  {
690  // run the estimator
691  EST_run(estHandle, \
692  &Iab_pu, \
693  &Vab_pu, \
694  gAdcData.dcBus, \
695  speed_ref_pu);
696  }
697 
698 
699  // run IPD-HFI
701  {
702  // run the IPD algorithm
703  IPD_HFI_run(ipdHandle,&Iab_pu);
704 
705  // set the Vdq bias
706  Vdq_offset_pu.value[0] = IPD_HFI_getVdValue(ipdHandle);
707  Vdq_offset_pu.value[1] = _IQ(0.0);
708 
709  // get the reference angle and frequency values
710  angle_pu = IPD_HFI_getAngle_pu(ipdHandle);
711  speed_pu = IPD_HFI_getSpeed_lp_pu(ipdHandle);
712  }
713  else
714  {
715  // zero the Vdq bias
716  Vdq_offset_pu.value[0] = _IQ(0.0);
717  Vdq_offset_pu.value[1] = _IQ(0.0);
718 
719  // get the estimator angle and frequency values
720  angle_pu = EST_getAngle_pu(estHandle);
721  speed_pu = EST_getFm_pu(estHandle);
722  }
723 
724 
726  {
727  // get the reference angle and frequency values
728  angle_hfi_pu = IPD_HFI_getAngle_pu(ipdHandle);
729  speed_hfi_pu = IPD_HFI_getSpeed_lp_pu(ipdHandle);
730 
731  // get the estimator angle and frequency values
732  angle_est_pu = EST_getAngle_pu(estHandle);
733  speed_est_pu = EST_getFm_pu(estHandle);
734 
735  // setup the angle/frequency selector
737  angle_hfi_pu,
738  speed_hfi_pu,
739  angle_est_pu,
740  speed_est_pu);
741 
742  // run the angle/frequency selector
744 
745  // get the angle and frequency
746  angle_pu = AFSEL_getAngle_pu(afselHandle);
747  speed_pu = AFSEL_getFreq_pu(afselHandle);
748  }
749 
750  // compute the sin/cos phasor
751  CTRL_computePhasor(angle_pu,&phasor);
752 
753  // set the phasor in the Park transform
754  PARK_setPhasor(parkHandle,&phasor);
755 
756  // run the Park transform
757  PARK_run(parkHandle,&Iab_pu,CTRL_getIdq_in_addr(ctrlHandle));
758 
759  // run the Iq current trajectory
760  TRAJ_run(trajHandle_Iq);
761 
762  // set the offset based on the Id trajectory
763  Idq_offset_pu.value[0] = TRAJ_getIntValue(((CTRL_Obj *)ctrlHandle)->trajHandle_Id);
764  Idq_offset_pu.value[1] = TRAJ_getIntValue(trajHandle_Iq);;
765 
766  flag_enableSpeedCtrl = EST_doSpeedCtrl(estHandle) & gMotorVars.Flag_enableSpeedCtrl;
767  flag_enableCurrentCtrl = EST_doCurrentCtrl(estHandle);
768 
769  CTRL_setup_user(ctrlHandle,
770  angle_pu,
771  speed_ref_pu,
772  speed_pu,
773  speed_outMax_pu,
774  &Idq_offset_pu,
775  &Vdq_offset_pu,
776  flag_enableSpeedCtrl,
777  flag_enableCurrentCtrl);
778 
779  // run the appropriate controller
780  if(ctrlState == CTRL_State_OnLine)
781  {
782  // run the online controller
783  CTRL_runPiOnly(ctrlHandle);
784 
785  // get the controller output
786  CTRL_getVdq_out_pu(ctrlHandle,&Vdq_out_pu);
787 
788  // set the phasor in the inverse Park transform
789  IPARK_setPhasor(iparkHandle,&phasor);
790 
791  // run the inverse Park module
792  IPARK_run(iparkHandle,&Vdq_out_pu,&Vab_out_pu);
793 
794  // run the space Vector Generator (SVGEN) module
795  SVGEN_run(svgenHandle,&Vab_out_pu,&(gPwmData.Tabc));
796  }
797  else if(ctrlState == CTRL_State_OffLine)
798  {
799  // run the offline controller
800  CTRL_runOffLine(ctrlHandle,halHandle,&gAdcData,&gPwmData);
801  }
802  }
803  else
804  {
805  // increment the isr count
806  CTRL_incrCounter_isr(ctrlHandle);
807  }
808  }
809 
810  // write the PWM compare values
811  HAL_writePwmData(halHandle,&gPwmData);
812 
813 
814  return;
815 } // end of mainISR() function
816 
817 
818 void setupClarke_I(CLARKE_Handle handle,const uint_least8_t numCurrentSensors)
819 {
820  _iq alpha_sf,beta_sf;
821 
822 
823  // initialize the Clarke transform module for current
824  if(numCurrentSensors == 3)
825  {
826  alpha_sf = _IQ(MATH_ONE_OVER_THREE);
827  beta_sf = _IQ(MATH_ONE_OVER_SQRT_THREE);
828  }
829  else if(numCurrentSensors == 2)
830  {
831  alpha_sf = _IQ(1.0);
832  beta_sf = _IQ(MATH_ONE_OVER_SQRT_THREE);
833  }
834  else
835  {
836  alpha_sf = _IQ(0.0);
837  beta_sf = _IQ(0.0);
838  }
839 
840  // set the parameters
841  CLARKE_setScaleFactors(handle,alpha_sf,beta_sf);
842  CLARKE_setNumSensors(handle,numCurrentSensors);
843 
844  return;
845 } // end of setupClarke_I() function
846 
847 
848 void setupClarke_V(CLARKE_Handle handle,const uint_least8_t numVoltageSensors)
849 {
850  _iq alpha_sf,beta_sf;
851 
852 
853  // initialize the Clarke transform module for voltage
854  if(numVoltageSensors == 3)
855  {
856  alpha_sf = _IQ(MATH_ONE_OVER_THREE);
857  beta_sf = _IQ(MATH_ONE_OVER_SQRT_THREE);
858  }
859  else
860  {
861  alpha_sf = _IQ(0.0);
862  beta_sf = _IQ(0.0);
863  }
864 
865  // set the parameters
866  CLARKE_setScaleFactors(handle,alpha_sf,beta_sf);
867  CLARKE_setNumSensors(handle,numVoltageSensors);
868 
869  return;
870 } // end of setupClarke_V() function
871 
872 
874 {
875  CTRL_Obj *obj = (CTRL_Obj *)handle;
876 
877  // get the speed estimate
878  gMotorVars.Speed_krpm = EST_getSpeed_krpm(obj->estHandle);
879 
880  // get the real time speed reference coming out of the speed trajectory generator
882 
883  // get the torque estimate
885 
886  // get the magnetizing current
887  gMotorVars.MagnCurr_A = EST_getIdRated(obj->estHandle);
888 
889  // get the rotor resistance
890  gMotorVars.Rr_Ohm = EST_getRr_Ohm(obj->estHandle);
891 
892  // get the stator resistance
893  gMotorVars.Rs_Ohm = EST_getRs_Ohm(obj->estHandle);
894 
895  // get the stator inductance in the direct coordinate direction
896  gMotorVars.Lsd_H = EST_getLs_d_H(obj->estHandle);
897 
898  // get the stator inductance in the quadrature coordinate direction
899  gMotorVars.Lsq_H = EST_getLs_q_H(obj->estHandle);
900 
901  // get the flux in V/Hz in floating point
902  gMotorVars.Flux_VpHz = EST_getFlux_VpHz(obj->estHandle);
903 
904  // get the flux in Wb in fixed point
905  gMotorVars.Flux_Wb = USER_computeFlux(handle, gFlux_pu_to_Wb_sf);
906 
907  // get the controller state
908  gMotorVars.CtrlState = CTRL_getState(handle);
909 
910  // get the estimator state
911  gMotorVars.EstState = EST_getState(obj->estHandle);
912 
913  // Get the DC buss voltage
914  gMotorVars.VdcBus_kV = _IQmpy(gAdcData.dcBus,_IQ(USER_IQ_FULL_SCALE_VOLTAGE_V/1000.0));
915 
916  return;
917 } // end of updateGlobalVariables_motor() function
918 
919 
920 void updateKpKiGains(CTRL_Handle handle)
921 {
922  if((gMotorVars.CtrlState == CTRL_State_OnLine) && (gMotorVars.Flag_MotorIdentified == true) && (Flag_Latch_softwareUpdate == false))
923  {
924  // set the kp and ki speed values from the watch window
925  CTRL_setKp(handle,CTRL_Type_PID_spd,gMotorVars.Kp_spd);
926  CTRL_setKi(handle,CTRL_Type_PID_spd,gMotorVars.Ki_spd);
927 
928  // set the kp and ki current values for Id and Iq from the watch window
929  CTRL_setKp(handle,CTRL_Type_PID_Id,gMotorVars.Kp_Idq);
930  CTRL_setKi(handle,CTRL_Type_PID_Id,gMotorVars.Ki_Idq);
931  CTRL_setKp(handle,CTRL_Type_PID_Iq,gMotorVars.Kp_Idq);
932  CTRL_setKi(handle,CTRL_Type_PID_Iq,gMotorVars.Ki_Idq);
933  }
934 
935  return;
936 } // end of updateKpKiGains() function
937 
938 
940 // end of file
941 
942 
943 
float_t EST_getFlux_VpHz(EST_Handle handle)
void EST_setFlag_enableForceAngle(EST_Handle handle, const bool state)
float ipd_waitTime_fine_sec
Definition: main.h:180
CTRL_Obj ctrl
Defines the CTRL object.
Definition: proj_lab21.c:120
IPARK_Handle iparkHandle
the handle for the inverse Park transform
Definition: proj_lab21.c:89
IPARK_Handle IPARK_init(void *pMemory, const size_t numBytes)
void main(void)
Definition: fast_obs_im.c:119
void CTRL_incrCounter_isr(CTRL_Handle handle)
static void TRAJ_setTargetValue(TRAJ_Handle handle, const _iq targetValue)
struct _FStart_Handle_ * FStart_Handle
#define MAX_ACCEL_KRPMPS_SF
Defines the speed acceleration scale factor.
Definition: float/main.h:37
void HAL_enableGlobalInts(HAL_Handle handle)
void HAL_enableAdcInts(HAL_Handle handle)
USER_ErrorCode_e UserErrorCode
Definition: main.h:150
bool Flag_MotorIdentified
Definition: main.h:138
void updateGlobalVariables_motor(EST_Handle estHandle)
Updates the global motor variables.
Definition: fast_obs_im.c:491
float_t Lsq_H
Definition: main.h:172
uint_least16_t gCounter_updateGlobals
A counter that is denotes when to update the global variables.
Definition: proj_lab21.c:73
_iq USER_computeFlux_pu_to_VpHz_sf(void)
Computes the scale factor needed to convert from per unit to V/Hz.
#define _IQ(A)
static void TRAJ_setMaxDelta(TRAJ_Handle handle, const _iq maxDelta)
_iq gFlux_pu_to_VpHz_sf
Definition: proj_lab21.c:140
bool Flag_Run_Identify
Definition: main.h:137
static void PARK_setPhasor(PARK_Handle handle, const MATH_vec2 *pPhasor)
_iq EST_getSpeed_krpm(EST_Handle handle)
_iq ipd_excMag_coarse_pu
Definition: main.h:177
_iq gTorque_Flux_Iq_pu_to_Nm_sf
Definition: proj_lab21.c:144
CLARKE_Obj clarke_V
the voltage Clarke transform object
Definition: proj_lab21.c:85
static _iq TRAJ_getIntValue(TRAJ_Handle handle)
void AFSEL_run(AFSEL_Handle handle)
void AFSEL_enable(AFSEL_Handle handle)
void CTRL_getVdq_out_pu(CTRL_Handle handle, MATH_vec2 *pVdq_out_pu)
void USER_calcPIgains(CTRL_Handle handle)
Updates Id and Iq PI gains.
CTRL_State_e CtrlState
Definition: main.h:147
#define USER_EST_FREQ_Hz
Defines the estimator frequency, Hz.
Definition: user.h:219
bool Flag_enablePowerWarp
Definition: main.h:144
static void HAL_writePwmData(HAL_Handle handle, HAL_PwmData_t *pPwmData)
#define MATH_TWO_PI
void EST_setMaxCurrentSlope_pu(EST_Handle handle, const _iq maxCurrentSlope_pu)
_iq value[3]
interrupt void mainISR(void)
The main interrupt service (ISR) routine.
Definition: proj_lab20.c:512
_iq FStart_run(FStart_Handle handle, const _iq fm_Hz, const _iq flux_VpHz)
#define NUM_MAIN_TICKS_FOR_GLOBAL_VARIABLE_UPDATE
Defines the number of main iterations before global variables are updated.
Definition: float/main.h:48
CLARKE_Handle clarkeHandle_V
the handle for the voltage Clarke transform
Definition: proj_lab21.c:84
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)
void AFSEL_setParams(AFSEL_Handle handle, const _iq IqMaxLfEst, const _iq IqMaxHfEst, const _iq IqSlopeLfEst, const _iq IqSlopeHfEst, const _iq freqLow_pu, const _iq freqHigh_pu, IPD_HFI_Handle hfiHandle, EST_Handle estHandle)
uint_least16_t CTRL_getNumIsrTicksPerCtrlTick(CTRL_Handle handle)
AFSEL_Handle AFSEL_init(void)
FStart_Handle FStart_init(void)
void USER_softwareUpdate1p6(CTRL_Handle handle)
Recalculates Inductances with the correct Q Format.
static void HAL_acqAdcInt(HAL_Handle handle, const ADC_IntNumber_e intNumber)
_iq EST_get_pu_to_krpm_sf(EST_Handle handle)
_iq AFSEL_getAngle_pu(AFSEL_Handle handle)
TRAJ_Handle trajHandle_spd
the handle for the speed trajectory
#define USER_IQ_FULL_SCALE_VOLTAGE_V
Defines full scale value for the IQ30 variable of Voltage inside the system.
Definition: user.h:88
uint_least8_t numCurrentSensors
void memCopy(uint16_t *srcStartAddr, uint16_t *srcEndAddr, uint16_t *dstAddr)
EST_Handle estHandle
void CTRL_setKi(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Ki)
HAL_AdcData_t gAdcData
Defines the ADC data.
Definition: proj_lab21.c:113
float_t ipd_excFreq_Hz
Definition: main.h:175
bool Flag_enableForceAngle
Definition: main.h:139
_iq ipd_Kspd
Definition: main.h:176
TRAJ_Handle trajHandle_Iq
the trajectory handle for the Iq current reference
Definition: proj_lab21.c:104
static void SVGEN_run(SVGEN_Handle handle, const MATH_vec2 *pVab, MATH_vec3 *pT)
void CTRL_setFlag_enableCtrl(CTRL_Handle handle, const bool state)
void CTRL_setFlag_enableSpeedCtrl(CTRL_Handle handle, const bool state)
void IPD_HFI_disable(IPD_HFI_Handle handle)
void IPD_HFI_setTrajPeriods(IPD_HFI_Handle handle, const uint_least32_t *pPeriods)
long _iq
_iq AFSEL_getIqSlope(AFSEL_Handle handle)
AFSEL_Handle afselHandle
the handle for the afselect general algorithm
Definition: proj_lab21.c:100
MATH_vec2 * CTRL_getIdq_in_addr(CTRL_Handle handle)
void AFSEL_updateState(AFSEL_Handle handle)
#define MATH_ONE_OVER_THREE
void IPD_HFI_setAngle_pu(IPD_HFI_Handle handle, const _iq angle_pu)
void USER_setParams(USER_Params *pUserParams)
Sets the user parameter values.
_iq IPD_HFI_getSpeed_lp_pu(IPD_HFI_Handle handle)
uint_least16_t CTRL_getCount_isr(CTRL_Handle handle)
EST_State_e EstState
Definition: main.h:148
void setupClarke_V(CLARKE_Handle handle, const uint_least8_t numVoltageSensors)
Sets the number of voltage sensors.
Definition: proj_lab21.c:848
void AFSEL_disable(AFSEL_Handle handle)
float_t Rs_Ohm
Definition: main.h:169
#define HAL_toggleLed
_iq IPD_HFI_getVdValue(IPD_HFI_Handle handle)
static void CLARKE_setScaleFactors(CLARKE_Handle handle, const _iq alpha_sf, const _iq beta_sf)
Defines the structures, global initialization, and functions used in MAIN.
void CTRL_setMaxAccel_pu(CTRL_Handle handle, const _iq maxAccel_pu)
_iq USER_computeFlux(CTRL_Handle handle, const _iq sf)
Computes Flux in Wb or V/Hz depending on the scale factor sent as parameter.
TRAJ_Handle TRAJ_init(void *pMemory, const size_t numBytes)
void HAL_setupFaults(HAL_Handle handle)
_iq Kp_Idq
Definition: main.h:185
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)
MATH_vec3 Tabc
static void HAL_enablePwm(HAL_Handle handle)
void CTRL_setParams(CTRL_Handle handle, USER_Params *pUserParams)
#define _IQmpy(A, B)
volatile MOTOR_Vars_t gMotorVars
Definition: proj_lab21.c:125
void IPD_HFI_run(IPD_HFI_Handle handle, const MATH_vec2 *pIab_pu)
USER_ErrorCode_e USER_getErrorCode(USER_Params *pUserParams)
Gets the error code in the user parameters.
void HAL_enableDrv(HAL_Handle handle)
void CTRL_resetCounter_isr(CTRL_Handle handle)
void IPD_HFI_setWaitTimes(IPD_HFI_Handle handle, const uint_least32_t *pWaitTimes)
TRAJ_Handle trajHandle_Id
the handle for the Id trajectory
Definition: fast_obs_im.c:102
_iq value[2]
_iq VdcBus_kV
Definition: main.h:192
bool EST_doSpeedCtrl(EST_Handle handle)
_iq Torque_Nm
Definition: main.h:165
_iq SpeedRef_krpm
Definition: main.h:157
_iq Ki_spd
Definition: main.h:183
_iq EST_getFlux_pu(EST_Handle handle)
#define USER_MOTOR_RATED_FLUX
Definition: user.h:403
IPD_HFI_Handle ipdHandle
the handle for the ipd algorithm
Definition: proj_lab21.c:98
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)
bool CTRL_getFlag_enableUserMotorParams(CTRL_Handle handle)
void HAL_enableDebugInt(HAL_Handle handle)
CLARKE_Handle CLARKE_init(void *pMemory, const size_t numBytes)
PARK_Obj park
the Park transform object
Definition: proj_lab21.c:93
CTRL_State_e CTRL_getState(CTRL_Handle handle)
void IPD_HFI_setParams(IPD_HFI_Handle handle, float_t estFreq_Hz, float_t excFreq_Hz, float_t lpFilterCutOffFreq_Hz, float_t hpFilterCutOffFreq_Hz, float_t iqFullScaleFreq_Hz, float_t Kspd, float_t excMag_coarse_pu, float_t excMag_fine_pu, float_t waitTime_coarse_sec, float_t waitTime_fine_sec)
float_t Flux_VpHz
Definition: main.h:173
static void IPARK_run(IPARK_Handle handle, const MATH_vec2 *pInVec, MATH_vec2 *pOutVec)
bool Flag_enableUserParams
Definition: main.h:142
MATH_vec3 gAdcBiasI
Definition: proj_lab21.c:77
EST_State_e EST_getState(EST_Handle handle)
bool Flag_enableOffsetcalc
Definition: main.h:143
void setupClarke_I(CLARKE_Handle handle, const uint_least8_t numCurrentSensors)
Sets the number of current sensors.
Definition: proj_lab21.c:818
PARK_Handle parkHandle
the handle for the Park object
Definition: proj_lab21.c:92
uint16_t gLEDcnt
Definition: proj_lab21.c:123
_iq EST_getFm_pu(EST_Handle handle)
_iq gThrottle_Result
Definition: proj_lab21.c:147
_iq CTRL_getKp(CTRL_Handle handle, const CTRL_Type_e ctrlType)
#define MOTOR_Vars_INIT
Initialization values of global variables.
Definition: main.h:76
CTRL_State_e
bool Flag_Latch_softwareUpdate
Definition: proj_lab21.c:75
_iq ipd_excMag_fine_pu
Definition: main.h:178
_iq AFSEL_getFreq_pu(AFSEL_Handle handle)
_iq USER_computeTorque_Flux_Iq_pu_to_Nm_sf(void)
Computes the scale factor needed to convert from torque created by flux and Iq, from per unit to Nm...
_iq Speed_krpm
Definition: main.h:160
float_t EST_getIdRated(EST_Handle handle)
bool flag_update_ipd
Definition: proj_lab21.c:149
_iq Ki_Idq
Definition: main.h:186
void CTRL_runOffLine(CTRL_Handle handle, HAL_Handle halHandle, const HAL_AdcData_t *pAdcData, HAL_PwmData_t *pPwmData)
_iq gTorque_Ls_Id_Iq_pu_to_Nm_sf
Definition: proj_lab21.c:142
static void CLARKE_setNumSensors(CLARKE_Handle handle, const uint_least8_t numSensors)
float_t Rr_Ohm
Definition: main.h:168
float_t EST_getRs_Ohm(EST_Handle handle)
CTRL_Handle CTRL_initCtrl(const uint_least8_t estNumber, void *pMemory, const size_t numBytes)
bool Flag_enableSpeedCtrl
Definition: main.h:145
bool AFSEL_isEnabled(AFSEL_Handle handle)
float_t Lsd_H
Definition: main.h:171
bool EST_doCurrentCtrl(EST_Handle handle)
#define USER_IQ_FULL_SCALE_FREQ_Hz
CURRENTS AND VOLTAGES.
Definition: user.h:78
void CTRL_setup_user(CTRL_Handle handle, const _iq angle_pu, const _iq speed_ref_pu, const _iq speed_fb_pu, const _iq speed_outMax_pu, const MATH_vec2 *pIdq_offset_pu, const MATH_vec2 *pVdq_offset_pu, const bool flag_enableSpeedCtrl, const bool flag_enableCurrentCtrl)
HAL_Handle halHandle
The hal handle.
Definition: proj_lab21.c:107
void CTRL_setFlag_enablePowerWarp(CTRL_Handle handle, const bool state)
IPD_HFI_Handle IPD_HFI_init(void)
#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)
_iq IPD_HFI_getAngle_pu(IPD_HFI_Handle handle)
bool CTRL_updateState(CTRL_Handle handle)
_iq EST_getAngle_pu(EST_Handle handle)
_iq CTRL_getKi(CTRL_Handle handle, const CTRL_Type_e ctrlType)
static void HAL_disablePwm(HAL_Handle handle)
void CTRL_runPiOnly(CTRL_Handle handle)
static void TRAJ_setMaxValue(TRAJ_Handle handle, const _iq maxValue)
struct IPD_HFI_Obj * IPD_HFI_Handle
bool EST_isMotorIdentified(EST_Handle handle)
FStart_Handle fstartHandle
the handle for the flying start algorithm
Definition: proj_lab21.c:102
bool IPD_HFI_isEnabled(IPD_HFI_Handle handle)
_iq USER_computeTorque_Nm(CTRL_Handle handle, const _iq torque_Flux_sf, const _iq torque_Ls_sf)
Computes Torque in Nm.
void CTRL_setFlag_enableOffset(CTRL_Handle handle, const bool state)
HAL_Handle HAL_init(void *pMemory, const size_t numBytes)
static void CLARKE_run(CLARKE_Handle handle, const MATH_vec3 *pInVec, MATH_vec2 *pOutVec)
void AFSEL_setup(AFSEL_Handle handle, const _iq angleLf_pu, const _iq freqLf_pu, const _iq angleHf_pu, const _iq freqHf_pu)
static void PARK_run(PARK_Handle handle, const MATH_vec2 *pInVec, MATH_vec2 *pOutVec)
MATH_vec3 gAdcBiasV
Definition: proj_lab21.c:78
void CTRL_setFlag_enableDcBusComp(CTRL_Handle handle, const bool state)
HAL_PwmData_t gPwmData
Defines the PWM data.
Definition: proj_lab21.c:111
_iq gFlux_pu_to_Wb_sf
Definition: proj_lab21.c:138
CTRL_Handle ctrlHandle
The controller handle.
Definition: proj_lab21.c:79
#define USER_MOTOR_TYPE
Definition: user.h:397
SVGEN_Obj svgen
the space vector generator object
Definition: proj_lab21.c:96
_iq gMaxCurrentSlope
Definition: proj_lab21.c:115
float ipd_waitTime_coarse_sec
Definition: main.h:179
_iq EST_getMaxCurrentSlope_pu(EST_Handle handle)
void CTRL_setFlag_enableUserMotorParams(CTRL_Handle handle, const bool state)
_iq SpeedTraj_krpm
Definition: main.h:158
float_t MagnCurr_A
Definition: main.h:167
static void HAL_readAdcData(HAL_Handle handle, HAL_AdcData_t *pAdcData)
HAL_Obj hal
void updateKpKiGains(CTRL_Handle handle)
Updates Kp and Ki gains in the controller object.
Definition: proj_lab20.c:749
static _iq HAL_getBias(HAL_Handle handle, const HAL_SensorType_e sensorType, uint_least8_t sensorNumber)
bool Flag_enableSys
Definition: main.h:136
void IPD_HFI_setKspd_pu(IPD_HFI_Handle handle, const _iq Kspd_pu)
_iq MaxAccel_krpmps
Definition: main.h:159
_iq CTRL_getSpd_int_ref_pu(CTRL_Handle handle)
#define MATH_ONE_OVER_SQRT_THREE
_iq gUi
Definition: proj_lab21.c:146
void IPD_HFI_updateState(IPD_HFI_Handle handle)
bool Flag_enableRsRecalc
Definition: main.h:141
CLARKE_Obj clarke_I
the current Clarke transform object
Definition: proj_lab21.c:82
static void HAL_initIntVectorTable(HAL_Handle handle)
_iq Kp_spd
Definition: main.h:182
static void HAL_setBias(HAL_Handle handle, const HAL_SensorType_e sensorType, uint_least8_t sensorNumber, const _iq bias)
static void HAL_updateAdcBias(HAL_Handle handle)
PARK_Handle PARK_init(void *pMemory, const size_t numBytes)
void CTRL_getVersion(CTRL_Handle handle, CTRL_Version *pVersion)
uint16_t minor
SVGEN_Handle svgenHandle
the handle for the space vector generator
Definition: proj_lab21.c:95
CTRL_Version CtrlVersion
Definition: main.h:152
float_t EST_getRr_Ohm(EST_Handle handle)
void CTRL_computePhasor(const _iq angle_pu, MATH_vec2 *pPhasor)
TRAJ_Obj traj_Iq
the trajectory for Iq current reference
Definition: proj_lab21.c:105
void HAL_setParams(HAL_Handle handle, const USER_Params *pUserParams)
void IPD_HFI_setId_sum(IPD_HFI_Handle handle, const _iq Id_sum_pu)
CLARKE_Handle clarkeHandle_I
the handle for the current Clarke transform
Definition: proj_lab21.c:81
_iq AFSEL_getIqMax(AFSEL_Handle handle)
void HAL_readDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
void IPD_HFI_setTrajMags(IPD_HFI_Handle handle, const _iq *pMags)
static void TRAJ_run(TRAJ_Handle handle)
struct _AFSEL_Obj_ * AFSEL_Handle
void FStart_setParams(FStart_Handle handle, const float_t iqFullScaleVoltage_V, const float_t iqFullScaleFreq_Hz, const float_t estFreq_Hz, const float_t maxFlux_VpHz)
void USER_checkForErrors(USER_Params *pUserParams)
Checks for errors in the user parameter values.
CTRL_Obj * controller_obj
Definition: proj_lab10c.c:84
USER_Params gUserParams
The user parameters.
Definition: proj_lab21.c:109
SVGEN_Handle SVGEN_init(void *pMemory, const size_t numBytes)
_iq Flux_Wb
Definition: main.h:164
EST_Handle estHandle
the handle for the estimator
Definition: proj_lab21.c:87
void IPD_HFI_enable(IPD_HFI_Handle handle)
GPIO_Number_e
_iq USER_computeTorque_Ls_Id_Iq_pu_to_Nm_sf(void)
Computes the scale factor needed to convert from torque created by Ld, Lq, Id and Iq...
IPARK_Obj ipark
the inverse Park transform object
Definition: proj_lab21.c:90
float_t iqFullScaleFreq_Hz
void CTRL_setSpd_ref_krpm(CTRL_Handle handle, const _iq spd_ref_krpm)
_iq USER_computeFlux_pu_to_Wb_sf(void)
Computes the scale factor needed to convert from per unit to Wb.
#define LED_BLINK_FREQ_Hz
Definition: proj_lab21.c:67
void CTRL_setKp(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Kp)
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)