instaspin_foc
proj_lab03b.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--*/
37 
39 
40 
45 
46 // **************************************************************************
47 // the includes
48 
49 // system includes
50 #include <math.h>
51 #include "main.h"
52 
53 #ifdef FLASH
54 #pragma CODE_SECTION(mainISR,"ramfuncs");
55 #endif
56 
57 // Include header files used in the main function
58 
59 
60 // **************************************************************************
61 // the defines
62 
63 #define LED_BLINK_FREQ_Hz 5
64 
65 
66 // **************************************************************************
67 // the globals
68 
69 uint_least16_t gCounter_updateGlobals = 0;
70 
72 
74 
75 #ifdef F2802xF
76 #pragma DATA_SECTION(halHandle,"rom_accessed_data");
77 #endif
79 
80 #ifdef F2802xF
81 #pragma DATA_SECTION(gUserParams,"rom_accessed_data");
82 #endif
84 
85 HAL_PwmData_t gPwmData = {_IQ(0.0), _IQ(0.0), _IQ(0.0)};
86 
88 
91 uint32_t gNumFreqErrors = 0;
92 uint32_t gMaxDeltaCntObserved = 0;
93 
99 
101 
102 #ifdef FAST_ROM_V1p6
104 #else
105 #ifdef F2802xF
106 #pragma DATA_SECTION(ctrl,"rom_accessed_data");
107 #endif
108 CTRL_Obj ctrl; //v1p7 format
109 #endif
110 
111 uint16_t gLEDcnt = 0;
112 
114 
115 #ifdef FLASH
116 // Used for running BackGround in flash, and ISR in RAM
117 extern uint16_t *RamfuncsLoadStart, *RamfuncsLoadEnd, *RamfuncsRunStart;
118 
119 #ifdef F2802xF
120 extern uint16_t *econst_start, *econst_end, *econst_ram_load;
121 extern uint16_t *switch_start, *switch_end, *switch_ram_load;
122 #endif
123 
124 #endif
125 
126 
127 #ifdef DRV8301_SPI
128 // Watch window interface to the 8301 SPI
129 DRV_SPI_8301_Vars_t gDrvSpi8301Vars;
130 #endif
131 
132 #ifdef DRV8305_SPI
133 // Watch window interface to the 8305 SPI
134 DRV_SPI_8305_Vars_t gDrvSpi8305Vars;
135 #endif
136 
138 
140 
142 
144 
145 // **************************************************************************
146 // the functions
147 
148 void main(void)
149 {
150  uint_least8_t estNumber = 0;
151 
152 #ifdef FAST_ROM_V1p6
153  uint_least8_t ctrlNumber = 0;
154 #endif
155 
156  // Only used if running from FLASH
157  // Note that the variable FLASH is defined by the project
158  #ifdef FLASH
159  // Copy time critical code and Flash setup code to RAM
160  // The RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart
161  // symbols are created by the linker. Refer to the linker files.
162  memCopy((uint16_t *)&RamfuncsLoadStart,(uint16_t *)&RamfuncsLoadEnd,(uint16_t *)&RamfuncsRunStart);
163 
164  #ifdef F2802xF
165  //copy .econst to unsecure RAM
166  if(*econst_end - *econst_start)
167  {
168  memCopy((uint16_t *)&econst_start,(uint16_t *)&econst_end,(uint16_t *)&econst_ram_load);
169  }
170 
171  //copy .switch ot unsecure RAM
172  if(*switch_end - *switch_start)
173  {
174  memCopy((uint16_t *)&switch_start,(uint16_t *)&switch_end,(uint16_t *)&switch_ram_load);
175  }
176  #endif
177 
178  #endif
179 
180  // initialize the hardware abstraction layer
181  halHandle = HAL_init(&hal,sizeof(hal));
182 
183 
184  // check for errors in user parameters
185  USER_checkForErrors(&gUserParams);
186 
187 
188  // store user parameter error in global variable
189  gMotorVars.UserErrorCode = USER_getErrorCode(&gUserParams);
190 
191 
192  // do not allow code execution if there is a user parameter error
193  if(gMotorVars.UserErrorCode != USER_ErrorCode_NoError)
194  {
195  for(;;)
196  {
197  gMotorVars.Flag_enableSys = false;
198  }
199  }
200 
201 
202  // initialize the user parameters
203  USER_setParams(&gUserParams);
204 
205 
206  // set the hardware abstraction layer parameters
207  HAL_setParams(halHandle,&gUserParams);
208 
209 
210  // initialize the controller
211 #ifdef FAST_ROM_V1p6
212  ctrlHandle = CTRL_initCtrl(ctrlNumber, estNumber); //v1p6 format (06xF and 06xM devices)
213  controller_obj = (CTRL_Obj *)ctrlHandle;
214 #else
215  ctrlHandle = CTRL_initCtrl(estNumber,&ctrl,sizeof(ctrl)); //v1p7 format default
216 #endif
217 
218 
219  {
220  CTRL_Version version;
221 
222  // get the version number
223  CTRL_getVersion(ctrlHandle,&version);
224 
225  gMotorVars.CtrlVersion = version;
226  }
227 
228 
229  // set the default controller parameters
230  CTRL_setParams(ctrlHandle,&gUserParams);
231 
232 
233  // initialize the frequency of execution monitoring module
234  femHandle = FEM_init(&fem,sizeof(fem));
235  FEM_setParams(femHandle,
236  USER_SYSTEM_FREQ_MHz * 1000000.0, // timer frequency, Hz
237  (uint32_t)USER_SYSTEM_FREQ_MHz * 1000000, // timer period, cnts
238  USER_CTRL_FREQ_Hz, // set point frequency, Hz
239  1000.0); // max frequency error, Hz
240 
241 
242  // initialize the CPU usage module
243  cpu_usageHandle = CPU_USAGE_init(&cpu_usage,sizeof(cpu_usage));
244  CPU_USAGE_setParams(cpu_usageHandle,
245  (uint32_t)USER_SYSTEM_FREQ_MHz * 1000000, // timer period, cnts
246  (uint32_t)USER_ISR_FREQ_Hz); // average over 1 second of ISRs
247 
248 
249  // setup faults
250  HAL_setupFaults(halHandle);
251 
252 
253  // initialize the interrupt vector table
254  HAL_initIntVectorTable(halHandle);
255 
256 
257  // enable the ADC interrupts
258  HAL_enableAdcInts(halHandle);
259 
260 
261  // reload timer to start running frequency of execution monitoring
262  HAL_reloadTimer(halHandle,0);
263 
264 
265  // enable global interrupts
266  HAL_enableGlobalInts(halHandle);
267 
268 
269  // enable debug interrupts
270  HAL_enableDebugInt(halHandle);
271 
272 
273  // disable the PWM
274  HAL_disablePwm(halHandle);
275 
276 
277 #ifdef DRV8301_SPI
278  // turn on the DRV8301 if present
279  HAL_enableDrv(halHandle);
280  // initialize the DRV8301 interface
281  HAL_setupDrvSpi(halHandle,&gDrvSpi8301Vars);
282 #endif
283 
284 #ifdef DRV8305_SPI
285  // turn on the DRV8305 if present
286  HAL_enableDrv(halHandle);
287  // initialize the DRV8305 interface
288  HAL_setupDrvSpi(halHandle,&gDrvSpi8305Vars);
289 #endif
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  // disable offsets recalibration by default
303  gMotorVars.Flag_enableOffsetcalc = false;
304 
305 
306  for(;;)
307  {
308  // Waiting for enable system flag to be set
309  while(!(gMotorVars.Flag_enableSys));
310 
311  // loop while the enable system flag is true
312  while(gMotorVars.Flag_enableSys)
313  {
314  CTRL_Obj *obj = (CTRL_Obj *)ctrlHandle;
315 
316  // increment counters
318 
319  // enable/disable the use of motor parameters being loaded from user.h
321 
322  // enable/disable Rs recalibration during motor startup
324 
325  // enable/disable automatic calculation of bias values
326  CTRL_setFlag_enableOffset(ctrlHandle,gMotorVars.Flag_enableOffsetcalc);
327 
328 
329  if(CTRL_isError(ctrlHandle))
330  {
331  // set the enable controller flag to false
332  CTRL_setFlag_enableCtrl(ctrlHandle,false);
333 
334  // set the enable system flag to false
335  gMotorVars.Flag_enableSys = false;
336 
337  // disable the PWM
338  HAL_disablePwm(halHandle);
339  }
340  else
341  {
342  // update the controller state
343  bool flag_ctrlStateChanged = CTRL_updateState(ctrlHandle);
344 
345  // enable or disable the control
346  CTRL_setFlag_enableCtrl(ctrlHandle, gMotorVars.Flag_Run_Identify);
347 
348  if(flag_ctrlStateChanged)
349  {
350  CTRL_State_e ctrlState = CTRL_getState(ctrlHandle);
351 
352  if(ctrlState == CTRL_State_OffLine)
353  {
354  // enable the PWM
355  HAL_enablePwm(halHandle);
356  }
357  else if(ctrlState == CTRL_State_OnLine)
358  {
359  if(gMotorVars.Flag_enableOffsetcalc == true)
360  {
361  // update the ADC bias values
362  HAL_updateAdcBias(halHandle);
363  }
364  else
365  {
366  // set the current bias
367  HAL_setBias(halHandle,HAL_SensorType_Current,0,_IQ(I_A_offset));
368  HAL_setBias(halHandle,HAL_SensorType_Current,1,_IQ(I_B_offset));
369  HAL_setBias(halHandle,HAL_SensorType_Current,2,_IQ(I_C_offset));
370 
371  // set the voltage bias
372  HAL_setBias(halHandle,HAL_SensorType_Voltage,0,_IQ(V_A_offset));
373  HAL_setBias(halHandle,HAL_SensorType_Voltage,1,_IQ(V_B_offset));
374  HAL_setBias(halHandle,HAL_SensorType_Voltage,2,_IQ(V_C_offset));
375  }
376 
377  // Return the bias value for currents
378  gMotorVars.I_bias.value[0] = HAL_getBias(halHandle,HAL_SensorType_Current,0);
379  gMotorVars.I_bias.value[1] = HAL_getBias(halHandle,HAL_SensorType_Current,1);
380  gMotorVars.I_bias.value[2] = HAL_getBias(halHandle,HAL_SensorType_Current,2);
381 
382  // Return the bias value for voltages
383  gMotorVars.V_bias.value[0] = HAL_getBias(halHandle,HAL_SensorType_Voltage,0);
384  gMotorVars.V_bias.value[1] = HAL_getBias(halHandle,HAL_SensorType_Voltage,1);
385  gMotorVars.V_bias.value[2] = HAL_getBias(halHandle,HAL_SensorType_Voltage,2);
386 
387  // enable the PWM
388  HAL_enablePwm(halHandle);
389  }
390  else if(ctrlState == CTRL_State_Idle)
391  {
392  // disable the PWM
393  HAL_disablePwm(halHandle);
394  gMotorVars.Flag_Run_Identify = false;
395  }
396 
397  if((CTRL_getFlag_enableUserMotorParams(ctrlHandle) == true) &&
398  (ctrlState > CTRL_State_Idle) &&
399  (gMotorVars.CtrlVersion.minor == 6))
400  {
401  // call this function to fix 1p6
402  USER_softwareUpdate1p6(ctrlHandle);
403  }
404 
405  }
406  }
407 
408 
410  {
411  // set the current ramp
413  gMotorVars.Flag_MotorIdentified = true;
414 
415  // set the speed reference
416  CTRL_setSpd_ref_krpm(ctrlHandle,gMotorVars.SpeedRef_krpm);
417 
418  // set the speed acceleration
420 
422  {
424 
425  USER_calcPIgains(ctrlHandle);
426  }
427 
428  }
429  else
430  {
432 
433  // the estimator sets the maximum current slope during identification
435  }
436 
437 
438  // when appropriate, update the global variables
440  {
441  // reset the counter
443 
444  updateGlobalVariables_motor(ctrlHandle);
445  }
446 
447  // get the maximum delta count observed
449 
450  // check for errors
451  if(FEM_isFreqError(femHandle))
452  {
453  gNumFreqErrors = FEM_getErrorCnt(femHandle);
454  }
455 
456  // update CPU usage
457  updateCPUusage();
458 
459  // enable/disable the forced angle
461 
462  // enable or disable power warp
463  CTRL_setFlag_enablePowerWarp(ctrlHandle,gMotorVars.Flag_enablePowerWarp);
464 
465 #ifdef DRV8301_SPI
466  HAL_writeDrvData(halHandle,&gDrvSpi8301Vars);
467 
468  HAL_readDrvData(halHandle,&gDrvSpi8301Vars);
469 #endif
470 #ifdef DRV8305_SPI
471  HAL_writeDrvData(halHandle,&gDrvSpi8305Vars);
472 
473  HAL_readDrvData(halHandle,&gDrvSpi8305Vars);
474 #endif
475  } // end of while(gFlag_enableSys) loop
476 
477 
478  // disable the PWM
479  HAL_disablePwm(halHandle);
480 
481  // set the default controller parameters (Reset the control to re-identify the motor)
482  CTRL_setParams(ctrlHandle,&gUserParams);
483  gMotorVars.Flag_Run_Identify = false;
484 
485  } // end of for(;;) loop
486 
487 } // end of main() function
488 
489 
490 interrupt void mainISR(void)
491 {
492  uint32_t timer0Cnt;
493  uint32_t timer1Cnt;
494 
495 
496  // read the timer 1 value and update the CPU usage module
497  timer1Cnt = HAL_readTimerCnt(halHandle,1);
498  CPU_USAGE_updateCnts(cpu_usageHandle,timer1Cnt);
499 
500 
501  // read the timer 0 value and update the FEM
502  timer0Cnt = HAL_readTimerCnt(halHandle,0);
503  FEM_updateCnts(femHandle,timer0Cnt);
504  FEM_run(femHandle);
505 
506 
507  // toggle status LED
508  if(gLEDcnt++ > (uint_least32_t)(USER_ISR_FREQ_Hz / LED_BLINK_FREQ_Hz))
509  {
510  HAL_toggleLed(halHandle,(GPIO_Number_e)HAL_Gpio_LED2);
511  gLEDcnt = 0;
512  }
513 
514 
515  // acknowledge the ADC interrupt
516  HAL_acqAdcInt(halHandle,ADC_IntNumber_1);
517 
518 
519  // convert the ADC data
520  HAL_readAdcData(halHandle,&gAdcData);
521 
522 
523  // run the controller
524  CTRL_run(ctrlHandle,halHandle,&gAdcData,&gPwmData);
525 
526 
527  // write the PWM compare values
528  HAL_writePwmData(halHandle,&gPwmData);
529 
530 
531  // setup the controller
532  CTRL_setup(ctrlHandle);
533 
534 
535  // read the timer 1 value and update the CPU usage module
536  timer1Cnt = HAL_readTimerCnt(halHandle,1);
537  CPU_USAGE_updateCnts(cpu_usageHandle,timer1Cnt);
538 
539 
540  // run the CPU usage module
541  CPU_USAGE_run(cpu_usageHandle);
542 
543 
544  return;
545 } // end of mainISR() function
546 
547 
549 {
550  CTRL_Obj *obj = (CTRL_Obj *)handle;
551 
552  // get the speed estimate
553  gMotorVars.Speed_krpm = EST_getSpeed_krpm(obj->estHandle);
554 
555  // get the real time speed reference coming out of the speed trajectory generator
557 
558  // get the torque estimate
560 
561  // get the magnetizing current
562  gMotorVars.MagnCurr_A = EST_getIdRated(obj->estHandle);
563 
564  // get the rotor resistance
565  gMotorVars.Rr_Ohm = EST_getRr_Ohm(obj->estHandle);
566 
567  // get the stator resistance
568  gMotorVars.Rs_Ohm = EST_getRs_Ohm(obj->estHandle);
569 
570  // get the stator inductance in the direct coordinate direction
571  gMotorVars.Lsd_H = EST_getLs_d_H(obj->estHandle);
572 
573  // get the stator inductance in the quadrature coordinate direction
574  gMotorVars.Lsq_H = EST_getLs_q_H(obj->estHandle);
575 
576  // get the flux in V/Hz in floating point
577  gMotorVars.Flux_VpHz = EST_getFlux_VpHz(obj->estHandle);
578 
579  // get the flux in Wb in fixed point
580  gMotorVars.Flux_Wb = USER_computeFlux(handle, gFlux_pu_to_Wb_sf);
581 
582  // get the controller state
583  gMotorVars.CtrlState = CTRL_getState(handle);
584 
585  // get the estimator state
586  gMotorVars.EstState = EST_getState(obj->estHandle);
587 
588  // Get the DC buss voltage
589  gMotorVars.VdcBus_kV = _IQmpy(gAdcData.dcBus,_IQ(USER_IQ_FULL_SCALE_VOLTAGE_V/1000.0));
590 
591  return;
592 } // end of updateGlobalVariables_motor() function
593 
594 
595 void updateCPUusage(void)
596 {
597  uint32_t minDeltaCntObserved = CPU_USAGE_getMinDeltaCntObserved(cpu_usageHandle);
598  uint32_t avgDeltaCntObserved = CPU_USAGE_getAvgDeltaCntObserved(cpu_usageHandle);
599  uint32_t maxDeltaCntObserved = CPU_USAGE_getMaxDeltaCntObserved(cpu_usageHandle);
600  uint16_t pwmPeriod = HAL_readPwmPeriod(halHandle,PWM_Number_1);
601  float_t cpu_usage_den = (float_t)pwmPeriod * (float_t)USER_NUM_PWM_TICKS_PER_ISR_TICK * 2.0;
602 
603  // calculate the minimum cpu usage percentage
604  gCpuUsagePercentageMin = (float_t)minDeltaCntObserved / cpu_usage_den * 100.0;
605 
606  // calculate the average cpu usage percentage
607  gCpuUsagePercentageAvg = (float_t)avgDeltaCntObserved / cpu_usage_den * 100.0;
608 
609  // calculate the maximum cpu usage percentage
610  gCpuUsagePercentageMax = (float_t)maxDeltaCntObserved / cpu_usage_den * 100.0;
611 
612  return;
613 } // end of updateCPUusage() function
614 
615 
617 // end of file
618 
619 
620 
float_t EST_getFlux_VpHz(EST_Handle handle)
#define USER_SYSTEM_FREQ_MHz
CLOCKS & TIMERS.
Definition: user.h:140
void EST_setFlag_enableForceAngle(EST_Handle handle, const bool state)
void main(void)
Definition: proj_lab03b.c:148
uint32_t gNumFreqErrors
Definition: proj_lab03b.c:91
#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 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 HAL_reloadTimer(HAL_Handle handle, const uint_least8_t timerNumber)
HAL_Handle halHandle
The hal handle.
Definition: proj_lab03b.c:78
_iq USER_computeFlux_pu_to_VpHz_sf(void)
Computes the scale factor needed to convert from per unit to V/Hz.
#define _IQ(A)
uint16_t gLEDcnt
Definition: proj_lab03b.c:111
bool Flag_Run_Identify
Definition: main.h:137
_iq EST_getSpeed_krpm(EST_Handle handle)
bool Flag_Latch_softwareUpdate
Definition: proj_lab03b.c:71
void USER_calcPIgains(CTRL_Handle handle)
Updates Id and Iq PI gains.
CTRL_State_e CtrlState
Definition: main.h:147
float_t gCpuUsagePercentageMax
Definition: proj_lab03b.c:98
HAL_PwmData_t gPwmData
Defines the PWM data.
Definition: proj_lab03b.c:85
CTRL_Handle ctrlHandle
The controller handle.
Definition: proj_lab03b.c:73
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]
_iq gTorque_Ls_Id_Iq_pu_to_Nm_sf
Definition: proj_lab03b.c:141
#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)
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
void memCopy(uint16_t *srcStartAddr, uint16_t *srcEndAddr, uint16_t *dstAddr)
EST_Handle estHandle
void updateCPUusage(void)
Updates CPU usage.
Definition: proj_lab03b.c:595
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)
#define V_B_offset
Definition: user.h:133
long _iq
_iq gFlux_pu_to_Wb_sf
Definition: proj_lab03b.c:137
_iq gMaxCurrentSlope
Definition: proj_lab03b.c:100
void USER_setParams(USER_Params *pUserParams)
Sets the user parameter values.
EST_State_e EstState
Definition: main.h:148
FEM_Handle femHandle
Definition: proj_lab03b.c:89
float_t Rs_Ohm
Definition: main.h:169
CPU_USAGE_Handle cpu_usageHandle
Definition: proj_lab03b.c:94
#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.
void HAL_setupFaults(HAL_Handle handle)
float_t EST_getLs_d_H(EST_Handle handle)
void EST_setFlag_enableRsRecalc(EST_Handle handle, const bool state)
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)
#define LED_BLINK_FREQ_Hz
Definition: proj_lab03b.c:63
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
CTRL_Obj ctrl
Defines the CTRL object.
Definition: proj_lab03b.c:108
_iq Torque_Nm
Definition: main.h:165
_iq SpeedRef_krpm
Definition: main.h:157
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)
#define I_C_offset
Definition: user.h:127
float_t Flux_VpHz
Definition: main.h:173
uint_least16_t gCounter_updateGlobals
A counter that is denotes when to update the global variables.
Definition: proj_lab03b.c:69
void updateGlobalVariables_motor(CTRL_Handle handle)
Updates the global motor variables.
Definition: proj_lab03b.c:548
bool Flag_enableUserParams
Definition: main.h:142
CPU_USAGE_Obj cpu_usage
Definition: proj_lab03b.c:95
USER_Params gUserParams
The user parameters.
Definition: proj_lab03b.c:83
EST_State_e EST_getState(EST_Handle handle)
bool Flag_enableOffsetcalc
Definition: main.h:143
#define I_B_offset
Definition: user.h:126
_iq gFlux_pu_to_VpHz_sf
Definition: proj_lab03b.c:139
static bool FEM_isFreqError(FEM_Handle handle)
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
_iq gTorque_Flux_Iq_pu_to_Nm_sf
Definition: proj_lab03b.c:143
CTRL_State_e
FEM_Obj fem
Definition: proj_lab03b.c:90
#define V_C_offset
Definition: user.h:134
_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)
float_t gCpuUsagePercentageAvg
Definition: proj_lab03b.c:97
#define USER_CTRL_FREQ_Hz
Defines the controller frequency, Hz.
Definition: user.h:215
uint32_t gMaxDeltaCntObserved
Definition: proj_lab03b.c:92
static uint32_t HAL_readTimerCnt(HAL_Handle handle, const uint_least8_t timerNumber)
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
CPU_USAGE_Handle CPU_USAGE_init(void *pMemory, const size_t numBytes)
bool CTRL_updateState(CTRL_Handle handle)
static void HAL_disablePwm(HAL_Handle handle)
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)
void CTRL_setFlag_enableDcBusComp(CTRL_Handle handle, const bool state)
float_t gCpuUsagePercentageMin
Definition: proj_lab03b.c:96
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
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)
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)
static uint32_t CPU_USAGE_getMinDeltaCntObserved(CPU_USAGE_Handle handle)
HAL_AdcData_t gAdcData
Defines the ADC data.
Definition: proj_lab03b.c:87
MATH_vec3 I_bias
Definition: main.h:198
bool Flag_enableRsRecalc
Definition: main.h:141
static void HAL_initIntVectorTable(HAL_Handle handle)
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
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 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
interrupt void mainISR(void)
The main interrupt service (ISR) routine.
Definition: proj_lab03b.c:490
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)
_iq USER_computeFlux_pu_to_Wb_sf(void)
Computes the scale factor needed to convert from per unit to Wb.
float float_t
#define USER_NUM_PWM_TICKS_PER_ISR_TICK
DECIMATION.
Definition: user.h:184
volatile MOTOR_Vars_t gMotorVars
Definition: proj_lab03b.c:113