instaspin_foc
proj_lab05a.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 
115 #ifdef DRV8301_SPI
116 // Watch window interface to the 8301 SPI
117 DRV_SPI_8301_Vars_t gDrvSpi8301Vars;
118 #endif
119 
120 #ifdef DRV8305_SPI
121 // Watch window interface to the 8305 SPI
122 DRV_SPI_8305_Vars_t gDrvSpi8305Vars;
123 #endif
124 
126 
128 
130 
132 
133 // **************************************************************************
134 // the functions
135 
136 void main(void)
137 {
138  uint_least8_t estNumber = 0;
139 
140 #ifdef FAST_ROM_V1p6
141  uint_least8_t ctrlNumber = 0;
142 #endif
143 
144  // Only used if running from FLASH
145  // Note that the variable FLASH is defined by the project
146  #ifdef FLASH
147  // Copy time critical code and Flash setup code to RAM
148  // The RamfuncsLoadStart, RamfuncsLoadEnd, and RamfuncsRunStart
149  // symbols are created by the linker. Refer to the linker files.
150  memCopy((uint16_t *)&RamfuncsLoadStart,(uint16_t *)&RamfuncsLoadEnd,(uint16_t *)&RamfuncsRunStart);
151 
152  #ifdef F2802xF
153  //copy .econst to unsecure RAM
154  if(*econst_end - *econst_start)
155  {
156  memCopy((uint16_t *)&econst_start,(uint16_t *)&econst_end,(uint16_t *)&econst_ram_load);
157  }
158 
159  //copy .switch ot unsecure RAM
160  if(*switch_end - *switch_start)
161  {
162  memCopy((uint16_t *)&switch_start,(uint16_t *)&switch_end,(uint16_t *)&switch_ram_load);
163  }
164  #endif
165 
166  #endif
167 
168  // initialize the hardware abstraction layer
169  halHandle = HAL_init(&hal,sizeof(hal));
170 
171 
172  // check for errors in user parameters
173  USER_checkForErrors(&gUserParams);
174 
175 
176  // store user parameter error in global variable
177  gMotorVars.UserErrorCode = USER_getErrorCode(&gUserParams);
178 
179 
180  // do not allow code execution if there is a user parameter error
181  if(gMotorVars.UserErrorCode != USER_ErrorCode_NoError)
182  {
183  for(;;)
184  {
185  gMotorVars.Flag_enableSys = false;
186  }
187  }
188 
189 
190  // initialize the user parameters
191  USER_setParams(&gUserParams);
192 
193 
194  // set the hardware abstraction layer parameters
195  HAL_setParams(halHandle,&gUserParams);
196 
197 
198  // initialize the controller
199 #ifdef FAST_ROM_V1p6
200  ctrlHandle = CTRL_initCtrl(ctrlNumber, estNumber); //v1p6 format (06xF and 06xM devices)
201  controller_obj = (CTRL_Obj *)ctrlHandle;
202 #else
203  ctrlHandle = CTRL_initCtrl(estNumber,&ctrl,sizeof(ctrl)); //v1p7 format default
204 #endif
205 
206 
207  {
208  CTRL_Version version;
209 
210  // get the version number
211  CTRL_getVersion(ctrlHandle,&version);
212 
213  gMotorVars.CtrlVersion = version;
214  }
215 
216 
217  // set the default controller parameters
218  CTRL_setParams(ctrlHandle,&gUserParams);
219 
220 
221  // setup faults
222  HAL_setupFaults(halHandle);
223 
224 
225  // initialize the interrupt vector table
226  HAL_initIntVectorTable(halHandle);
227 
228 
229  // enable the ADC interrupts
230  HAL_enableAdcInts(halHandle);
231 
232 
233  // enable global interrupts
234  HAL_enableGlobalInts(halHandle);
235 
236 
237  // enable debug interrupts
238  HAL_enableDebugInt(halHandle);
239 
240 
241  // disable the PWM
242  HAL_disablePwm(halHandle);
243 
244 
245 #ifdef DRV8301_SPI
246  // turn on the DRV8301 if present
247  HAL_enableDrv(halHandle);
248  // initialize the DRV8301 interface
249  HAL_setupDrvSpi(halHandle,&gDrvSpi8301Vars);
250 #endif
251 
252 #ifdef DRV8305_SPI
253  // turn on the DRV8305 if present
254  HAL_enableDrv(halHandle);
255  // initialize the DRV8305 interface
256  HAL_setupDrvSpi(halHandle,&gDrvSpi8305Vars);
257 #endif
258 
259 
260  // enable DC bus compensation
261  CTRL_setFlag_enableDcBusComp(ctrlHandle, true);
262 
263 
264  // compute scaling factors for flux and torque calculations
269 
270 
271  for(;;)
272  {
273  // Waiting for enable system flag to be set
274  while(!(gMotorVars.Flag_enableSys));
275 
276  // Dis-able the Library internal PI. Iq has no reference now
277  CTRL_setFlag_enableSpeedCtrl(ctrlHandle, false);
278 
279  // loop while the enable system flag is true
280  while(gMotorVars.Flag_enableSys)
281  {
282  CTRL_Obj *obj = (CTRL_Obj *)ctrlHandle;
283 
284  // increment counters
286 
287  // enable/disable the use of motor parameters being loaded from user.h
289 
290  // enable/disable Rs recalibration during motor startup
292 
293  // enable/disable automatic calculation of bias values
294  CTRL_setFlag_enableOffset(ctrlHandle,gMotorVars.Flag_enableOffsetcalc);
295 
296 
297  if(CTRL_isError(ctrlHandle))
298  {
299  // set the enable controller flag to false
300  CTRL_setFlag_enableCtrl(ctrlHandle,false);
301 
302  // set the enable system flag to false
303  gMotorVars.Flag_enableSys = false;
304 
305  // disable the PWM
306  HAL_disablePwm(halHandle);
307  }
308  else
309  {
310  // update the controller state
311  bool flag_ctrlStateChanged = CTRL_updateState(ctrlHandle);
312 
313  // enable or disable the control
314  CTRL_setFlag_enableCtrl(ctrlHandle, gMotorVars.Flag_Run_Identify);
315 
316  if(flag_ctrlStateChanged)
317  {
318  CTRL_State_e ctrlState = CTRL_getState(ctrlHandle);
319 
320  if(ctrlState == CTRL_State_OffLine)
321  {
322  // enable the PWM
323  HAL_enablePwm(halHandle);
324  }
325  else if(ctrlState == CTRL_State_OnLine)
326  {
327  if(gMotorVars.Flag_enableOffsetcalc == true)
328  {
329  // update the ADC bias values
330  HAL_updateAdcBias(halHandle);
331  }
332  else
333  {
334  // set the current bias
335  HAL_setBias(halHandle,HAL_SensorType_Current,0,_IQ(I_A_offset));
336  HAL_setBias(halHandle,HAL_SensorType_Current,1,_IQ(I_B_offset));
337  HAL_setBias(halHandle,HAL_SensorType_Current,2,_IQ(I_C_offset));
338 
339  // set the voltage bias
340  HAL_setBias(halHandle,HAL_SensorType_Voltage,0,_IQ(V_A_offset));
341  HAL_setBias(halHandle,HAL_SensorType_Voltage,1,_IQ(V_B_offset));
342  HAL_setBias(halHandle,HAL_SensorType_Voltage,2,_IQ(V_C_offset));
343  }
344 
345  // Return the bias value for currents
346  gMotorVars.I_bias.value[0] = HAL_getBias(halHandle,HAL_SensorType_Current,0);
347  gMotorVars.I_bias.value[1] = HAL_getBias(halHandle,HAL_SensorType_Current,1);
348  gMotorVars.I_bias.value[2] = HAL_getBias(halHandle,HAL_SensorType_Current,2);
349 
350  // Return the bias value for voltages
351  gMotorVars.V_bias.value[0] = HAL_getBias(halHandle,HAL_SensorType_Voltage,0);
352  gMotorVars.V_bias.value[1] = HAL_getBias(halHandle,HAL_SensorType_Voltage,1);
353  gMotorVars.V_bias.value[2] = HAL_getBias(halHandle,HAL_SensorType_Voltage,2);
354 
355  // enable the PWM
356  HAL_enablePwm(halHandle);
357  }
358  else if(ctrlState == CTRL_State_Idle)
359  {
360  // disable the PWM
361  HAL_disablePwm(halHandle);
362  gMotorVars.Flag_Run_Identify = false;
363  }
364 
365  if((CTRL_getFlag_enableUserMotorParams(ctrlHandle) == true) &&
366  (ctrlState > CTRL_State_Idle) &&
367  (gMotorVars.CtrlVersion.minor == 6))
368  {
369  // call this function to fix 1p6
370  USER_softwareUpdate1p6(ctrlHandle);
371  }
372 
373  }
374  }
375 
376 
378  {
379  // set the current ramp
381  gMotorVars.Flag_MotorIdentified = true;
382 
383 
385  {
387 
388  USER_calcPIgains(ctrlHandle);
389 
390  // initialize the watch window kp and ki current values with pre-calculated values
391  gMotorVars.Kp_Idq = CTRL_getKp(ctrlHandle,CTRL_Type_PID_Id);
392  gMotorVars.Ki_Idq = CTRL_getKi(ctrlHandle,CTRL_Type_PID_Id);
393  }
394 
395  }
396  else
397  {
399 
400  // the estimator sets the maximum current slope during identification
402  }
403 
404 
405  // when appropriate, update the global variables
407  {
408  // reset the counter
410 
411  updateGlobalVariables_motor(ctrlHandle);
412  }
413 
414  // update Iq reference
415  updateIqRef(ctrlHandle);
416 
417  // update Kp and Ki gains
418  updateKpKiGains(ctrlHandle);
419 
420  // enable/disable the forced angle
422 
423  // enable or disable power warp
424  CTRL_setFlag_enablePowerWarp(ctrlHandle,gMotorVars.Flag_enablePowerWarp);
425 
426 #ifdef DRV8301_SPI
427  HAL_writeDrvData(halHandle,&gDrvSpi8301Vars);
428 
429  HAL_readDrvData(halHandle,&gDrvSpi8301Vars);
430 #endif
431 #ifdef DRV8305_SPI
432  HAL_writeDrvData(halHandle,&gDrvSpi8305Vars);
433 
434  HAL_readDrvData(halHandle,&gDrvSpi8305Vars);
435 #endif
436  } // end of while(gFlag_enableSys) loop
437 
438 
439  // disable the PWM
440  HAL_disablePwm(halHandle);
441 
442  // set the default controller parameters (Reset the control to re-identify the motor)
443  CTRL_setParams(ctrlHandle,&gUserParams);
444  gMotorVars.Flag_Run_Identify = false;
445 
446  } // end of for(;;) loop
447 
448 } // end of main() function
449 
450 
451 interrupt void mainISR(void)
452 {
453  // toggle status LED
454  if(gLEDcnt++ > (uint_least32_t)(USER_ISR_FREQ_Hz / LED_BLINK_FREQ_Hz))
455  {
456  HAL_toggleLed(halHandle,(GPIO_Number_e)HAL_Gpio_LED2);
457  gLEDcnt = 0;
458  }
459 
460 
461  // acknowledge the ADC interrupt
462  HAL_acqAdcInt(halHandle,ADC_IntNumber_1);
463 
464 
465  // convert the ADC data
466  HAL_readAdcData(halHandle,&gAdcData);
467 
468 
469  // run the controller
470  CTRL_run(ctrlHandle,halHandle,&gAdcData,&gPwmData);
471 
472 
473  // write the PWM compare values
474  HAL_writePwmData(halHandle,&gPwmData);
475 
476 
477  // setup the controller
478  CTRL_setup(ctrlHandle);
479 
480 
481  return;
482 } // end of mainISR() function
483 
484 
486 {
487  CTRL_Obj *obj = (CTRL_Obj *)handle;
488 
489  // get the speed estimate
490  gMotorVars.Speed_krpm = EST_getSpeed_krpm(obj->estHandle);
491 
492  // get the real time speed reference coming out of the speed trajectory generator
494 
495  // get the torque estimate
497 
498  // get the magnetizing current
499  gMotorVars.MagnCurr_A = EST_getIdRated(obj->estHandle);
500 
501  // get the rotor resistance
502  gMotorVars.Rr_Ohm = EST_getRr_Ohm(obj->estHandle);
503 
504  // get the stator resistance
505  gMotorVars.Rs_Ohm = EST_getRs_Ohm(obj->estHandle);
506 
507  // get the stator inductance in the direct coordinate direction
508  gMotorVars.Lsd_H = EST_getLs_d_H(obj->estHandle);
509 
510  // get the stator inductance in the quadrature coordinate direction
511  gMotorVars.Lsq_H = EST_getLs_q_H(obj->estHandle);
512 
513  // get the flux in V/Hz in floating point
514  gMotorVars.Flux_VpHz = EST_getFlux_VpHz(obj->estHandle);
515 
516  // get the flux in Wb in fixed point
517  gMotorVars.Flux_Wb = USER_computeFlux(handle, gFlux_pu_to_Wb_sf);
518 
519  // get the controller state
520  gMotorVars.CtrlState = CTRL_getState(handle);
521 
522  // get the estimator state
523  gMotorVars.EstState = EST_getState(obj->estHandle);
524 
525  // read Vd and Vq vectors per units
526  gMotorVars.Vd = CTRL_getVd_out_pu(ctrlHandle);
527  gMotorVars.Vq = CTRL_getVq_out_pu(ctrlHandle);
528 
529  // calculate vector Vs in per units
530  gMotorVars.Vs = _IQsqrt(_IQmpy(gMotorVars.Vd, gMotorVars.Vd) + _IQmpy(gMotorVars.Vq, gMotorVars.Vq));
531 
532  // read Id and Iq vectors in amps
533  gMotorVars.Id_A = _IQmpy(CTRL_getId_in_pu(ctrlHandle), _IQ(USER_IQ_FULL_SCALE_CURRENT_A));
534  gMotorVars.Iq_A = _IQmpy(CTRL_getIq_in_pu(ctrlHandle), _IQ(USER_IQ_FULL_SCALE_CURRENT_A));
535 
536  // calculate vector Is in amps
537  gMotorVars.Is_A = _IQsqrt(_IQmpy(gMotorVars.Id_A, gMotorVars.Id_A) + _IQmpy(gMotorVars.Iq_A, gMotorVars.Iq_A));
538 
539  // Get the DC buss voltage
540  gMotorVars.VdcBus_kV = _IQmpy(gAdcData.dcBus,_IQ(USER_IQ_FULL_SCALE_VOLTAGE_V/1000.0));
541 
542  return;
543 } // end of updateGlobalVariables_motor() function
544 
545 
547 {
548  _iq iq_ref = _IQmpy(gMotorVars.IqRef_A,_IQ(1.0/USER_IQ_FULL_SCALE_CURRENT_A));
549 
550  // set the speed reference so that the forced angle rotates in the correct direction for startup
551  if(_IQabs(gMotorVars.Speed_krpm) < _IQ(0.01))
552  {
553  if(iq_ref < _IQ(0.0))
554  {
555  CTRL_setSpd_ref_krpm(handle,_IQ(-0.01));
556  }
557  else if(iq_ref > _IQ(0.0))
558  {
559  CTRL_setSpd_ref_krpm(handle,_IQ(0.01));
560  }
561  }
562 
563  // Set the Iq reference that use to come out of the PI speed control
564  CTRL_setIq_ref_pu(handle, iq_ref);
565 
566  return;
567 } // end of updateIqRef() function
568 
569 
571 {
572  if((gMotorVars.CtrlState == CTRL_State_OnLine) && (gMotorVars.Flag_MotorIdentified == true) && (Flag_Latch_softwareUpdate == false))
573  {
574  // set the kp and ki current values for Id and Iq from the watch window
575  CTRL_setKp(handle,CTRL_Type_PID_Id,gMotorVars.Kp_Idq);
576  CTRL_setKi(handle,CTRL_Type_PID_Id,gMotorVars.Ki_Idq);
577  CTRL_setKp(handle,CTRL_Type_PID_Iq,gMotorVars.Kp_Idq);
578  CTRL_setKi(handle,CTRL_Type_PID_Iq,gMotorVars.Ki_Idq);
579  }
580 
581  return;
582 } // end of updateKpKiGains() function
583 
584 
586 // end of file
587 
588 
589 
float_t EST_getFlux_VpHz(EST_Handle handle)
void EST_setFlag_enableForceAngle(EST_Handle handle, const bool state)
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
_iq USER_computeFlux_pu_to_VpHz_sf(void)
Computes the scale factor needed to convert from per unit to V/Hz.
#define _IQ(A)
_iq gMaxCurrentSlope
Definition: proj_lab05a.c:88
_iq Iq_A
Definition: main.h:195
bool Flag_Run_Identify
Definition: main.h:137
_iq EST_getSpeed_krpm(EST_Handle handle)
bool Flag_Latch_softwareUpdate
Definition: proj_lab05a.c:70
void USER_calcPIgains(CTRL_Handle handle)
Updates Id and Iq PI gains.
void main(void)
Definition: proj_lab05a.c:136
CTRL_State_e CtrlState
Definition: main.h:147
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
_iq CTRL_getId_in_pu(CTRL_Handle handle)
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.
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 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)
void CTRL_setFlag_enableSpeedCtrl(CTRL_Handle handle, const bool state)
HAL_PwmData_t gPwmData
Defines the PWM data.
Definition: proj_lab05a.c:84
_iq gFlux_pu_to_Wb_sf
Definition: proj_lab05a.c:125
CTRL_Handle ctrlHandle
The controller handle.
Definition: proj_lab05a.c:72
#define V_B_offset
Definition: user.h:133
HAL_Handle halHandle
The hal handle.
Definition: proj_lab05a.c:77
long _iq
void USER_setParams(USER_Params *pUserParams)
Sets the user parameter values.
EST_State_e EstState
Definition: main.h:148
float_t Rs_Ohm
Definition: main.h:169
#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.
_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)
_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)
_iq CTRL_getIq_in_pu(CTRL_Handle handle)
static void HAL_enablePwm(HAL_Handle handle)
void CTRL_setParams(CTRL_Handle handle, USER_Params *pUserParams)
#define _IQmpy(A, B)
uint_least16_t gCounter_updateGlobals
A counter that is denotes when to update the global variables.
Definition: proj_lab05a.c:68
void updateGlobalVariables_motor(CTRL_Handle handle)
Updates the global motor variables.
Definition: proj_lab05a.c:485
USER_ErrorCode_e USER_getErrorCode(USER_Params *pUserParams)
Gets the error code in the user parameters.
void HAL_enableDrv(HAL_Handle handle)
_iq IqRef_A
Definition: main.h:155
_iq VdcBus_kV
Definition: main.h:192
_iq Torque_Nm
Definition: main.h:165
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
bool Flag_enableUserParams
Definition: main.h:142
EST_State_e EST_getState(EST_Handle handle)
#define LED_BLINK_FREQ_Hz
Definition: proj_lab05a.c:62
bool Flag_enableOffsetcalc
Definition: main.h:143
#define I_B_offset
Definition: user.h:126
_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
_iq CTRL_getVd_out_pu(CTRL_Handle handle)
_iq gFlux_pu_to_VpHz_sf
Definition: proj_lab05a.c:127
CTRL_State_e
CTRL_Obj ctrl
Defines the CTRL object.
Definition: proj_lab05a.c:96
#define _IQabs(A)
#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)
_iq Is_A
Definition: main.h:196
USER_Params gUserParams
The user parameters.
Definition: proj_lab05a.c:82
_iq Ki_Idq
Definition: main.h:186
HAL_AdcData_t gAdcData
Defines the ADC data.
Definition: proj_lab05a.c:86
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)
#define USER_ISR_FREQ_Hz
Defines the Interrupt Service Routine (ISR) frequency, Hz.
Definition: user.h:173
bool CTRL_updateState(CTRL_Handle handle)
_iq CTRL_getKi(CTRL_Handle handle, const CTRL_Type_e ctrlType)
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)
void CTRL_setFlag_enableDcBusComp(CTRL_Handle handle, const bool state)
#define _IQsqrt(A)
interrupt void mainISR(void)
The main interrupt service (ISR) routine.
Definition: proj_lab05a.c:451
_iq EST_getMaxCurrentSlope_pu(EST_Handle handle)
void CTRL_setFlag_enableUserMotorParams(CTRL_Handle handle, const bool state)
_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
float_t MagnCurr_A
Definition: main.h:167
_iq gTorque_Flux_Iq_pu_to_Nm_sf
Definition: proj_lab05a.c:131
static void HAL_readAdcData(HAL_Handle handle, HAL_AdcData_t *pAdcData)
HAL_Obj hal
volatile MOTOR_Vars_t gMotorVars
Definition: proj_lab05a.c:101
void updateIqRef(CTRL_Handle handle)
Updates Iq reference and also sets the right sign to the speed reference for correct force angle...
Definition: proj_lab05a.c:546
void CTRL_setIq_ref_pu(CTRL_Handle handle, const _iq IqRef_pu)
void updateKpKiGains(CTRL_Handle handle)
Updates Kp and Ki gains in the controller object.
Definition: proj_lab05a.c:570
static _iq HAL_getBias(HAL_Handle handle, const HAL_SensorType_e sensorType, uint_least8_t sensorNumber)
bool Flag_enableSys
Definition: main.h:136
_iq Id_A
Definition: main.h:194
_iq CTRL_getSpd_int_ref_pu(CTRL_Handle handle)
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)
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)
uint16_t gLEDcnt
Definition: proj_lab05a.c:99
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.
CTRL_Obj * controller_obj
Definition: proj_lab10c.c:84
_iq CTRL_getVq_out_pu(CTRL_Handle handle)
_iq Flux_Wb
Definition: main.h:164
GPIO_Number_e
_iq gTorque_Ls_Id_Iq_pu_to_Nm_sf
Definition: proj_lab05a.c:129
_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.
void CTRL_setKp(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Kp)