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