instaspin_foc
proj_lab02c.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 
52 #ifdef FLASH
53 #pragma CODE_SECTION(mainISR,"ramfuncs");
54 #endif
55 
56 // Include header files used in the main function
57 
58 
59 // **************************************************************************
60 // the defines
61 
62 #define LED_BLINK_FREQ_Hz 5
63 
64 
65 // **************************************************************************
66 // the globals
67 
68 uint_least16_t gCounter_updateGlobals = 0;
69 
71 
73 
74 #ifdef F2802xF
75 #pragma DATA_SECTION(halHandle,"rom_accessed_data");
76 #endif
78 
79 #ifdef F2802xF
80 #pragma DATA_SECTION(gUserParams,"rom_accessed_data");
81 #endif
83 
84 HAL_PwmData_t gPwmData = {_IQ(0.0), _IQ(0.0), _IQ(0.0)};
85 
87 
89 
90 #ifdef FAST_ROM_V1p6
92 #else
93 #ifdef F2802xF
94 #pragma DATA_SECTION(ctrl,"rom_accessed_data");
95 #endif
96 CTRL_Obj ctrl; //v1p7 format
97 #endif
98 
99 uint16_t gLEDcnt = 0;
100 
102 
103 #ifdef FLASH
104 // Used for running BackGround in flash, and ISR in RAM
105 extern uint16_t *RamfuncsLoadStart, *RamfuncsLoadEnd, *RamfuncsRunStart;
106 
107 #ifdef F2802xF
108 extern uint16_t *econst_start, *econst_end, *econst_ram_load;
109 extern uint16_t *switch_start, *switch_end, *switch_ram_load;
110 #endif
111 
112 #endif
113 
114 _iq gLs_pu = _IQ30(0.0);
115 uint_least8_t gLs_qFmt = 0;
116 uint_least8_t gMax_Ls_qFmt = 0;
117 
118 #ifdef DRV8301_SPI
119 // Watch window interface to the 8301 SPI
120 DRV_SPI_8301_Vars_t gDrvSpi8301Vars;
121 #endif
122 
123 #ifdef DRV8305_SPI
124 // Watch window interface to the 8305 SPI
125 DRV_SPI_8305_Vars_t gDrvSpi8305Vars;
126 #endif
127 
128 // **************************************************************************
129 // the functions
130 
131 void main(void)
132 {
133  uint_least8_t estNumber = 0;
134 
135 #ifdef FAST_ROM_V1p6
136  uint_least8_t ctrlNumber = 0;
137 #endif
138 
139  // Only used if running from FLASH
140  // Note that the variable FLASH is defined by the project
141  #ifdef FLASH
142  // Copy time critical code and Flash setup code to RAM
143  // The RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart
144  // symbols are created by the linker. Refer to the linker files.
145  memCopy((uint16_t *)&RamfuncsLoadStart,(uint16_t *)&RamfuncsLoadEnd,(uint16_t *)&RamfuncsRunStart);
146 
147  #ifdef F2802xF
148  //copy .econst to unsecure RAM
149  if(*econst_end - *econst_start)
150  {
151  memCopy((uint16_t *)&econst_start,(uint16_t *)&econst_end,(uint16_t *)&econst_ram_load);
152  }
153 
154  //copy .switch ot unsecure RAM
155  if(*switch_end - *switch_start)
156  {
157  memCopy((uint16_t *)&switch_start,(uint16_t *)&switch_end,(uint16_t *)&switch_ram_load);
158  }
159  #endif
160 
161  #endif
162 
163  // initialize the hardware abstraction layer
164  halHandle = HAL_init(&hal,sizeof(hal));
165 
166 
167  // check for errors in user parameters
168  USER_checkForErrors(&gUserParams);
169 
170 
171  // store user parameter error in global variable
172  gMotorVars.UserErrorCode = USER_getErrorCode(&gUserParams);
173 
174 
175  // do not allow code execution if there is a user parameter error
176  if(gMotorVars.UserErrorCode != USER_ErrorCode_NoError)
177  {
178  for(;;)
179  {
180  gMotorVars.Flag_enableSys = false;
181  }
182  }
183 
184 
185  // initialize the user parameters
186  USER_setParams(&gUserParams);
187 
188 
189  // set the hardware abstraction layer parameters
190  HAL_setParams(halHandle,&gUserParams);
191 
192 
193  // initialize the controller
194 #ifdef FAST_ROM_V1p6
195  ctrlHandle = CTRL_initCtrl(ctrlNumber, estNumber); //v1p6 format (06xF and 06xM devices)
196  controller_obj = (CTRL_Obj *)ctrlHandle;
197 #else
198  ctrlHandle = CTRL_initCtrl(estNumber,&ctrl,sizeof(ctrl)); //v1p7 format default
199 #endif
200 
201 
202  {
203  CTRL_Version version;
204 
205  // get the version number
206  CTRL_getVersion(ctrlHandle,&version);
207 
208  gMotorVars.CtrlVersion = version;
209  }
210 
211 
212  // set the default controller parameters
213  CTRL_setParams(ctrlHandle,&gUserParams);
214 
215 
216  // setup faults
217  HAL_setupFaults(halHandle);
218 
219 
220  // initialize the interrupt vector table
221  HAL_initIntVectorTable(halHandle);
222 
223 
224  // enable the ADC interrupts
225  HAL_enableAdcInts(halHandle);
226 
227 
228  // enable global interrupts
229  HAL_enableGlobalInts(halHandle);
230 
231 
232  // enable debug interrupts
233  HAL_enableDebugInt(halHandle);
234 
235 
236  // disable the PWM
237  HAL_disablePwm(halHandle);
238 
239 
240 #ifdef DRV8301_SPI
241  // turn on the DRV8301 if present
242  HAL_enableDrv(halHandle);
243  // initialize the DRV8301 interface
244  HAL_setupDrvSpi(halHandle,&gDrvSpi8301Vars);
245 #endif
246 
247 #ifdef DRV8305_SPI
248  // turn on the DRV8305 if present
249  HAL_enableDrv(halHandle);
250  // initialize the DRV8305 interface
251  HAL_setupDrvSpi(halHandle,&gDrvSpi8305Vars);
252 #endif
253 
254 
255  // enable DC bus compensation
256  CTRL_setFlag_enableDcBusComp(ctrlHandle, true);
257 
258 
259  for(;;)
260  {
261  // Waiting for enable system flag to be set
262  while(!(gMotorVars.Flag_enableSys));
263 
264  // loop while the enable system flag is true
265  while(gMotorVars.Flag_enableSys)
266  {
267  CTRL_Obj *obj = (CTRL_Obj *)ctrlHandle;
268 
269  // increment counters
271 
272 
273  if(CTRL_isError(ctrlHandle))
274  {
275  // set the enable controller flag to false
276  CTRL_setFlag_enableCtrl(ctrlHandle,false);
277 
278  // set the enable system flag to false
279  gMotorVars.Flag_enableSys = false;
280 
281  // disable the PWM
282  HAL_disablePwm(halHandle);
283  }
284  else
285  {
286  // update the controller state
287  bool flag_ctrlStateChanged = CTRL_updateState(ctrlHandle);
288 
289  // enable or disable the control
290  CTRL_setFlag_enableCtrl(ctrlHandle, gMotorVars.Flag_Run_Identify);
291 
292  if(flag_ctrlStateChanged)
293  {
294  CTRL_State_e ctrlState = CTRL_getState(ctrlHandle);
295  EST_State_e estState = EST_getState(obj->estHandle);
296 
297  if(ctrlState == CTRL_State_OffLine)
298  {
299  // enable the PWM
300  HAL_enablePwm(halHandle);
301  }
302  else if(ctrlState == CTRL_State_OnLine)
303  {
304  if((estState < EST_State_LockRotor) || (estState > EST_State_MotorIdentified))
305  {
306  // update the ADC bias values
307  HAL_updateAdcBias(halHandle);
308  }
309 
310  // Return the bias value for currents
311  gMotorVars.I_bias.value[0] = HAL_getBias(halHandle,HAL_SensorType_Current,0);
312  gMotorVars.I_bias.value[1] = HAL_getBias(halHandle,HAL_SensorType_Current,1);
313  gMotorVars.I_bias.value[2] = HAL_getBias(halHandle,HAL_SensorType_Current,2);
314 
315  // Return the bias value for voltages
316  gMotorVars.V_bias.value[0] = HAL_getBias(halHandle,HAL_SensorType_Voltage,0);
317  gMotorVars.V_bias.value[1] = HAL_getBias(halHandle,HAL_SensorType_Voltage,1);
318  gMotorVars.V_bias.value[2] = HAL_getBias(halHandle,HAL_SensorType_Voltage,2);
319 
320  // enable the PWM
321  HAL_enablePwm(halHandle);
322  }
323  else if(ctrlState == CTRL_State_Idle)
324  {
325  // disable the PWM
326  HAL_disablePwm(halHandle);
327  gMotorVars.Flag_Run_Identify = false;
328  }
329 
330  if((CTRL_getFlag_enableUserMotorParams(ctrlHandle) == true) &&
331  (ctrlState > CTRL_State_Idle) &&
332  (gMotorVars.CtrlVersion.minor == 6))
333  {
334  // call this function to fix 1p6
335  USER_softwareUpdate1p6(ctrlHandle);
336  }
337 
338  }
339  }
340 
341 
343  {
344  // set the current ramp
346  gMotorVars.Flag_MotorIdentified = true;
347 
348  // set the speed reference
349  CTRL_setSpd_ref_krpm(ctrlHandle,gMotorVars.SpeedRef_krpm);
350 
351  // set the speed acceleration
353 
355  {
357 
358  USER_calcPIgains(ctrlHandle);
359  }
360 
361  }
362  else
363  {
365 
366  // the estimator sets the maximum current slope during identification
368  }
369 
370 
371  // when appropriate, update the global variables
373  {
374  // reset the counter
376 
377  updateGlobalVariables_motor(ctrlHandle);
378  }
379 
380  if(CTRL_getMotorType(ctrlHandle) == MOTOR_Type_Induction)
381  {
382  // recalculate Kp and Ki gains to fix the R/L limitation of 2000.0, and Kp limit to 0.11
383  recalcKpKi(ctrlHandle);
384 
385  // set electrical frequency limit to zero while identifying an induction motor
386  setFeLimitZero(ctrlHandle);
387 
388  // calculate Dir_qFmt for acim motors
389  acim_Dir_qFmtCalc(ctrlHandle);
390  }
391  else
392  {
393  // recalculate Kp and Ki gains to fix the R/L limitation of 2000.0, and Kp limit to 0.11
394  // as well as recalculates gains based on estimator state to allow low inductance pmsm to id
395  recalcKpKiPmsm(ctrlHandle);
396 
397  // calculate an Ls qFmt that allows ten times smaller inductance compared to Lhf
398  CTRL_calcMax_Ls_qFmt(ctrlHandle, &gMax_Ls_qFmt);
399 
402  }
403 
404  // enable/disable the forced angle
406 
407  // enable or disable power warp
408  CTRL_setFlag_enablePowerWarp(ctrlHandle,gMotorVars.Flag_enablePowerWarp);
409 
410 #ifdef DRV8301_SPI
411  HAL_writeDrvData(halHandle,&gDrvSpi8301Vars);
412 
413  HAL_readDrvData(halHandle,&gDrvSpi8301Vars);
414 #endif
415 #ifdef DRV8305_SPI
416  HAL_writeDrvData(halHandle,&gDrvSpi8305Vars);
417 
418  HAL_readDrvData(halHandle,&gDrvSpi8305Vars);
419 #endif
420  } // end of while(gFlag_enableSys) loop
421 
422 
423  // disable the PWM
424  HAL_disablePwm(halHandle);
425 
426  // set the default controller parameters (Reset the control to re-identify the motor)
427  CTRL_setParams(ctrlHandle,&gUserParams);
428  gMotorVars.Flag_Run_Identify = false;
429 
430  } // end of for(;;) loop
431 
432 } // end of main() function
433 
434 
435 interrupt void mainISR(void)
436 {
437  // toggle status LED
438  if(gLEDcnt++ > (uint_least32_t)(USER_ISR_FREQ_Hz / LED_BLINK_FREQ_Hz))
439  {
440  HAL_toggleLed(halHandle,(GPIO_Number_e)HAL_Gpio_LED2);
441  gLEDcnt = 0;
442  }
443 
444 
445  // acknowledge the ADC interrupt
446  HAL_acqAdcInt(halHandle,ADC_IntNumber_1);
447 
448 
449  // convert the ADC data
450  HAL_readAdcData(halHandle,&gAdcData);
451 
452 
453  // run the controller
454  CTRL_run(ctrlHandle,halHandle,&gAdcData,&gPwmData);
455 
456 
457  // write the PWM compare values
458  HAL_writePwmData(halHandle,&gPwmData);
459 
460 
461  // setup the controller
462  CTRL_setup(ctrlHandle);
463 
464 
465  if(CTRL_getMotorType(ctrlHandle) == MOTOR_Type_Pm)
466  {
467  // reset Ls Q format to a higher value when Ls identification starts
468  CTRL_resetLs_qFmt(ctrlHandle, gMax_Ls_qFmt);
469  }
470 
471  return;
472 } // end of mainISR() function
473 
474 
476 {
477  CTRL_Obj *obj = (CTRL_Obj *)handle;
478 
479  // get the speed estimate
480  gMotorVars.Speed_krpm = EST_getSpeed_krpm(obj->estHandle);
481 
482  // get the real time speed reference coming out of the speed trajectory generator
484 
485  // get the magnetizing current
486  gMotorVars.MagnCurr_A = EST_getIdRated(obj->estHandle);
487 
488  // get the rotor resistance
489  gMotorVars.Rr_Ohm = EST_getRr_Ohm(obj->estHandle);
490 
491  // get the stator resistance
492  gMotorVars.Rs_Ohm = EST_getRs_Ohm(obj->estHandle);
493 
494  // get the stator inductance in the direct coordinate direction
495  gMotorVars.Lsd_H = EST_getLs_d_H(obj->estHandle);
496 
497  // get the stator inductance in the quadrature coordinate direction
498  gMotorVars.Lsq_H = EST_getLs_q_H(obj->estHandle);
499 
500  // get the flux in V/Hz in floating point
501  gMotorVars.Flux_VpHz = EST_getFlux_VpHz(obj->estHandle);
502 
503  // get the controller state
504  gMotorVars.CtrlState = CTRL_getState(handle);
505 
506  // get the estimator state
507  gMotorVars.EstState = EST_getState(obj->estHandle);
508 
509  // Get the DC buss voltage
510  gMotorVars.VdcBus_kV = _IQmpy(gAdcData.dcBus,_IQ(USER_IQ_FULL_SCALE_VOLTAGE_V/1000.0));
511 
512  return;
513 } // end of updateGlobalVariables_motor() function
514 
515 
516 void CTRL_resetLs_qFmt(CTRL_Handle handle, const uint_least8_t Ls_qFmt)
517 {
518  CTRL_Obj *obj = (CTRL_Obj *)handle;
519  static bool LsResetLatch = false;
520 
521  // reset Ls Q format to a higher value when Ls identification starts
522  if(EST_getState(obj->estHandle) == EST_State_Ls)
523  {
524  if((EST_getLs_d_pu(obj->estHandle) != _IQ30(0.0)) && (LsResetLatch == false))
525  {
526  EST_setLs_qFmt(obj->estHandle, Ls_qFmt);
527  LsResetLatch = true;
528  }
529  }
530  else
531  {
532  LsResetLatch = false;
533  }
534 
535  return;
536 } // end of CTRL_resetLs_qFmt() function
537 
538 
540 {
541  CTRL_Obj *obj = (CTRL_Obj *)handle;
542  EST_State_e EstState = EST_getState(obj->estHandle);
543 
544  if((EST_isMotorIdentified(obj->estHandle) == false) && (EstState == EST_State_Rs))
545  {
546  float_t Lhf = CTRL_getLhf(handle);
547  float_t Rhf = CTRL_getRhf(handle);
548  float_t RhfoverLhf = Rhf/Lhf;
550  _iq Ki = _IQ(RhfoverLhf*USER_CTRL_PERIOD_sec);
552 
553  // set Rhf/Lhf
554  CTRL_setRoverL(handle,RhfoverLhf);
555 
556  // set the controller proportional gains
557  CTRL_setKp(handle,CTRL_Type_PID_Id,Kp);
558  CTRL_setKp(handle,CTRL_Type_PID_Iq,Kp);
559 
560  // set the Id controller gains
561  CTRL_setKi(handle,CTRL_Type_PID_Id,Ki);
562  PID_setKi(obj->pidHandle_Id,Ki);
563 
564  // set the Iq controller gains
565  CTRL_setKi(handle,CTRL_Type_PID_Iq,Ki);
566  PID_setKi(obj->pidHandle_Iq,Ki);
567 
568  // set speed gains
569  PID_setKp(obj->pidHandle_spd,Kp_spd);
570  }
571  else if(EstState == EST_State_RatedFlux)
572  {
574 
575  // Set Ki on closing the feedback loop
576  PID_setKi(obj->pidHandle_spd,Ki_spd);
577  }
578  else if(EstState == EST_State_RampDown)
579  {
582 
583  // Set Kp and Ki of the speed controller
584  PID_setKp(obj->pidHandle_spd,Kp_spd);
585  PID_setKi(obj->pidHandle_spd,Ki_spd);
586 
588  }
589 
590  return;
591 } // end of recalcKpKiPmsm() function
592 
593 
594 void CTRL_calcMax_Ls_qFmt(CTRL_Handle handle, uint_least8_t *pLs_qFmt)
595 {
596  CTRL_Obj *obj = (CTRL_Obj *)handle;
597 
598  if((EST_isMotorIdentified(obj->estHandle) == false) && (EST_getState(obj->estHandle) == EST_State_Rs))
599  {
600  float_t Lhf = CTRL_getLhf(handle);
602  float_t Ls_coarse_max = _IQ30toF(EST_getLs_coarse_max_pu(obj->estHandle));
603  int_least8_t lShift = ceil(log((Lhf/20.0)/(Ls_coarse_max*fullScaleInductance))/log(2.0));
604 
605  *pLs_qFmt = 30 - lShift;
606  }
607 
608  return;
609 } // end of CTRL_calcMax_Ls_qFmt() function
610 
611 
613 {
614  CTRL_Obj *obj = (CTRL_Obj *)handle;
615  EST_State_e EstState = EST_getState(obj->estHandle);
616 
617  if((EST_isMotorIdentified(obj->estHandle) == false) && (EstState == EST_State_Rs))
618  {
619  float_t Lhf = CTRL_getLhf(handle);
620  float_t Rhf = CTRL_getRhf(handle);
621  float_t RhfoverLhf = Rhf/Lhf;
623  _iq Ki = _IQ(RhfoverLhf*USER_CTRL_PERIOD_sec);
624 
625  // set Rhf/Lhf
626  CTRL_setRoverL(handle,RhfoverLhf);
627 
628  // set the controller proportional gains
629  CTRL_setKp(handle,CTRL_Type_PID_Id,Kp);
630  CTRL_setKp(handle,CTRL_Type_PID_Iq,Kp);
631 
632  // set the Id controller gains
633  CTRL_setKi(handle,CTRL_Type_PID_Id,Ki);
634  PID_setKi(obj->pidHandle_Id,Ki);
635 
636  // set the Iq controller gains
637  CTRL_setKi(handle,CTRL_Type_PID_Iq,Ki);
638  PID_setKi(obj->pidHandle_Iq,Ki);
639  }
640 
641  return;
642 } // end of recalcKpKi() function
643 
644 
646 {
647  CTRL_Obj *obj = (CTRL_Obj *)handle;
648  EST_State_e EstState = EST_getState(obj->estHandle);
649 
650  _iq fe_neg_max_pu;
651  _iq fe_pos_min_pu;
652 
653  if((EST_isMotorIdentified(obj->estHandle) == false) && (CTRL_getMotorType(handle) == MOTOR_Type_Induction))
654  {
655  fe_neg_max_pu = _IQ30(0.0);
656 
657  fe_pos_min_pu = _IQ30(0.0);
658  }
659  else
660  {
661  fe_neg_max_pu = _IQ30(-USER_ZEROSPEEDLIMIT);
662 
663  fe_pos_min_pu = _IQ30(USER_ZEROSPEEDLIMIT);
664  }
665 
666  EST_setFe_neg_max_pu(obj->estHandle, fe_neg_max_pu);
667 
668  EST_setFe_pos_min_pu(obj->estHandle, fe_pos_min_pu);
669 
670  return;
671 } // end of setFeLimitZero() function
672 
673 
675 {
676  CTRL_Obj *obj = (CTRL_Obj *)handle;
677  EST_State_e EstState = EST_getState(obj->estHandle);
678 
679  if(EstState == EST_State_IdRated)
680  {
682  }
683 
684  return;
685 } // end of acim_Dir_qFmtCalc() function
686 
687 
689 // end of file
690 
691 
692 
float_t EST_getFlux_VpHz(EST_Handle handle)
void EST_setFlag_enableForceAngle(EST_Handle handle, const bool state)
_iq EST_getLs_coarse_max_pu(EST_Handle handle)
static void TRAJ_setTargetValue(TRAJ_Handle handle, const _iq targetValue)
#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 acim_Dir_qFmtCalc(CTRL_Handle handle)
Calculates Dir_qFmt for ACIM.
Definition: proj_lab02c.c:674
void CTRL_run(CTRL_Handle handle, HAL_Handle halHandle, const HAL_AdcData_t *pAdcData, HAL_PwmData_t *pPwmData)
float_t Lsq_H
Definition: main.h:172
static void PID_setKi(PID_Handle handle, const _iq Ki)
#define _IQ(A)
bool Flag_Latch_softwareUpdate
Definition: proj_lab02c.c:70
bool Flag_Run_Identify
Definition: main.h:137
_iq EST_getSpeed_krpm(EST_Handle handle)
_iq gMaxCurrentSlope
Definition: proj_lab02c.c:88
void USER_calcPIgains(CTRL_Handle handle)
Updates Id and Iq PI gains.
CTRL_State_e CtrlState
Definition: main.h:147
void EST_setFe_pos_min_pu(EST_Handle handle, const _iq fe_pos_min_pu)
void EST_setFe_neg_max_pu(EST_Handle handle, const _iq fe_neg_max_pu)
bool Flag_enablePowerWarp
Definition: main.h:144
static void HAL_writePwmData(HAL_Handle handle, HAL_PwmData_t *pPwmData)
void EST_setMaxCurrentSlope_pu(EST_Handle handle, const _iq maxCurrentSlope_pu)
_iq value[3]
float_t CTRL_getLhf(CTRL_Handle handle)
#define NUM_MAIN_TICKS_FOR_GLOBAL_VARIABLE_UPDATE
Defines the number of main iterations before global variables are updated.
Definition: float/main.h:48
void HAL_writeDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
bool CTRL_isError(CTRL_Handle handle)
void USER_softwareUpdate1p6(CTRL_Handle handle)
Recalculates Inductances with the correct Q Format.
PID_Handle pidHandle_Id
static void HAL_acqAdcInt(HAL_Handle handle, const ADC_IntNumber_e intNumber)
_iq EST_get_pu_to_krpm_sf(EST_Handle handle)
#define USER_IQ_FULL_SCALE_VOLTAGE_V
Defines full scale value for the IQ30 variable of Voltage inside the system.
Definition: user.h:88
volatile MOTOR_Vars_t gMotorVars
Definition: proj_lab02c.c:101
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)
bool Flag_enableForceAngle
Definition: main.h:139
#define USER_ZEROSPEEDLIMIT
Defines the low speed limit for the flux integrator, pu.
Definition: user.h:244
void recalcKpKi(CTRL_Handle handle)
Recalculate Kp and Ki gains to fix the R/L limitation of 2000.0 and Kp limitation of 0...
Definition: proj_lab02c.c:612
void CTRL_setFlag_enableCtrl(CTRL_Handle handle, const bool state)
long _iq
void USER_setParams(USER_Params *pUserParams)
Sets the user parameter values.
void EST_setLs_qFmt(EST_Handle handle, const uint_least8_t Ls_qFmt)
EST_State_e EstState
Definition: main.h:148
TRAJ_Handle trajHandle_spdMax
uint_least8_t EST_computeDirection_qFmt(EST_Handle handle, const float_t flux_max)
float_t Rs_Ohm
Definition: main.h:169
uint_least8_t gMax_Ls_qFmt
Definition: proj_lab02c.c:116
#define HAL_toggleLed
float_t CTRL_getRhf(CTRL_Handle handle)
HAL_AdcData_t gAdcData
Defines the ADC data.
Definition: proj_lab02c.c:86
_iq EST_getLs_d_pu(EST_Handle handle)
Defines the structures, global initialization, and functions used in MAIN.
void EST_setDir_qFmt(EST_Handle handle, const uint_least8_t dir_qFmt)
void CTRL_setMaxAccel_pu(CTRL_Handle handle, const _iq maxAccel_pu)
void recalcKpKiPmsm(CTRL_Handle handle)
Recalculate Kp and Ki gains to fix the R/L limitation of 2000.0 and Kp limitation of 0...
Definition: proj_lab02c.c:539
void HAL_setupFaults(HAL_Handle handle)
float_t EST_getLs_d_H(EST_Handle handle)
void CTRL_resetLs_qFmt(CTRL_Handle handle, const uint_least8_t Ls_qFmt)
Reset Ls Q format to a higher value when Ls identification starts.
Definition: proj_lab02c.c:516
void main(void)
Definition: proj_lab02c.c:131
static void HAL_enablePwm(HAL_Handle handle)
void CTRL_setParams(CTRL_Handle handle, USER_Params *pUserParams)
#define _IQmpy(A, B)
EST_State_e
uint_least8_t gLs_qFmt
Definition: proj_lab02c.c:115
USER_ErrorCode_e USER_getErrorCode(USER_Params *pUserParams)
Gets the error code in the user parameters.
void HAL_enableDrv(HAL_Handle handle)
_iq VdcBus_kV
Definition: main.h:192
void setFeLimitZero(CTRL_Handle handle)
Set electrical frequency limit to zero while identifying an induction motor.
Definition: proj_lab02c.c:645
_iq SpeedRef_krpm
Definition: main.h:157
uint_least8_t EST_getLs_qFmt(EST_Handle handle)
PID_Handle pidHandle_spd
void HAL_setupDrvSpi(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
float_t EST_getLs_q_H(EST_Handle handle)
bool CTRL_getFlag_enableUserMotorParams(CTRL_Handle handle)
void HAL_enableDebugInt(HAL_Handle handle)
CTRL_State_e CTRL_getState(CTRL_Handle handle)
float_t Flux_VpHz
Definition: main.h:173
EST_State_e EST_getState(EST_Handle handle)
CTRL_Handle ctrlHandle
The controller handle.
Definition: proj_lab02c.c:72
CTRL_Obj ctrl
Defines the CTRL object.
Definition: proj_lab02c.c:96
HAL_Handle halHandle
The hal handle.
Definition: proj_lab02c.c:77
void CTRL_setup(CTRL_Handle handle)
MATH_vec3 V_bias
Definition: main.h:199
#define MOTOR_Vars_INIT
Initialization values of global variables.
Definition: main.h:76
CTRL_State_e
USER_Params gUserParams
The user parameters.
Definition: proj_lab02c.c:82
void CTRL_calcMax_Ls_qFmt(CTRL_Handle handle, uint_least8_t *pLs_qFmt)
Calculates the maximum qFmt value for Ls identification, to get a more accurate Ls per unit...
Definition: proj_lab02c.c:594
_iq Speed_krpm
Definition: main.h:160
float_t EST_getIdRated(EST_Handle handle)
#define USER_MOTOR_RES_EST_CURRENT
Definition: user.h:405
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)
float_t Lsd_H
Definition: main.h:171
#define _IQ30(A)
#define USER_IQ_FULL_SCALE_FREQ_Hz
CURRENTS AND VOLTAGES.
Definition: user.h:78
PID_Handle pidHandle_Iq
_iq gLs_pu
Definition: proj_lab02c.c:114
void CTRL_setFlag_enablePowerWarp(CTRL_Handle handle, const bool state)
#define USER_ISR_FREQ_Hz
Defines the Interrupt Service Routine (ISR) frequency, Hz.
Definition: user.h:173
bool CTRL_updateState(CTRL_Handle handle)
static void HAL_disablePwm(HAL_Handle handle)
bool EST_isMotorIdentified(EST_Handle handle)
HAL_Handle HAL_init(void *pMemory, const size_t numBytes)
void CTRL_setFlag_enableDcBusComp(CTRL_Handle handle, const bool state)
#define USER_VOLTAGE_FILTER_POLE_rps
Defines the analog voltage filter pole location, rad/s.
Definition: user.h:305
_iq EST_getMaxCurrentSlope_pu(EST_Handle handle)
_iq SpeedTraj_krpm
Definition: main.h:158
#define USER_IQ_FULL_SCALE_CURRENT_A
Defines the full scale current for the IQ variables, A.
Definition: user.h:102
interrupt void mainISR(void)
The main interrupt service (ISR) routine.
Definition: proj_lab02c.c:435
float_t MagnCurr_A
Definition: main.h:167
static void HAL_readAdcData(HAL_Handle handle, HAL_AdcData_t *pAdcData)
HAL_Obj hal
#define LED_BLINK_FREQ_Hz
Definition: proj_lab02c.c:62
static _iq HAL_getBias(HAL_Handle handle, const HAL_SensorType_e sensorType, uint_least8_t sensorNumber)
bool Flag_enableSys
Definition: main.h:136
_iq MaxAccel_krpmps
Definition: main.h:159
_iq CTRL_getSpd_int_ref_pu(CTRL_Handle handle)
HAL_PwmData_t gPwmData
Defines the PWM data.
Definition: proj_lab02c.c:84
MATH_vec3 I_bias
Definition: main.h:198
static void HAL_initIntVectorTable(HAL_Handle handle)
static void HAL_updateAdcBias(HAL_Handle handle)
void CTRL_getVersion(CTRL_Handle handle, CTRL_Version *pVersion)
uint16_t minor
CTRL_Version CtrlVersion
Definition: main.h:152
float_t EST_getRr_Ohm(EST_Handle handle)
void HAL_setParams(HAL_Handle handle, const USER_Params *pUserParams)
MOTOR_Type_e CTRL_getMotorType(CTRL_Handle handle)
uint_least16_t gCounter_updateGlobals
A counter that is denotes when to update the global variables.
Definition: proj_lab02c.c:68
void updateGlobalVariables_motor(CTRL_Handle handle)
Updates the global motor variables.
Definition: proj_lab02c.c:475
void HAL_readDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
void CTRL_setRoverL(CTRL_Handle handle, const float_t RoverL)
uint16_t gLEDcnt
Definition: proj_lab02c.c:99
#define USER_MOTOR_MAX_CURRENT
Definition: user.h:407
#define USER_CTRL_PERIOD_sec
Defines the controller execution period, sec.
Definition: user.h:231
float _IQ30toF(long A)
void USER_checkForErrors(USER_Params *pUserParams)
Checks for errors in the user parameter values.
CTRL_Obj * controller_obj
Definition: proj_lab10c.c:84
GPIO_Number_e
void CTRL_setSpd_ref_krpm(CTRL_Handle handle, const _iq spd_ref_krpm)
static void PID_setKp(PID_Handle handle, const _iq Kp)
void CTRL_setKp(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Kp)
float float_t