instaspin_foc
proj_lab07.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 
90 uint32_t gNumFreqErrors = 0;
91 uint32_t gMaxDeltaCntObserved = 0;
92 
98 
100 
101 #ifdef FAST_ROM_V1p6
103 #else
104 #ifdef F2802xF
105 #pragma DATA_SECTION(ctrl,"rom_accessed_data");
106 #endif
107 CTRL_Obj ctrl; //v1p7 format
108 #endif
109 
110 uint16_t gLEDcnt = 0;
111 
113 
114 #ifdef FLASH
115 // Used for running BackGround in flash, and ISR in RAM
116 extern uint16_t *RamfuncsLoadStart, *RamfuncsLoadEnd, *RamfuncsRunStart;
117 
118 #ifdef F2802xF
119 extern uint16_t *econst_start, *econst_end, *econst_ram_load;
120 extern uint16_t *switch_start, *switch_end, *switch_ram_load;
121 #endif
122 
123 #endif
124 
125 
126 #ifdef DRV8301_SPI
127 // Watch window interface to the 8301 SPI
128 DRV_SPI_8301_Vars_t gDrvSpi8301Vars;
129 #endif
130 
131 #ifdef DRV8305_SPI
132 // Watch window interface to the 8305 SPI
133 DRV_SPI_8305_Vars_t gDrvSpi8305Vars;
134 #endif
135 
137 
139 
141 
143 
144 // **************************************************************************
145 // the functions
146 
147 void main(void)
148 {
149  uint_least8_t estNumber = 0;
150 
151 #ifdef FAST_ROM_V1p6
152  uint_least8_t ctrlNumber = 0;
153 #endif
154 
155  // Only used if running from FLASH
156  // Note that the variable FLASH is defined by the project
157  #ifdef FLASH
158  // Copy time critical code and Flash setup code to RAM
159  // The RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart
160  // symbols are created by the linker. Refer to the linker files.
161  memCopy((uint16_t *)&RamfuncsLoadStart,(uint16_t *)&RamfuncsLoadEnd,(uint16_t *)&RamfuncsRunStart);
162 
163  #ifdef F2802xF
164  //copy .econst to unsecure RAM
165  if(*econst_end - *econst_start)
166  {
167  memCopy((uint16_t *)&econst_start,(uint16_t *)&econst_end,(uint16_t *)&econst_ram_load);
168  }
169 
170  //copy .switch ot unsecure RAM
171  if(*switch_end - *switch_start)
172  {
173  memCopy((uint16_t *)&switch_start,(uint16_t *)&switch_end,(uint16_t *)&switch_ram_load);
174  }
175  #endif
176 
177  #endif
178 
179  // initialize the hardware abstraction layer
180  halHandle = HAL_init(&hal,sizeof(hal));
181 
182 
183  // check for errors in user parameters
184  USER_checkForErrors(&gUserParams);
185 
186 
187  // store user parameter error in global variable
188  gMotorVars.UserErrorCode = USER_getErrorCode(&gUserParams);
189 
190 
191  // do not allow code execution if there is a user parameter error
192  if(gMotorVars.UserErrorCode != USER_ErrorCode_NoError)
193  {
194  for(;;)
195  {
196  gMotorVars.Flag_enableSys = false;
197  }
198  }
199 
200 
201  // initialize the user parameters
202  USER_setParams(&gUserParams);
203 
204 
205  // set the hardware abstraction layer parameters
206  HAL_setParams(halHandle,&gUserParams);
207 
208 
209  // initialize the controller
210 #ifdef FAST_ROM_V1p6
211  ctrlHandle = CTRL_initCtrl(ctrlNumber, estNumber); //v1p6 format (06xF and 06xM devices)
212  controller_obj = (CTRL_Obj *)ctrlHandle;
213 #else
214  ctrlHandle = CTRL_initCtrl(estNumber,&ctrl,sizeof(ctrl)); //v1p7 format default
215 #endif
216 
217 
218  {
219  CTRL_Version version;
220 
221  // get the version number
222  CTRL_getVersion(ctrlHandle,&version);
223 
224  gMotorVars.CtrlVersion = version;
225  }
226 
227 
228  // set the default controller parameters
229  CTRL_setParams(ctrlHandle,&gUserParams);
230 
231 
232  // initialize the frequency of execution monitoring module
233  femHandle = FEM_init(&fem,sizeof(fem));
234  FEM_setParams(femHandle,
235  USER_SYSTEM_FREQ_MHz * 1000000.0, // timer frequency, Hz
236  (uint32_t)USER_SYSTEM_FREQ_MHz * 1000000, // timer period, cnts
237  USER_CTRL_FREQ_Hz, // set point frequency, Hz
238  1000.0); // max frequency error, Hz
239 
240 
241  // initialize the CPU usage module
242  cpu_usageHandle = CPU_USAGE_init(&cpu_usage,sizeof(cpu_usage));
243  CPU_USAGE_setParams(cpu_usageHandle,
244  (uint32_t)USER_SYSTEM_FREQ_MHz * 1000000, // timer period, cnts
245  (uint32_t)USER_ISR_FREQ_Hz); // average over 1 second of ISRs
246 
247 
248  // setup faults
249  HAL_setupFaults(halHandle);
250 
251 
252  // initialize the interrupt vector table
253  HAL_initIntVectorTable(halHandle);
254 
255 
256  // enable the ADC interrupts
257  HAL_enableAdcInts(halHandle);
258 
259 
260  // reload timer to start running frequency of execution monitoring
261  HAL_reloadTimer(halHandle,0);
262 
263 
264  // enable global interrupts
265  HAL_enableGlobalInts(halHandle);
266 
267 
268  // enable debug interrupts
269  HAL_enableDebugInt(halHandle);
270 
271 
272  // disable the PWM
273  HAL_disablePwm(halHandle);
274 
275 
276 #ifdef DRV8301_SPI
277  // turn on the DRV8301 if present
278  HAL_enableDrv(halHandle);
279  // initialize the DRV8301 interface
280  HAL_setupDrvSpi(halHandle,&gDrvSpi8301Vars);
281 #endif
282 
283 #ifdef DRV8305_SPI
284  // turn on the DRV8305 if present
285  HAL_enableDrv(halHandle);
286  // initialize the DRV8305 interface
287  HAL_setupDrvSpi(halHandle,&gDrvSpi8305Vars);
288 #endif
289 
290 
291  // enable DC bus compensation
292  CTRL_setFlag_enableDcBusComp(ctrlHandle, true);
293 
294 
295  // compute scaling factors for flux and torque calculations
300 
301 
302  for(;;)
303  {
304  // Waiting for enable system flag to be set
305  while(!(gMotorVars.Flag_enableSys));
306 
307  // Enable the Library internal PI. Iq is referenced by the speed PI now
308  CTRL_setFlag_enableSpeedCtrl(ctrlHandle, true);
309 
310  // loop while the enable system flag is true
311  while(gMotorVars.Flag_enableSys)
312  {
313  CTRL_Obj *obj = (CTRL_Obj *)ctrlHandle;
314 
315  // increment counters
317 
318  // enable/disable the use of motor parameters being loaded from user.h
320 
321  // enable/disable Rs recalibration during motor startup
323 
324  // enable/disable automatic calculation of bias values
325  CTRL_setFlag_enableOffset(ctrlHandle,gMotorVars.Flag_enableOffsetcalc);
326 
327 
328  if(CTRL_isError(ctrlHandle))
329  {
330  // set the enable controller flag to false
331  CTRL_setFlag_enableCtrl(ctrlHandle,false);
332 
333  // set the enable system flag to false
334  gMotorVars.Flag_enableSys = false;
335 
336  // disable the PWM
337  HAL_disablePwm(halHandle);
338  }
339  else
340  {
341  // update the controller state
342  bool flag_ctrlStateChanged = CTRL_updateState(ctrlHandle);
343 
344  // enable or disable the control
345  CTRL_setFlag_enableCtrl(ctrlHandle, gMotorVars.Flag_Run_Identify);
346 
347  if(flag_ctrlStateChanged)
348  {
349  CTRL_State_e ctrlState = CTRL_getState(ctrlHandle);
350 
351  if(ctrlState == CTRL_State_OffLine)
352  {
353  // enable the PWM
354  HAL_enablePwm(halHandle);
355  }
356  else if(ctrlState == CTRL_State_OnLine)
357  {
358  if(gMotorVars.Flag_enableOffsetcalc == true)
359  {
360  // update the ADC bias values
361  HAL_updateAdcBias(halHandle);
362  }
363  else
364  {
365  // set the current bias
366  HAL_setBias(halHandle,HAL_SensorType_Current,0,_IQ(I_A_offset));
367  HAL_setBias(halHandle,HAL_SensorType_Current,1,_IQ(I_B_offset));
368  HAL_setBias(halHandle,HAL_SensorType_Current,2,_IQ(I_C_offset));
369 
370  // set the voltage bias
371  HAL_setBias(halHandle,HAL_SensorType_Voltage,0,_IQ(V_A_offset));
372  HAL_setBias(halHandle,HAL_SensorType_Voltage,1,_IQ(V_B_offset));
373  HAL_setBias(halHandle,HAL_SensorType_Voltage,2,_IQ(V_C_offset));
374  }
375 
376  // Return the bias value for currents
377  gMotorVars.I_bias.value[0] = HAL_getBias(halHandle,HAL_SensorType_Current,0);
378  gMotorVars.I_bias.value[1] = HAL_getBias(halHandle,HAL_SensorType_Current,1);
379  gMotorVars.I_bias.value[2] = HAL_getBias(halHandle,HAL_SensorType_Current,2);
380 
381  // Return the bias value for voltages
382  gMotorVars.V_bias.value[0] = HAL_getBias(halHandle,HAL_SensorType_Voltage,0);
383  gMotorVars.V_bias.value[1] = HAL_getBias(halHandle,HAL_SensorType_Voltage,1);
384  gMotorVars.V_bias.value[2] = HAL_getBias(halHandle,HAL_SensorType_Voltage,2);
385 
386  // enable the PWM
387  HAL_enablePwm(halHandle);
388  }
389  else if(ctrlState == CTRL_State_Idle)
390  {
391  // disable the PWM
392  HAL_disablePwm(halHandle);
393  gMotorVars.Flag_Run_Identify = false;
394  }
395 
396  if((CTRL_getFlag_enableUserMotorParams(ctrlHandle) == true) &&
397  (ctrlState > CTRL_State_Idle) &&
398  (gMotorVars.CtrlVersion.minor == 6))
399  {
400  // call this function to fix 1p6
401  USER_softwareUpdate1p6(ctrlHandle);
402  }
403 
404  }
405  }
406 
407 
409  {
410  // set the current ramp
412  gMotorVars.Flag_MotorIdentified = true;
413 
414  // set the speed reference
415  CTRL_setSpd_ref_krpm(ctrlHandle,gMotorVars.SpeedRef_krpm);
416 
417  // set the speed acceleration
419 
421  {
423 
424  USER_calcPIgains(ctrlHandle);
425 
426  // initialize the watch window kp and ki current values with pre-calculated values
427  gMotorVars.Kp_Idq = CTRL_getKp(ctrlHandle,CTRL_Type_PID_Id);
428  gMotorVars.Ki_Idq = CTRL_getKi(ctrlHandle,CTRL_Type_PID_Id);
429 
430  // initialize the watch window kp and ki values with pre-calculated values
431  gMotorVars.Kp_spd = CTRL_getKp(ctrlHandle,CTRL_Type_PID_spd);
432  gMotorVars.Ki_spd = CTRL_getKi(ctrlHandle,CTRL_Type_PID_spd);
433  }
434 
435  }
436  else
437  {
439 
440  // the estimator sets the maximum current slope during identification
442  }
443 
444 
445  // when appropriate, update the global variables
447  {
448  // reset the counter
450 
451  updateGlobalVariables_motor(ctrlHandle);
452  }
453 
454  // update Kp and Ki gains
455  updateKpKiGains(ctrlHandle);
456 
457  // run Rs online
458  runRsOnLine(ctrlHandle);
459 
460  // update CPU usage
461  updateCPUusage();
462 
463  // enable/disable the forced angle
465 
466  // enable or disable power warp
467  CTRL_setFlag_enablePowerWarp(ctrlHandle,gMotorVars.Flag_enablePowerWarp);
468 
469 #ifdef DRV8301_SPI
470  HAL_writeDrvData(halHandle,&gDrvSpi8301Vars);
471 
472  HAL_readDrvData(halHandle,&gDrvSpi8301Vars);
473 #endif
474 #ifdef DRV8305_SPI
475  HAL_writeDrvData(halHandle,&gDrvSpi8305Vars);
476 
477  HAL_readDrvData(halHandle,&gDrvSpi8305Vars);
478 #endif
479  // get the maximum delta count observed
481 
482  // check for errors
483  if(FEM_isFreqError(femHandle))
484  {
485  gNumFreqErrors = FEM_getErrorCnt(femHandle);
486  }
487 
488  } // end of while(gFlag_enableSys) loop
489 
490 
491  // disable the PWM
492  HAL_disablePwm(halHandle);
493 
494  // set the default controller parameters (Reset the control to re-identify the motor)
495  CTRL_setParams(ctrlHandle,&gUserParams);
496  gMotorVars.Flag_Run_Identify = false;
497 
498  } // end of for(;;) loop
499 
500 } // end of main() function
501 
502 
503 interrupt void mainISR(void)
504 {
505  uint32_t timer0Cnt;
506  uint32_t timer1Cnt;
507 
508 
509  // read the timer 1 value and update the CPU usage module
510  timer1Cnt = HAL_readTimerCnt(halHandle,1);
511  CPU_USAGE_updateCnts(cpu_usageHandle,timer1Cnt);
512 
513 
514  // read the timer 0 value and update the FEM
515  timer0Cnt = HAL_readTimerCnt(halHandle,0);
516  FEM_updateCnts(femHandle,timer0Cnt);
517  FEM_run(femHandle);
518 
519 
520  // toggle status LED
521  if(gLEDcnt++ > (uint_least32_t)(USER_ISR_FREQ_Hz / LED_BLINK_FREQ_Hz))
522  {
523  HAL_toggleLed(halHandle,(GPIO_Number_e)HAL_Gpio_LED2);
524  gLEDcnt = 0;
525  }
526 
527 
528  // acknowledge the ADC interrupt
529  HAL_acqAdcInt(halHandle,ADC_IntNumber_1);
530 
531 
532  // convert the ADC data
533  HAL_readAdcData(halHandle,&gAdcData);
534 
535 
536  // run the controller
537  CTRL_run(ctrlHandle,halHandle,&gAdcData,&gPwmData);
538 
539 
540  // write the PWM compare values
541  HAL_writePwmData(halHandle,&gPwmData);
542 
543 
544  // setup the controller
545  CTRL_setup(ctrlHandle);
546 
547 
548  // read the timer 1 value and update the CPU usage module
549  timer1Cnt = HAL_readTimerCnt(halHandle,1);
550  CPU_USAGE_updateCnts(cpu_usageHandle,timer1Cnt);
551 
552 
553  // run the CPU usage module
554  CPU_USAGE_run(cpu_usageHandle);
555 
556 
557  return;
558 } // end of mainISR() function
559 
560 
562 {
563  CTRL_Obj *obj = (CTRL_Obj *)handle;
564 
565  // get the speed estimate
566  gMotorVars.Speed_krpm = EST_getSpeed_krpm(obj->estHandle);
567 
568  // get the real time speed reference coming out of the speed trajectory generator
570 
571  // get the torque estimate
573 
574  // get the magnetizing current
575  gMotorVars.MagnCurr_A = EST_getIdRated(obj->estHandle);
576 
577  // get the rotor resistance
578  gMotorVars.Rr_Ohm = EST_getRr_Ohm(obj->estHandle);
579 
580  // get the stator resistance
581  gMotorVars.Rs_Ohm = EST_getRs_Ohm(obj->estHandle);
582 
583  // get the stator resistance online
584  gMotorVars.RsOnLine_Ohm = EST_getRsOnLine_Ohm(obj->estHandle);
585 
586  // get the stator inductance in the direct coordinate direction
587  gMotorVars.Lsd_H = EST_getLs_d_H(obj->estHandle);
588 
589  // get the stator inductance in the quadrature coordinate direction
590  gMotorVars.Lsq_H = EST_getLs_q_H(obj->estHandle);
591 
592  // get the flux in V/Hz in floating point
593  gMotorVars.Flux_VpHz = EST_getFlux_VpHz(obj->estHandle);
594 
595  // get the flux in Wb in fixed point
596  gMotorVars.Flux_Wb = USER_computeFlux(handle, gFlux_pu_to_Wb_sf);
597 
598  // get the controller state
599  gMotorVars.CtrlState = CTRL_getState(handle);
600 
601  // get the estimator state
602  gMotorVars.EstState = EST_getState(obj->estHandle);
603 
604  // Get the DC buss voltage
605  gMotorVars.VdcBus_kV = _IQmpy(gAdcData.dcBus,_IQ(USER_IQ_FULL_SCALE_VOLTAGE_V/1000.0));
606 
607  return;
608 } // end of updateGlobalVariables_motor() function
609 
610 
612 {
613  if((gMotorVars.CtrlState == CTRL_State_OnLine) && (gMotorVars.Flag_MotorIdentified == true) && (Flag_Latch_softwareUpdate == false))
614  {
615  // set the kp and ki speed values from the watch window
616  CTRL_setKp(handle,CTRL_Type_PID_spd,gMotorVars.Kp_spd);
617  CTRL_setKi(handle,CTRL_Type_PID_spd,gMotorVars.Ki_spd);
618 
619  // set the kp and ki current values for Id and Iq from the watch window
620  CTRL_setKp(handle,CTRL_Type_PID_Id,gMotorVars.Kp_Idq);
621  CTRL_setKi(handle,CTRL_Type_PID_Id,gMotorVars.Ki_Idq);
622  CTRL_setKp(handle,CTRL_Type_PID_Iq,gMotorVars.Kp_Idq);
623  CTRL_setKi(handle,CTRL_Type_PID_Iq,gMotorVars.Ki_Idq);
624  }
625 
626  return;
627 } // end of updateKpKiGains() function
628 
629 
631 {
632  CTRL_Obj *obj = (CTRL_Obj *)handle;
633 
634  // execute Rs OnLine code
635  if(gMotorVars.Flag_Run_Identify == true)
636  {
637  if(EST_getState(obj->estHandle) == EST_State_OnLine)
638  {
639  float_t RsError_Ohm = gMotorVars.RsOnLine_Ohm - gMotorVars.Rs_Ohm;
640 
643 
644  if(abs(RsError_Ohm) < (gMotorVars.Rs_Ohm * 0.05))
645  {
646  EST_setFlag_updateRs(obj->estHandle,true);
647  }
648  }
649  else
650  {
653  EST_setRsOnLine_pu(obj->estHandle,_IQ(0.0));
655  EST_setFlag_updateRs(obj->estHandle,false);
657  }
658  }
659 
660  return;
661 } // end of runRsOnLine() function
662 
663 
664 void updateCPUusage(void)
665 {
666  uint32_t minDeltaCntObserved = CPU_USAGE_getMinDeltaCntObserved(cpu_usageHandle);
667  uint32_t avgDeltaCntObserved = CPU_USAGE_getAvgDeltaCntObserved(cpu_usageHandle);
668  uint32_t maxDeltaCntObserved = CPU_USAGE_getMaxDeltaCntObserved(cpu_usageHandle);
669  uint16_t pwmPeriod = HAL_readPwmPeriod(halHandle,PWM_Number_1);
670  float_t cpu_usage_den = (float_t)pwmPeriod * (float_t)USER_NUM_PWM_TICKS_PER_ISR_TICK * 2.0;
671 
672  // calculate the minimum cpu usage percentage
673  gCpuUsagePercentageMin = (float_t)minDeltaCntObserved / cpu_usage_den * 100.0;
674 
675  // calculate the average cpu usage percentage
676  gCpuUsagePercentageAvg = (float_t)avgDeltaCntObserved / cpu_usage_den * 100.0;
677 
678  // calculate the maximum cpu usage percentage
679  gCpuUsagePercentageMax = (float_t)maxDeltaCntObserved / cpu_usage_den * 100.0;
680 
681  return;
682 } // end of updateCPUusage() function
683 
684 
686 // end of file
687 
688 
689 
float_t EST_getFlux_VpHz(EST_Handle handle)
_iq gTorque_Flux_Iq_pu_to_Nm_sf
Definition: proj_lab07.c:142
#define USER_SYSTEM_FREQ_MHz
CLOCKS & TIMERS.
Definition: user.h:140
float_t EST_getRsOnLine_Ohm(EST_Handle handle)
void EST_setFlag_enableForceAngle(EST_Handle handle, const bool state)
#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
_iq RsOnLineCurrent_A
Definition: main.h:162
void CTRL_run(CTRL_Handle handle, HAL_Handle halHandle, const HAL_AdcData_t *pAdcData, HAL_PwmData_t *pPwmData)
float_t RsOnLine_Ohm
Definition: main.h:170
float_t Lsq_H
Definition: main.h:172
static void HAL_reloadTimer(HAL_Handle handle, const uint_least8_t timerNumber)
_iq USER_computeFlux_pu_to_VpHz_sf(void)
Computes the scale factor needed to convert from per unit to V/Hz.
#define _IQ(A)
bool Flag_Run_Identify
Definition: main.h:137
_iq EST_getSpeed_krpm(EST_Handle handle)
void EST_setRsOnLineId_mag_pu(EST_Handle handle, const _iq Id_mag_pu)
void USER_calcPIgains(CTRL_Handle handle)
Updates Id and Iq PI gains.
CTRL_State_e CtrlState
Definition: main.h:147
CPU_USAGE_Handle cpu_usageHandle
Definition: proj_lab07.c:93
float_t gCpuUsagePercentageMax
Definition: proj_lab07.c:97
uint_least16_t gCounter_updateGlobals
A counter that is denotes when to update the global variables.
Definition: proj_lab07.c:68
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]
#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)
static uint32_t FEM_getErrorCnt(FEM_Handle handle)
HAL_PwmData_t gPwmData
Defines the PWM data.
Definition: proj_lab07.c:84
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)
#define USER_IQ_FULL_SCALE_VOLTAGE_V
Defines full scale value for the IQ30 variable of Voltage inside the system.
Definition: user.h:88
uint32_t gMaxDeltaCntObserved
Definition: proj_lab07.c:91
_iq gTorque_Ls_Id_Iq_pu_to_Nm_sf
Definition: proj_lab07.c:140
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
void CTRL_setFlag_enableCtrl(CTRL_Handle handle, const bool state)
static uint32_t CPU_USAGE_getAvgDeltaCntObserved(CPU_USAGE_Handle handle)
void CTRL_setFlag_enableSpeedCtrl(CTRL_Handle handle, const bool state)
float_t gCpuUsagePercentageMin
Definition: proj_lab07.c:95
#define V_B_offset
Definition: user.h:133
_iq gFlux_pu_to_Wb_sf
Definition: proj_lab07.c:136
long _iq
void EST_setRsOnLine_pu(EST_Handle handle, const _iq Rs_pu)
bool Flag_Latch_softwareUpdate
Definition: proj_lab07.c:70
void USER_setParams(USER_Params *pUserParams)
Sets the user parameter values.
EST_State_e EstState
Definition: main.h:148
void EST_setFlag_updateRs(EST_Handle handle, const bool state)
float_t Rs_Ohm
Definition: main.h:169
void updateGlobalVariables_motor(CTRL_Handle handle)
Updates the global motor variables.
Definition: proj_lab07.c:561
#define HAL_toggleLed
#define V_A_offset
ADC voltage offsets for A, B, and C phases.
Definition: user.h:132
#define I_A_offset
ADC current offsets for A, B, and C phases.
Definition: user.h:125
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.
CTRL_Obj ctrl
Defines the CTRL object.
Definition: proj_lab07.c:107
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)
USER_Params gUserParams
The user parameters.
Definition: proj_lab07.c:82
void FEM_setParams(FEM_Handle handle, const float_t timerFreq_Hz, const uint32_t timerPeriod_cnts, const float_t spFreq_Hz, const float_t maxError_Hz)
static void HAL_enablePwm(HAL_Handle handle)
void CTRL_setParams(CTRL_Handle handle, USER_Params *pUserParams)
#define _IQmpy(A, B)
USER_ErrorCode_e USER_getErrorCode(USER_Params *pUserParams)
Gets the error code in the user parameters.
static void FEM_run(FEM_Handle handle)
void HAL_enableDrv(HAL_Handle handle)
_iq VdcBus_kV
Definition: main.h:192
void EST_setRsOnLine_qFmt(EST_Handle handle, const uint_least8_t Rs_qFmt)
_iq Torque_Nm
Definition: main.h:165
_iq SpeedRef_krpm
Definition: main.h:157
uint16_t gLEDcnt
Definition: proj_lab07.c:110
_iq Ki_spd
Definition: main.h:183
void updateCPUusage(void)
Updates CPU usage.
Definition: proj_lab07.c:664
void HAL_setupDrvSpi(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
FEM_Obj fem
Definition: proj_lab07.c:89
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)
#define I_C_offset
Definition: user.h:127
float_t Flux_VpHz
Definition: main.h:173
bool Flag_enableUserParams
Definition: main.h:142
EST_State_e EST_getState(EST_Handle handle)
bool Flag_enableOffsetcalc
Definition: main.h:143
#define I_B_offset
Definition: user.h:126
float_t gCpuUsagePercentageAvg
Definition: proj_lab07.c:96
uint32_t gNumFreqErrors
Definition: proj_lab07.c:90
static bool FEM_isFreqError(FEM_Handle handle)
_iq gMaxCurrentSlope
Definition: proj_lab07.c:99
_iq CTRL_getKp(CTRL_Handle handle, const CTRL_Type_e ctrlType)
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
#define V_C_offset
Definition: user.h:134
void EST_setFlag_enableRsOnLine(EST_Handle handle, const bool state)
_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)
interrupt void mainISR(void)
The main interrupt service (ISR) routine.
Definition: proj_lab07.c:503
#define USER_CTRL_FREQ_Hz
Defines the controller frequency, Hz.
Definition: user.h:215
_iq Ki_Idq
Definition: main.h:186
static uint32_t HAL_readTimerCnt(HAL_Handle handle, const uint_least8_t timerNumber)
#define LED_BLINK_FREQ_Hz
Definition: proj_lab07.c:62
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
void CTRL_setFlag_enablePowerWarp(CTRL_Handle handle, const bool state)
void CPU_USAGE_setParams(CPU_USAGE_Handle handle, const uint32_t timerPeriod_cnts, const uint32_t numDeltaCntsAvg)
#define USER_ISR_FREQ_Hz
Defines the Interrupt Service Routine (ISR) frequency, Hz.
Definition: user.h:173
HAL_AdcData_t gAdcData
Defines the ADC data.
Definition: proj_lab07.c:86
CPU_USAGE_Handle CPU_USAGE_init(void *pMemory, const size_t numBytes)
bool CTRL_updateState(CTRL_Handle handle)
_iq CTRL_getKi(CTRL_Handle handle, const CTRL_Type_e ctrlType)
static void HAL_disablePwm(HAL_Handle handle)
_iq gFlux_pu_to_VpHz_sf
Definition: proj_lab07.c:138
bool EST_isMotorIdentified(EST_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 FEM_updateCnts(FEM_Handle handle, const uint32_t cnt)
static uint32_t CPU_USAGE_getMaxDeltaCntObserved(CPU_USAGE_Handle handle)
HAL_Handle halHandle
The hal handle.
Definition: proj_lab07.c:77
void CTRL_setFlag_enableDcBusComp(CTRL_Handle handle, const bool state)
static uint32_t FEM_getMaxDeltaCntObserved(FEM_Handle handle)
_iq EST_getMaxCurrentSlope_pu(EST_Handle handle)
void CTRL_setFlag_enableUserMotorParams(CTRL_Handle handle, const bool state)
_iq SpeedTraj_krpm
Definition: main.h:158
uint_least8_t EST_getRs_qFmt(EST_Handle handle)
#define USER_IQ_FULL_SCALE_CURRENT_A
Defines the full scale current for the IQ variables, A.
Definition: user.h:102
float_t MagnCurr_A
Definition: main.h:167
static void HAL_readAdcData(HAL_Handle handle, HAL_AdcData_t *pAdcData)
HAL_Obj hal
static _iq HAL_getBias(HAL_Handle handle, const HAL_SensorType_e sensorType, uint_least8_t sensorNumber)
volatile MOTOR_Vars_t gMotorVars
Definition: proj_lab07.c:112
static void CPU_USAGE_updateCnts(CPU_USAGE_Handle handle, const uint32_t cnt)
bool Flag_enableSys
Definition: main.h:136
_iq MaxAccel_krpmps
Definition: main.h:159
_iq CTRL_getSpd_int_ref_pu(CTRL_Handle handle)
CTRL_Handle ctrlHandle
The controller handle.
Definition: proj_lab07.c:72
static uint32_t CPU_USAGE_getMinDeltaCntObserved(CPU_USAGE_Handle handle)
CPU_USAGE_Obj cpu_usage
Definition: proj_lab07.c:94
MATH_vec3 I_bias
Definition: main.h:198
bool Flag_enableRsRecalc
Definition: main.h:141
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)
void CTRL_getVersion(CTRL_Handle handle, CTRL_Version *pVersion)
static uint16_t HAL_readPwmPeriod(HAL_Handle handle, const PWM_Number_e pwmNumber)
uint16_t minor
void updateKpKiGains(CTRL_Handle handle)
Updates Kp and Ki gains in the controller object.
Definition: proj_lab07.c:611
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)
static void CPU_USAGE_run(CPU_USAGE_Handle handle)
void EST_setRsOnLineId_pu(EST_Handle handle, const _iq Id_pu)
void runRsOnLine(CTRL_Handle handle)
Runs Rs online.
Definition: proj_lab07.c:630
void HAL_readDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
void USER_checkForErrors(USER_Params *pUserParams)
Checks for errors in the user parameter values.
FEM_Handle FEM_init(void *pMemory, const size_t numBytes)
CTRL_Obj * controller_obj
Definition: proj_lab10c.c:84
_iq Flux_Wb
Definition: main.h:164
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...
void CTRL_setSpd_ref_krpm(CTRL_Handle handle, const _iq spd_ref_krpm)
void main(void)
Definition: proj_lab07.c:147
_iq USER_computeFlux_pu_to_Wb_sf(void)
Computes the scale factor needed to convert from per unit to Wb.
FEM_Handle femHandle
Definition: proj_lab07.c:88
void CTRL_setKp(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Kp)
float float_t
#define USER_NUM_PWM_TICKS_PER_ISR_TICK
DECIMATION.
Definition: user.h:184