instaspin_foc
fast_obs_pm_rs.c
Go to the documentation of this file.
1 
7 
8 // **************************************************************************
9 
10 // solutions
11 #include "fast_obs.h"
12 
13 
14 // **************************************************************************
15 // the defines
16 
17 
18 // **************************************************************************
19 // the globals
20 
21 EST_State_e gEstState = EST_State_Idle;
22 
23 volatile bool gFlag_enableSys = true;
24 
25 volatile bool gFlag_runOnLine = false;
26 
27 volatile bool gFlag_enableForceAngle = true;
28 
29 volatile bool gFlag_enableRsRecalc = true;
30 
32 
34 
36 
38 
40 
42 
43 volatile float_t gSpeed_Kp = 0.01;
44 
45 volatile float_t gSpeed_Ki = 0.001;
46 
47 volatile float_t gId_ref_A = 0.0;
48 
50 
52 
53 uint16_t gCounter_speed = 0;
54 
56 
58 
60 
62 
64 
66 
68 
69 MATH_vec3 gOffsets_I_A = {0.0, 0.0, 0.0};
70 
71 MATH_vec3 gOffsets_V_V = {0.0, 0.0, 0.0};
72 
75 
78 
81 
83 
86 
89 
92 
95 
98 
101 
102 #ifdef DRV8301_SPI
103 // Watch window interface to the 8301 SPI
104 DRV_SPI_8301_Vars_t gDrvSpi8301Vars;
105 #endif
106 
112 
113 // **************************************************************************
114 // the functions
115 
116 void main(void)
117 {
118  uint_least8_t estNumber = 0;
119 
120  // initialize the user parameters
121  USER_setParams(&gUserParams);
122 
123  // initialize the user parameters
124  USER_setParams_priv(&gUserParams);
125 
126  // initialize the driver
127  halHandle = HAL_init(&hal,sizeof(hal));
128 
129  // set the driver parameters
130  HAL_setParams(halHandle,&gUserParams);
131 
132  // initialize the Clarke modules
133  clarkeHandle_I = CLARKE_init(&clarke_I,sizeof(clarke_I));
134  clarkeHandle_V = CLARKE_init(&clarke_V,sizeof(clarke_V));
135 
136  // set the Clarke parameters
137  setupClarke_I(clarkeHandle_I,gUserParams.numCurrentSensors);
138  setupClarke_V(clarkeHandle_V,gUserParams.numVoltageSensors);
139 
140  // initialize the estimator
141  estHandle = EST_initEst(estNumber);
142 
143  // set the default estimator parameters
144  EST_setParams(estHandle,&gUserParams);
147 
148  // initialize the inverse Park module
149  iparkHandle = IPARK_init(&ipark,sizeof(ipark));
150 
151  // initialize the Park module
152  parkHandle = PARK_init(&park,sizeof(park));
153 
154  // initialize the PI controllers
155  piHandle_Id = PI_init(&pi_Id, sizeof(pi_Id));
156  piHandle_Iq = PI_init(&pi_Iq, sizeof(pi_Iq));
157  piHandle_spd = PI_init(&pi_spd,sizeof(pi_spd));
158 
159  // setup the controllers
161 
162  // initialize the space vector generator module
163  svgenHandle = SVGEN_init(&svgen,sizeof(svgen));
164 
165  // initialize the CPU usage module
166  cpu_usageHandle = CPU_USAGE_init(&cpu_usage,sizeof(cpu_usage));
167  CPU_USAGE_setParams(cpu_usageHandle,
168  (uint32_t)USER_SYSTEM_FREQ_MHz * 1000000, // timer period, cnts
169  (uint32_t)USER_ISR_FREQ_Hz); // average over 1 second of ISRs
170 
171  // setup faults
172  HAL_setupFaults(halHandle);
173 
174  // initialize the interrupt vector table
175  HAL_initIntVectorTable(halHandle);
176 
177  // enable the ADC interrupts
178  HAL_enableAdcInts(halHandle);
179 
180  // disable global interrupts
181  HAL_disableGlobalInts(halHandle);
182 
183  // enable debug interrupts
184  HAL_enableDebugInt(halHandle);
185 
186  // disable the PWM
187  HAL_disablePwm(halHandle);
188 
189  // set adcBias values
190  gOffsets_I_A.value[0] = IA_OFFSET_A;
191  gOffsets_I_A.value[1] = IB_OFFSET_A;
192  gOffsets_I_A.value[2] = IC_OFFSET_A;
193  gOffsets_V_V.value[0] = VA_OFFSET_V;
194  gOffsets_V_V.value[1] = VB_OFFSET_V;
195  gOffsets_V_V.value[2] = VC_OFFSET_V;
196 
197 #ifdef DRV8301_SPI
198  // turn on the DRV8301 if present
199  HAL_enableDrv(halHandle);
200  // initialize the DRV8301 interface
201  HAL_setupDrvSpi(halHandle,&gDrvSpi8301Vars);
202 #endif
203 
204  // Waiting for enable system flag to be set
205  while(!gFlag_enableSys);
206 
207  // loop while the enable system flag is true
208  while(gFlag_enableSys)
209  {
210  // set custom speed controller gains
211  PI_setGains(piHandle_spd,gSpeed_Kp,gSpeed_Ki);
212 
213  // enable or disable force angle
215 
216  // enable or disable Rs recalibration
218 
219  if(gFlag_runOnLine)
220  {
221  // enable the estimator
223 
224  // enable the PWM
225  HAL_enablePwm(halHandle);
226 
227  // enable global interrupts
228  HAL_enableGlobalInts(halHandle);
229  }
230  else
231  {
232  // disable the estimator
234 
235  // disable the PWM
236  HAL_disablePwm(halHandle);
237 
238  // disable global interrupts
239  HAL_disableGlobalInts(halHandle);
240 
241  // clear integral outputs of the controllers
242  PI_setUi(piHandle_Id,0.0);
243  PI_setUi(piHandle_Iq,0.0);
244  PI_setUi(piHandle_spd,0.0);
245 
246  // clear current references
247  gId_ref_A = 0.0;
248  gIq_ref_A = 0.0;
249 
250  // clear PWM data
251  gPwmData.Vabc_pu.value[0] = 0.0;
252  gPwmData.Vabc_pu.value[1] = 0.0;
253  gPwmData.Vabc_pu.value[2] = 0.0;
254  }
255 
256  // update the estimator state
258 
259  // update the global variables
261 
262  // update CPU usage
263  updateCPUusage();
264 
265 #ifdef DRV8301_SPI
266  HAL_writeDrvData(halHandle,&gDrvSpi8301Vars);
267 
268  HAL_readDrvData(halHandle,&gDrvSpi8301Vars);
269 #endif
270 
271  } // end of while() loop
272 
273  // disable the PWM
274  HAL_disablePwm(halHandle);
275 
276 } // end of main() function
277 
278 
279 interrupt void mainISR(void)
280 {
281  uint32_t timer1Cnt;
282  float_t angleDelta_rad;
283  float_t angleWithDelay_rad;
284  MATH_vec2 Idq_A;
285  float_t outMax_V;
286  MATH_vec2 phasor;
287  MATH_vec2 Vab_out_V;
288  MATH_vec2 Vdq_out_V;
289  HAL_AdcData_t AdcDataWithOffset;
290 
291  // read the timer 1 value and update the CPU usage module
292  timer1Cnt = HAL_readTimerCnt(halHandle,1);
293  CPU_USAGE_updateCnts(cpu_usageHandle,timer1Cnt);
294 
295  // acknowledge the ADC interrupt
296  HAL_acqAdcInt(halHandle,ADC_IntNumber_6);
297 
298  // read the ADC data with offsets
299  HAL_readAdcDataWithOffsets(halHandle,&AdcDataWithOffset);
300 
301  // remove offsets
302  gAdcData.I_A.value[0] = AdcDataWithOffset.I_A.value[0] - gOffsets_I_A.value[0];
303  gAdcData.I_A.value[1] = AdcDataWithOffset.I_A.value[1] - gOffsets_I_A.value[1];
304  gAdcData.I_A.value[2] = AdcDataWithOffset.I_A.value[2] - gOffsets_I_A.value[2];
305  gAdcData.V_V.value[0] = AdcDataWithOffset.V_V.value[0] - gOffsets_V_V.value[0];
306  gAdcData.V_V.value[1] = AdcDataWithOffset.V_V.value[1] - gOffsets_V_V.value[1];
307  gAdcData.V_V.value[2] = AdcDataWithOffset.V_V.value[2] - gOffsets_V_V.value[2];
308  gAdcData.dcBus_V = AdcDataWithOffset.dcBus_V;
309 
310  // run Clarke transform on current
311  CLARKE_run(clarkeHandle_I,&(gAdcData.I_A),&(gEstInputData.Iab_A));
312 
313  // run Clarke transform on voltage
314  CLARKE_run(clarkeHandle_V,&(gAdcData.V_V),&(gEstInputData.Vab_V));
315 
316  // store the input data into a buffer
317  gEstInputData.dcBus_V = gAdcData.dcBus_V;
318 
319  // modify references if running Rs recalibration
320  if(EST_getState(estHandle) == EST_State_Rs)
321  {
322  gEstInputData.speed_ref_Hz = 0.0;
324  }
325  else
326  {
327  gEstInputData.speed_ref_Hz = gSpeed_ref_Hz;
328  gId_rs_recalc_ref_A = 0.0;
329  }
330 
331  // run the estimator
332  EST_run(estHandle,&gEstInputData,&gEstOutputData);
333 
334  // run the speed controller
335  if(++gCounter_speed >= gUserParams.numCtrlTicksPerSpeedTick)
336  {
337  gCounter_speed = 0;
338 
339  PI_run_series(piHandle_spd,gEstInputData.speed_ref_Hz,gEstOutputData.fm_lp_rps * MATH_ONE_OVER_TWO_PI,0.0,&gIq_ref_A);
340  }
341 
342  // get Idq, reutilizing a Park transform used inside the estimator. This is optional, user's Park works as well
343  EST_getIdq_A(estHandle,&Idq_A);
344 
345  // run the Id controller
346  PI_run_series(piHandle_Id,gId_ref_A + gId_rs_recalc_ref_A,Idq_A.value[0],0.0,&(Vdq_out_V.value[0]));
347 
348  // calculate Iq controller limits, and run Iq controller using fast RTS function, callable assembly
349  outMax_V = sqrt_fastRTS((gUserParams.maxVsMag_V * gUserParams.maxVsMag_V) - (Vdq_out_V.value[0] * Vdq_out_V.value[0]));
350  PI_setMinMax(piHandle_Iq,-outMax_V,outMax_V);
351  PI_run_series(piHandle_Iq,gIq_ref_A,Idq_A.value[1],0.0,&(Vdq_out_V.value[1]));
352 
353  // compute angle with delay compensation
354  angleDelta_rad = gUserParams.angleDelayed_sf_sec * gEstOutputData.fm_lp_rps;
355  angleWithDelay_rad = MATH_incrAngle(gEstOutputData.angle_rad, angleDelta_rad);
356 
357  // compute the sin/cos phasor using fast RTS function, callable assembly
358  sincos_fastRTS(angleWithDelay_rad, &(phasor.value[1]), &(phasor.value[0]));
359 
360  // set the phasor in the inverse Park transform
361  IPARK_setPhasor(iparkHandle,&phasor);
362 
363  // run the inverse Park module
364  IPARK_run(iparkHandle,&Vdq_out_V,&Vab_out_V);
365 
366  // setup the space vector generator (SVGEN) module
367  SVGEN_setup(svgenHandle,gEstOutputData.oneOverDcBus_invV);
368 
369  // run the space vector generator (SVGEN) module
370  SVGEN_run(svgenHandle,&Vab_out_V,&(gPwmData.Vabc_pu));
371 
372  // write the PWM compare values
373  HAL_writePwmData(halHandle,&gPwmData);
374 
375  // read the timer 1 value and update the CPU usage module
376  timer1Cnt = HAL_readTimerCnt(halHandle,1);
377  CPU_USAGE_updateCnts(cpu_usageHandle,timer1Cnt);
378 
379  // run the CPU usage module
380  CPU_USAGE_run(cpu_usageHandle);
381 
382  return;
383 } // end of mainISR() function
384 
385 
386 void setupClarke_I(CLARKE_Handle handle,const uint_least8_t numCurrentSensors)
387 {
388  float_t alpha_sf,beta_sf;
389 
390  // initialize the Clarke transform module for current
391  if(numCurrentSensors == 3)
392  {
393  alpha_sf = MATH_ONE_OVER_THREE;
394  beta_sf = MATH_ONE_OVER_SQRT_THREE;
395  }
396  else if(numCurrentSensors == 2)
397  {
398  alpha_sf = 1.0;
399  beta_sf = MATH_ONE_OVER_SQRT_THREE;
400  }
401  else
402  {
403  alpha_sf = 0.0;
404  beta_sf = 0.0;
405  }
406 
407  // set the parameters
408  CLARKE_setScaleFactors(handle,alpha_sf,beta_sf);
409  CLARKE_setNumSensors(handle,numCurrentSensors);
410 
411  return;
412 } // end of setupClarke_I() function
413 
414 
415 void setupClarke_V(CLARKE_Handle handle,const uint_least8_t numVoltageSensors)
416 {
417  float_t alpha_sf,beta_sf;
418 
419  // initialize the Clarke transform module for voltage
420  if(numVoltageSensors == 3)
421  {
422  alpha_sf = MATH_ONE_OVER_THREE;
423  beta_sf = MATH_ONE_OVER_SQRT_THREE;
424  }
425  else
426  {
427  alpha_sf = 0.0;
428  beta_sf = 0.0;
429  }
430 
431  // set the parameters
432  CLARKE_setScaleFactors(handle,alpha_sf,beta_sf);
433  CLARKE_setNumSensors(handle,numVoltageSensors);
434 
435  return;
436 } // end of setupClarke_V() function
437 
438 
440 {
441  float_t Ls_d_H = gUserParams.motor_Ls_d_H;
442  float_t Ls_q_H = gUserParams.motor_Ls_q_H;
443  float_t Rs_d_Ohm = gUserParams.motor_Rs_d_Ohm;
444  float_t Rs_q_Ohm = gUserParams.motor_Rs_q_Ohm;
445  float_t RdoverLd_rps = Rs_d_Ohm / Ls_d_H;
446  float_t RqoverLq_rps = Rs_q_Ohm / Ls_q_H;
447  float_t BWc_rps = gUserParams.BWc_rps;
448  float_t currentCtrlPeriod_sec = (float_t)gUserParams.numCtrlTicksPerCurrentTick / gUserParams.ctrlFreq_Hz;
449  float_t outMax_V = gUserParams.Vd_sf * gUserParams.maxVsMag_V;
450 
451  float_t Kp_Id = Ls_d_H * BWc_rps;
452  float_t Ki_Id = RdoverLd_rps * currentCtrlPeriod_sec;
453 
454  float_t Kp_Iq = Ls_q_H * BWc_rps;
455  float_t Ki_Iq = RqoverLq_rps * currentCtrlPeriod_sec;
456 
457  // set the Id controller
458  PI_setGains(piHandle_Id,Kp_Id,Ki_Id);
459  PI_setUi(piHandle_Id,0.0);
460  PI_setRefValue(piHandle_Id,0.0);
461  PI_setFbackValue(piHandle_Id,0.0);
462  PI_setFfwdValue(piHandle_Id,0.0);
463  PI_setMinMax(piHandle_Id,-outMax_V,outMax_V);
464 
465  // set the Iq controller
466  PI_setGains(piHandle_Iq,Kp_Iq,Ki_Iq);
467  PI_setUi(piHandle_Iq,0.0);
468  PI_setRefValue(piHandle_Iq,0.0);
469  PI_setFbackValue(piHandle_Iq,0.0);
470  PI_setFfwdValue(piHandle_Iq,0.0);
471  PI_setMinMax(piHandle_Iq,0.0,0.0);
472 
473  // set the speed controller
474  PI_setGains(piHandle_spd,gSpeed_Kp,gSpeed_Ki);
475  PI_setUi(piHandle_spd,0.0);
476  PI_setRefValue(piHandle_spd,0.0);
477  PI_setFbackValue(piHandle_spd,0.0);
478  PI_setFfwdValue(piHandle_spd,0.0);
479  PI_setMinMax(piHandle_spd,-gUserParams.maxCurrent_A,gUserParams.maxCurrent_A);
480 
481  return;
482 } // end of setupCurrentControllers() function
483 
484 
486 {
487  // get the states
488  gEstState = EST_getState(estHandle);
489 
490  // get the speed estimate
491  gSpeed_Hz = EST_getFe_Hz(estHandle);
492 
493  // get the torque estimate
494  gTorque_Nm = EST_computeTorque_Nm(estHandle);
495 
496  // get the stator resistance
497  gRs_Ohm = EST_getRs_Ohm(estHandle);
498 
499  // get the stator inductance in the direct coordinate direction
500  gLs_d_H = EST_getLs_d_H(estHandle);
501 
502  // get the stator inductance in the quadrature coordinate direction
503  gLs_q_H = EST_getLs_q_H(estHandle);
504 
505  // get the flux, Wb
506  gFlux_Wb = EST_getFlux_Wb(estHandle);
507 
508  return;
509 } // end of updateGlobalVariables_motor() function
510 
511 
512 void updateCPUusage(void)
513 {
514  uint32_t minDeltaCntObserved = CPU_USAGE_getMinDeltaCntObserved(cpu_usageHandle);
515  uint32_t avgDeltaCntObserved = CPU_USAGE_getAvgDeltaCntObserved(cpu_usageHandle);
516  uint32_t maxDeltaCntObserved = CPU_USAGE_getMaxDeltaCntObserved(cpu_usageHandle);
517  uint16_t pwmPeriod = HAL_readPwmPeriod(halHandle,PWM_Number_1);
518  float_t cpu_usage_den = (float_t)pwmPeriod * (float_t)USER_NUM_PWM_TICKS_PER_ISR_TICK * 2.0;
519 
520  // calculate the minimum cpu usage percentage
521  gCpuUsagePercentageMin = (float_t)minDeltaCntObserved / cpu_usage_den * 100.0;
522 
523  // calculate the average cpu usage percentage
524  gCpuUsagePercentageAvg = (float_t)avgDeltaCntObserved / cpu_usage_den * 100.0;
525 
526  // calculate the maximum cpu usage percentage
527  gCpuUsagePercentageMax = (float_t)maxDeltaCntObserved / cpu_usage_den * 100.0;
528 
529  return;
530 } // end of updateCPUusage() function
531 
532 
533 // end of file
534 
#define USER_SYSTEM_FREQ_MHz
CLOCKS & TIMERS.
Definition: user.h:140
EST_State_e gEstState
Global variable for the estimator state.
float_t angleDelayed_sf_sec
void EST_setFlag_enableForceAngle(EST_Handle handle, const bool state)
IPARK_Handle IPARK_init(void *pMemory, const size_t numBytes)
#define MATH_ONE_OVER_TWO_PI
EST_Handle estHandle
the handle for the estimator
void HAL_enableGlobalInts(HAL_Handle handle)
void HAL_enableAdcInts(HAL_Handle handle)
float_t EST_getFlux_Wb(EST_Handle handle)
void updateGlobalVariables_motor(EST_Handle estHandle)
Updates the global motor variables.
static void PI_setFfwdValue(PI_Handle handle, const _iq ffwdValue)
void HAL_disableGlobalInts(HAL_Handle handle)
MATH_vec3 Vabc_pu
HAL_Obj hal
the hardware abstraction layer object
static void HAL_readAdcDataWithOffsets(HAL_Handle handle, HAL_AdcData_t *pAdcData)
float_t gLs_d_H
Global variable for the stator inductance in the direct coordinate direction, Henry.
float_t motor_Rs_d_Ohm
IPARK_Obj ipark
the inverse Park transform object
static void HAL_writePwmData(HAL_Handle handle, HAL_PwmData_t *pPwmData)
float_t BWc_rps
_iq value[3]
PI_Obj pi_spd
the speed PI controller object
struct _EST_Obj_ * EST_Handle
float_t gIq_ref_A
float_t maxCurrent_A
void HAL_writeDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
static void PI_setUi(PI_Handle handle, const _iq Ui)
static void HAL_acqAdcInt(HAL_Handle handle, const ADC_IntNumber_e intNumber)
PI_Handle piHandle_Iq
the handle for the Iq PI controller
float_t motor_Rs_q_Ohm
uint_least8_t numCurrentSensors
float_t gSpeed_ref_Hz
SVGEN_Obj svgen
the space vector generator object
void EST_setParams(EST_Handle handle, USER_Params *pUserParams)
static void SVGEN_run(SVGEN_Handle handle, const MATH_vec2 *pVab, MATH_vec3 *pT)
static uint32_t CPU_USAGE_getAvgDeltaCntObserved(CPU_USAGE_Handle handle)
PI_Handle piHandle_Id
the handle for the Id PI controller
volatile float_t gSpeed_Ki
uint_least16_t numCtrlTicksPerCurrentTick
#define MATH_ONE_OVER_THREE
void USER_setParams(USER_Params *pUserParams)
Sets the user parameter values.
void setupClarke_V(CLARKE_Handle handle, const uint_least8_t numVoltageSensors)
Sets the number of voltage sensors.
float_t EST_computeTorque_Nm(EST_Handle handle)
float_t speed_ref_Hz
static void CLARKE_setScaleFactors(CLARKE_Handle handle, const _iq alpha_sf, const _iq beta_sf)
volatile bool gFlag_enableRsRecalc
void EST_enable(EST_Handle handle)
float_t maxVsMag_V
MATH_vec3 gOffsets_V_V
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)
USER_Params gUserParams
The user parameters.
void EST_getIdq_A(EST_Handle handle, MATH_vec2 *pIdq_A)
float_t gSpeed_Hz
static void HAL_enablePwm(HAL_Handle handle)
EST_State_e
EST_OutputData_t gEstOutputData
volatile bool gFlag_runOnLine
void HAL_enableDrv(HAL_Handle handle)
_iq value[2]
PI_Obj pi_Iq
the Iq PI controller object
EST_Handle EST_initEst(const uint_least8_t estNumber)
float_t gCpuUsagePercentageMin
PI_Handle PI_init(void *pMemory, const size_t numBytes)
void HAL_setupDrvSpi(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
uint_least8_t numVoltageSensors
float_t EST_getLs_q_H(EST_Handle handle)
void HAL_enableDebugInt(HAL_Handle handle)
float_t gCpuUsagePercentageMax
CLARKE_Handle CLARKE_init(void *pMemory, const size_t numBytes)
float_t oneOverDcBus_invV
void sincos_fastRTS(float_t angle_rad, float_t *pSin, float_t *pCos)
Calculates sine and cosine in a single function call, using callable assembly, fast RTS...
MATH_vec3 gOffsets_I_A
EST_InputData_t gEstInputData
static void IPARK_run(IPARK_Handle handle, const MATH_vec2 *pInVec, MATH_vec2 *pOutVec)
EST_State_e EST_getState(EST_Handle handle)
void setupClarke_I(CLARKE_Handle handle, const uint_least8_t numCurrentSensors)
Sets the number of current sensors.
float_t gRs_Ohm
HAL_DacData_t gDacData
Defines the DAC data.
float_t gLs_q_H
Global variable for the stator inductance in the quadrature coordinate direction, Henry...
interrupt void mainISR(void)
The main interrupt service (ISR) routine.
static uint32_t HAL_readTimerCnt(HAL_Handle handle, const uint_least8_t timerNumber)
float_t gId_rs_recalc_ref_A
static void CLARKE_setNumSensors(CLARKE_Handle handle, const uint_least8_t numSensors)
float_t EST_getRs_Ohm(EST_Handle handle)
uint_least16_t numCtrlTicksPerSpeedTick
CPU_USAGE_Obj cpu_usage
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
static void IPARK_setPhasor(IPARK_Handle handle, const MATH_vec2 *pPhasor)
CPU_USAGE_Handle CPU_USAGE_init(void *pMemory, const size_t numBytes)
uint16_t gCounter_speed
static void HAL_disablePwm(HAL_Handle handle)
HAL_Handle HAL_init(void *pMemory, const size_t numBytes)
static void CLARKE_run(CLARKE_Handle handle, const MATH_vec3 *pInVec, MATH_vec2 *pOutVec)
static uint32_t CPU_USAGE_getMaxDeltaCntObserved(CPU_USAGE_Handle handle)
HAL_Handle halHandle
the handle for the hardware abstraction layer
PARK_Obj park
the Park transform object
CLARKE_Handle clarkeHandle_V
the handle for the voltage Clarke transform
void updateCPUusage(void)
Updates CPU usage.
float_t gFlux_Wb
Global variable for the rotor flux estimate, Wb.
MATH_vec2 Iab_A
uint_least32_t ctrlFreq_Hz
float_t gCpuUsagePercentageAvg
void SVGEN_setup(SVGEN_Handle svgenHandle)
static void PI_setMinMax(PI_Handle handle, const _iq outMin, const _iq outMax)
static void PI_setRefValue(PI_Handle handle, const _iq refValue)
void main(void)
static void CPU_USAGE_updateCnts(CPU_USAGE_Handle handle, const uint32_t cnt)
void setupControllers(void)
Setups the controllers.
float_t sqrt_fastRTS(float_t x)
Calculates square root using callable assembly, fast RTS.
CLARKE_Obj clarke_V
the voltage Clarke transform object
volatile bool gFlag_enableSys
Global flag to enable/disable the system.
MATH_vec2 Vab_V
static uint32_t CPU_USAGE_getMinDeltaCntObserved(CPU_USAGE_Handle handle)
#define MATH_ONE_OVER_SQRT_THREE
volatile bool gFlag_enableForceAngle
static void HAL_initIntVectorTable(HAL_Handle handle)
static float_t MATH_incrAngle(const float_t angle_rad, const float_t angleDelta_rad)
CLARKE_Obj clarke_I
the current Clarke transform object
PI_Obj pi_Id
the Id PI controller object
PARK_Handle PARK_init(void *pMemory, const size_t numBytes)
static void PI_setFbackValue(PI_Handle handle, const _iq fbackValue)
static uint16_t HAL_readPwmPeriod(HAL_Handle handle, const PWM_Number_e pwmNumber)
volatile float_t gId_ref_A
HAL_PwmData_t gPwmData
Defines the PWM data.
bool EST_updateState(EST_Handle handle, const _iq Id_target_pu)
void EST_disable(EST_Handle handle)
void HAL_setParams(HAL_Handle handle, const USER_Params *pUserParams)
static void CPU_USAGE_run(CPU_USAGE_Handle handle)
HAL_AdcData_t gAdcData
Defines the ADC data.
float_t EST_getFe_Hz(EST_Handle handle)
void HAL_readDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
float_t maxCurrent_resEst_A
PARK_Handle parkHandle
the handle for the Park object
PI_Handle piHandle_spd
the handle for the speed PI controller
float_t gTorque_Nm
Global variable for the estimated torque, N*m.
SVGEN_Handle svgenHandle
the handle for the space vector generator
float_t motor_Ls_d_H
float_t motor_Ls_q_H
CPU_USAGE_Handle cpu_usageHandle
CLARKE_Handle clarkeHandle_I
the handle for the current Clarke transform
IPARK_Handle iparkHandle
the handle for the inverse Park transform
SVGEN_Handle SVGEN_init(void *pMemory, const size_t numBytes)
volatile float_t gSpeed_Kp
static void PI_setGains(PI_Handle handle, const _iq Kp, const _iq Ki)
static void PI_run_series(PI_Handle handle, const _iq refValue, const _iq fbackValue, const _iq ffwdValue, _iq *pOutValue)
float float_t
void EST_run(EST_Handle handle, const MATH_vec2 *pIab_pu, const MATH_vec2 *pVab_pu, const _iq dcBus_pu, const _iq speed_ref_pu)
#define USER_NUM_PWM_TICKS_PER_ISR_TICK
DECIMATION.
Definition: user.h:184