instaspin_foc
fast_obs_pm_cal_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 CAL_State_e gCalState = CAL_State_Idle;
22 
23 EST_State_e gEstState = EST_State_Idle;
24 
25 volatile bool gFlag_enableSys = true;
26 
27 volatile bool gFlag_runCal = false;
28 
29 volatile bool gFlag_runOnLine = false;
30 
31 volatile bool gFlag_enableForceAngle = true;
32 
33 volatile bool gFlag_enableRsRecalc = true;
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 
56 
57 uint16_t gCounter_speed = 0;
58 
60 
62 
64 
66 
68 
70 
72 
73 MATH_vec3 gOffsets_I_A = {0.0, 0.0, 0.0};
74 
75 MATH_vec3 gOffsets_V_V = {0.0, 0.0, 0.0};
76 
79 
82 
85 
88 
90 
93 
96 
99 
102 
105 
108 
109 #ifdef DRV8301_SPI
110 // Watch window interface to the 8301 SPI
111 DRV_SPI_8301_Vars_t gDrvSpi8301Vars;
112 #endif
113 
119 
120 // **************************************************************************
121 // the functions
122 
123 void main(void)
124 {
125  uint_least8_t estNumber = 0;
126 
127  // initialize the user parameters
128  USER_setParams(&gUserParams);
129 
130  // initialize the user parameters
131  USER_setParams_priv(&gUserParams);
132 
133  // initialize the driver
134  halHandle = HAL_init(&hal,sizeof(hal));
135 
136  // set the driver parameters
137  HAL_setParams(halHandle,&gUserParams);
138 
139  // initialize the calibrator
140  calHandle = CAL_init(&cal,sizeof(cal));
141 
142  // set the default calibrator parameters
143  CAL_setParams(calHandle,&gUserParams);
144 
145  // initialize the Clarke modules
146  clarkeHandle_I = CLARKE_init(&clarke_I,sizeof(clarke_I));
147  clarkeHandle_V = CLARKE_init(&clarke_V,sizeof(clarke_V));
148 
149  // set the Clarke parameters
150  setupClarke_I(clarkeHandle_I,gUserParams.numCurrentSensors);
151  setupClarke_V(clarkeHandle_V,gUserParams.numVoltageSensors);
152 
153  // initialize the estimator
154  estHandle = EST_initEst(estNumber);
155 
156  // set the default estimator parameters
157  EST_setParams(estHandle,&gUserParams);
160 
161  // initialize the inverse Park module
162  iparkHandle = IPARK_init(&ipark,sizeof(ipark));
163 
164  // initialize the Park module
165  parkHandle = PARK_init(&park,sizeof(park));
166 
167  // initialize the PI controllers
168  piHandle_Id = PI_init(&pi_Id, sizeof(pi_Id));
169  piHandle_Iq = PI_init(&pi_Iq, sizeof(pi_Iq));
170  piHandle_spd = PI_init(&pi_spd,sizeof(pi_spd));
171 
172  // setup the controllers
174 
175  // initialize the space vector generator module
176  svgenHandle = SVGEN_init(&svgen,sizeof(svgen));
177 
178  // initialize the CPU usage module
179  cpu_usageHandle = CPU_USAGE_init(&cpu_usage,sizeof(cpu_usage));
180  CPU_USAGE_setParams(cpu_usageHandle,
181  (uint32_t)USER_SYSTEM_FREQ_MHz * 1000000, // timer period, cnts
182  (uint32_t)USER_ISR_FREQ_Hz); // average over 1 second of ISRs
183 
184  // setup faults
185  HAL_setupFaults(halHandle);
186 
187  // initialize the interrupt vector table
188  HAL_initIntVectorTable(halHandle);
189 
190  // enable the ADC interrupts
191  HAL_enableAdcInts(halHandle);
192 
193  // enable global interrupts
194  HAL_enableGlobalInts(halHandle);
195 
196  // enable debug interrupts
197  HAL_enableDebugInt(halHandle);
198 
199  // disable the PWM
200  HAL_disablePwm(halHandle);
201 
202 #ifdef DRV8301_SPI
203  // turn on the DRV8301 if present
204  HAL_enableDrv(halHandle);
205  // initialize the DRV8301 interface
206  HAL_setupDrvSpi(halHandle,&gDrvSpi8301Vars);
207 #endif
208 
209  // Waiting for enable system flag to be set
210  while(!gFlag_enableSys);
211 
212  // loop while the enable system flag is true
213  while(gFlag_enableSys)
214  {
215  // set custom speed controller gains
216  PI_setGains(piHandle_spd,gSpeed_Kp,gSpeed_Ki);
217 
218  // enable or disable force angle
220 
221  // enable or disable Rs recalibration
223 
224  if((gFlag_runOnLine) && (!gFlag_runCal))
225  {
226  // disable the calibrator
227  CAL_disable(calHandle);
228 
229  // enable the estimator
231 
232  // enable the PWM
233  HAL_enablePwm(halHandle);
234  }
235  else if(gFlag_runCal)
236  {
237  // enable the calibrator
238  CAL_setFlag_enableAdcOffset(calHandle,true);
239 
240  // enable the calibrator
241  CAL_enable(calHandle);
242 
243  // disable the estimator
245 
246  // enable the PWM
247  HAL_enablePwm(halHandle);
248  }
249  else
250  {
251  // disable the calibrator
252  CAL_disable(calHandle);
253 
254  // disable the estimator
256 
257  // disable the PWM
258  HAL_disablePwm(halHandle);
259 
260  // clear integral outputs of the controllers
261  PI_setUi(piHandle_Id,0.0);
262  PI_setUi(piHandle_Iq,0.0);
263  PI_setUi(piHandle_spd,0.0);
264 
265  // clear current references
266  gId_ref_A = 0.0;
267  gIq_ref_A = 0.0;
268  }
269 
270  // update the estimator state
272 
273  // update the calibrator state
274  if(CAL_updateState(calHandle))
275  {
276  CAL_State_e calState = CAL_getState(calHandle);
277 
278  if(calState == CAL_State_Done)
279  {
280  // update the ADC offset values
281  gOffsets_I_A.value[0] = CAL_getOffsetValue_I(calHandle,0);
282  gOffsets_I_A.value[1] = CAL_getOffsetValue_I(calHandle,1);
283  gOffsets_I_A.value[2] = CAL_getOffsetValue_I(calHandle,2);
284  gOffsets_V_V.value[0] = CAL_getOffsetValue_V(calHandle,0);
285  gOffsets_V_V.value[1] = CAL_getOffsetValue_V(calHandle,1);
286  gOffsets_V_V.value[2] = CAL_getOffsetValue_V(calHandle,2);
287 
288  // clear the flag
289  gFlag_runCal = false;
290  }
291  }
292 
293  // update the global variables
295 
296  // update CPU usage
297  updateCPUusage();
298 
299 #ifdef DRV8301_SPI
300  HAL_writeDrvData(halHandle,&gDrvSpi8301Vars);
301 
302  HAL_readDrvData(halHandle,&gDrvSpi8301Vars);
303 #endif
304 
305  } // end of while() loop
306 
307  // disable the PWM
308  HAL_disablePwm(halHandle);
309 
310 } // end of main() function
311 
312 
313 interrupt void mainISR(void)
314 {
315  uint32_t timer1Cnt;
316  float_t angleDelta_rad;
317  float_t angleWithDelay_rad;
318  MATH_vec2 Idq_A;
319  float_t outMax_V;
320  MATH_vec2 phasor;
321  MATH_vec2 Vab_out_V;
322  MATH_vec2 Vdq_out_V;
323  HAL_AdcData_t AdcDataWithOffset;
324 
325  // read the timer 1 value and update the CPU usage module
326  timer1Cnt = HAL_readTimerCnt(halHandle,1);
327  CPU_USAGE_updateCnts(cpu_usageHandle,timer1Cnt);
328 
329  // acknowledge the ADC interrupt
330  HAL_acqAdcInt(halHandle,ADC_IntNumber_6);
331 
332  // read the ADC data with offsets
333  HAL_readAdcDataWithOffsets(halHandle,&AdcDataWithOffset);
334 
335  // remove offsets
336  gAdcData.I_A.value[0] = AdcDataWithOffset.I_A.value[0] - gOffsets_I_A.value[0];
337  gAdcData.I_A.value[1] = AdcDataWithOffset.I_A.value[1] - gOffsets_I_A.value[1];
338  gAdcData.I_A.value[2] = AdcDataWithOffset.I_A.value[2] - gOffsets_I_A.value[2];
339  gAdcData.V_V.value[0] = AdcDataWithOffset.V_V.value[0] - gOffsets_V_V.value[0];
340  gAdcData.V_V.value[1] = AdcDataWithOffset.V_V.value[1] - gOffsets_V_V.value[1];
341  gAdcData.V_V.value[2] = AdcDataWithOffset.V_V.value[2] - gOffsets_V_V.value[2];
342  gAdcData.dcBus_V = AdcDataWithOffset.dcBus_V;
343 
344  // if enabled, run the calibrator
345  if(CAL_isEnabled(calHandle))
346  {
347  // run the calibrator
348  CAL_run(calHandle,&AdcDataWithOffset);
349  }
350 
351  // if enabled, run the estimator
353  {
354  // run Clarke transform on current
355  CLARKE_run(clarkeHandle_I,&(gAdcData.I_A),&(gEstInputData.Iab_A));
356 
357  // run Clarke transform on voltage
358  CLARKE_run(clarkeHandle_V,&(gAdcData.V_V),&(gEstInputData.Vab_V));
359 
360  // store the input data into a buffer
361  gEstInputData.dcBus_V = gAdcData.dcBus_V;
362 
363  // modify references if running Rs recalibration
364  if(EST_getState(estHandle) == EST_State_Rs)
365  {
366  gEstInputData.speed_ref_Hz = 0.0;
368  }
369  else
370  {
371  gEstInputData.speed_ref_Hz = gSpeed_ref_Hz;
372  gId_rs_recalc_ref_A = 0.0;
373  }
374 
375  // run the estimator
376  EST_run(estHandle,&gEstInputData,&gEstOutputData);
377 
378  // run the speed controller
379  if(++gCounter_speed >= gUserParams.numCtrlTicksPerSpeedTick)
380  {
381  gCounter_speed = 0;
382 
383  PI_run_series(piHandle_spd,gEstInputData.speed_ref_Hz,gEstOutputData.fm_lp_rps * MATH_ONE_OVER_TWO_PI,0.0,&gIq_ref_A);
384  }
385 
386  // get Idq, reutilizing a Park transform used inside the estimator. This is optional, user's Park works as well
387  EST_getIdq_A(estHandle,&Idq_A);
388 
389  // run the Id controller
390  PI_run_series(piHandle_Id,gId_ref_A + gId_rs_recalc_ref_A,Idq_A.value[0],0.0,&(Vdq_out_V.value[0]));
391 
392  // calculate Iq controller limits, and run Iq controller using fast RTS function, callable assembly
393  outMax_V = sqrt_fastRTS((gUserParams.maxVsMag_V * gUserParams.maxVsMag_V) - (Vdq_out_V.value[0] * Vdq_out_V.value[0]));
394  PI_setMinMax(piHandle_Iq,-outMax_V,outMax_V);
395  PI_run_series(piHandle_Iq,gIq_ref_A,Idq_A.value[1],0.0,&(Vdq_out_V.value[1]));
396 
397  // compute angle with delay compensation
398  angleDelta_rad = gUserParams.angleDelayed_sf_sec * gEstOutputData.fm_lp_rps;
399  angleWithDelay_rad = MATH_incrAngle(gEstOutputData.angle_rad, angleDelta_rad);
400 
401  // compute the sin/cos phasor using fast RTS function, callable assembly
402  sincos_fastRTS(angleWithDelay_rad, &(phasor.value[1]), &(phasor.value[0]));
403 
404  // set the phasor in the inverse Park transform
405  IPARK_setPhasor(iparkHandle,&phasor);
406 
407  // run the inverse Park module
408  IPARK_run(iparkHandle,&Vdq_out_V,&Vab_out_V);
409 
410  // setup the space vector generator (SVGEN) module
411  SVGEN_setup(svgenHandle,gEstOutputData.oneOverDcBus_invV);
412 
413  // run the space vector generator (SVGEN) module
414  SVGEN_run(svgenHandle,&Vab_out_V,&(gPwmData.Vabc_pu));
415  }
416  else
417  {
418  // create PWM data
419  gPwmData.Vabc_pu.value[0] = 0.0;
420  gPwmData.Vabc_pu.value[1] = 0.0;
421  gPwmData.Vabc_pu.value[2] = 0.0;
422  }
423 
424  // write the PWM compare values
425  HAL_writePwmData(halHandle,&gPwmData);
426 
427  // read the timer 1 value and update the CPU usage module
428  timer1Cnt = HAL_readTimerCnt(halHandle,1);
429  CPU_USAGE_updateCnts(cpu_usageHandle,timer1Cnt);
430 
431  // run the CPU usage module
432  CPU_USAGE_run(cpu_usageHandle);
433 
434  return;
435 } // end of mainISR() function
436 
437 
438 void setupClarke_I(CLARKE_Handle handle,const uint_least8_t numCurrentSensors)
439 {
440  float_t alpha_sf,beta_sf;
441 
442  // initialize the Clarke transform module for current
443  if(numCurrentSensors == 3)
444  {
445  alpha_sf = MATH_ONE_OVER_THREE;
446  beta_sf = MATH_ONE_OVER_SQRT_THREE;
447  }
448  else if(numCurrentSensors == 2)
449  {
450  alpha_sf = 1.0;
451  beta_sf = MATH_ONE_OVER_SQRT_THREE;
452  }
453  else
454  {
455  alpha_sf = 0.0;
456  beta_sf = 0.0;
457  }
458 
459  // set the parameters
460  CLARKE_setScaleFactors(handle,alpha_sf,beta_sf);
461  CLARKE_setNumSensors(handle,numCurrentSensors);
462 
463  return;
464 } // end of setupClarke_I() function
465 
466 
467 void setupClarke_V(CLARKE_Handle handle,const uint_least8_t numVoltageSensors)
468 {
469  float_t alpha_sf,beta_sf;
470 
471  // initialize the Clarke transform module for voltage
472  if(numVoltageSensors == 3)
473  {
474  alpha_sf = MATH_ONE_OVER_THREE;
475  beta_sf = MATH_ONE_OVER_SQRT_THREE;
476  }
477  else
478  {
479  alpha_sf = 0.0;
480  beta_sf = 0.0;
481  }
482 
483  // set the parameters
484  CLARKE_setScaleFactors(handle,alpha_sf,beta_sf);
485  CLARKE_setNumSensors(handle,numVoltageSensors);
486 
487  return;
488 } // end of setupClarke_V() function
489 
490 
492 {
493  float_t Ls_d_H = gUserParams.motor_Ls_d_H;
494  float_t Ls_q_H = gUserParams.motor_Ls_q_H;
495  float_t Rs_d_Ohm = gUserParams.motor_Rs_d_Ohm;
496  float_t Rs_q_Ohm = gUserParams.motor_Rs_q_Ohm;
497  float_t RdoverLd_rps = Rs_d_Ohm / Ls_d_H;
498  float_t RqoverLq_rps = Rs_q_Ohm / Ls_q_H;
499  float_t BWc_rps = gUserParams.BWc_rps;
500  float_t currentCtrlPeriod_sec = (float_t)gUserParams.numCtrlTicksPerCurrentTick / gUserParams.ctrlFreq_Hz;
501  float_t outMax_V = gUserParams.Vd_sf * gUserParams.maxVsMag_V;
502 
503  float_t Kp_Id = Ls_d_H * BWc_rps;
504  float_t Ki_Id = RdoverLd_rps * currentCtrlPeriod_sec;
505 
506  float_t Kp_Iq = Ls_q_H * BWc_rps;
507  float_t Ki_Iq = RqoverLq_rps * currentCtrlPeriod_sec;
508 
509  // set the Id controller
510  PI_setGains(piHandle_Id,Kp_Id,Ki_Id);
511  PI_setUi(piHandle_Id,0.0);
512  PI_setRefValue(piHandle_Id,0.0);
513  PI_setFbackValue(piHandle_Id,0.0);
514  PI_setFfwdValue(piHandle_Id,0.0);
515  PI_setMinMax(piHandle_Id,-outMax_V,outMax_V);
516 
517  // set the Iq controller
518  PI_setGains(piHandle_Iq,Kp_Iq,Ki_Iq);
519  PI_setUi(piHandle_Iq,0.0);
520  PI_setRefValue(piHandle_Iq,0.0);
521  PI_setFbackValue(piHandle_Iq,0.0);
522  PI_setFfwdValue(piHandle_Iq,0.0);
523  PI_setMinMax(piHandle_Iq,0.0,0.0);
524 
525  // set the speed controller
526  PI_setGains(piHandle_spd,gSpeed_Kp,gSpeed_Ki);
527  PI_setUi(piHandle_spd,0.0);
528  PI_setRefValue(piHandle_spd,0.0);
529  PI_setFbackValue(piHandle_spd,0.0);
530  PI_setFfwdValue(piHandle_spd,0.0);
531  PI_setMinMax(piHandle_spd,-gUserParams.maxCurrent_A,gUserParams.maxCurrent_A);
532 
533  return;
534 } // end of setupCurrentControllers() function
535 
536 
538 {
539  // get the states
540  gCalState = CAL_getState(calHandle);
541  gEstState = EST_getState(estHandle);
542 
543  // get the speed estimate
544  gSpeed_Hz = EST_getFe_Hz(estHandle);
545 
546  // get the torque estimate
547  gTorque_Nm = EST_computeTorque_Nm(estHandle);
548 
549  // get the stator resistance
550  gRs_Ohm = EST_getRs_Ohm(estHandle);
551 
552  // get the stator inductance in the direct coordinate direction
553  gLs_d_H = EST_getLs_d_H(estHandle);
554 
555  // get the stator inductance in the quadrature coordinate direction
556  gLs_q_H = EST_getLs_q_H(estHandle);
557 
558  // get the flux, Wb
559  gFlux_Wb = EST_getFlux_Wb(estHandle);
560 
561  return;
562 } // end of updateGlobalVariables_motor() function
563 
564 
565 void updateCPUusage(void)
566 {
567  uint32_t minDeltaCntObserved = CPU_USAGE_getMinDeltaCntObserved(cpu_usageHandle);
568  uint32_t avgDeltaCntObserved = CPU_USAGE_getAvgDeltaCntObserved(cpu_usageHandle);
569  uint32_t maxDeltaCntObserved = CPU_USAGE_getMaxDeltaCntObserved(cpu_usageHandle);
570  uint16_t pwmPeriod = HAL_readPwmPeriod(halHandle,PWM_Number_1);
571  float_t cpu_usage_den = (float_t)pwmPeriod * (float_t)USER_NUM_PWM_TICKS_PER_ISR_TICK * 2.0;
572 
573  // calculate the minimum cpu usage percentage
574  gCpuUsagePercentageMin = (float_t)minDeltaCntObserved / cpu_usage_den * 100.0;
575 
576  // calculate the average cpu usage percentage
577  gCpuUsagePercentageAvg = (float_t)avgDeltaCntObserved / cpu_usage_den * 100.0;
578 
579  // calculate the maximum cpu usage percentage
580  gCpuUsagePercentageMax = (float_t)maxDeltaCntObserved / cpu_usage_den * 100.0;
581 
582  return;
583 } // end of updateCPUusage() function
584 
585 
586 // end of file
587 
#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)
static void CAL_enable(CAL_Handle handle)
IPARK_Handle IPARK_init(void *pMemory, const size_t numBytes)
#define MATH_ONE_OVER_TWO_PI
void HAL_enableGlobalInts(HAL_Handle handle)
void HAL_enableAdcInts(HAL_Handle handle)
CLARKE_Handle clarkeHandle_V
the handle for the voltage Clarke transform
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)
MATH_vec3 Vabc_pu
static void HAL_readAdcDataWithOffsets(HAL_Handle handle, HAL_AdcData_t *pAdcData)
static void CAL_run(CAL_Handle handle, const HAL_AdcData_t *pAdcData)
float_t gLs_d_H
Global variable for the stator inductance in the direct coordinate direction, Henry.
CLARKE_Handle clarkeHandle_I
the handle for the current Clarke transform
float_t motor_Rs_d_Ohm
SVGEN_Obj svgen
the space vector generator object
volatile bool gFlag_runOnLine
static void HAL_writePwmData(HAL_Handle handle, HAL_PwmData_t *pPwmData)
float_t BWc_rps
_iq value[3]
void main(void)
struct _EST_Obj_ * EST_Handle
float_t maxCurrent_A
void HAL_writeDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
float_t gCpuUsagePercentageAvg
MATH_vec3 gOffsets_V_V
static void PI_setUi(PI_Handle handle, const _iq Ui)
static void HAL_acqAdcInt(HAL_Handle handle, const ADC_IntNumber_e intNumber)
float_t motor_Rs_q_Ohm
CAL_Obj cal
the calibrator object
static void CAL_setFlag_enableAdcOffset(CAL_Handle handle, const bool value)
uint_least8_t numCurrentSensors
bool EST_isEnabled(EST_Handle handle)
float_t gIq_ref_A
volatile float_t gSpeed_Ki
void CAL_setParams(CAL_Handle handle, const USER_Params *pUserParams)
CLARKE_Obj clarke_V
the voltage Clarke transform 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)
float_t gCpuUsagePercentageMax
EST_InputData_t gEstInputData
uint_least16_t numCtrlTicksPerCurrentTick
#define MATH_ONE_OVER_THREE
void USER_setParams(USER_Params *pUserParams)
Sets the user parameter values.
EST_OutputData_t gEstOutputData
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
volatile float_t gSpeed_Kp
static void CLARKE_setScaleFactors(CLARKE_Handle handle, const _iq alpha_sf, const _iq beta_sf)
CAL_State_e
void EST_enable(EST_Handle handle)
HAL_Obj hal
the hardware abstraction layer object
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)
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
void HAL_enableDrv(HAL_Handle handle)
_iq value[2]
volatile bool gFlag_runCal
PARK_Handle parkHandle
the handle for the Park object
EST_Handle EST_initEst(const uint_least8_t estNumber)
float_t gSpeed_ref_Hz
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)
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...
PI_Obj pi_Id
the Id PI controller object
static void IPARK_run(IPARK_Handle handle, const MATH_vec2 *pInVec, MATH_vec2 *pOutVec)
EST_State_e EST_getState(EST_Handle handle)
static void CAL_disable(CAL_Handle handle)
void setupClarke_I(CLARKE_Handle handle, const uint_least8_t numCurrentSensors)
Sets the number of current sensors.
PI_Handle piHandle_Iq
the handle for the Iq PI controller
float_t gRs_Ohm
HAL_DacData_t gDacData
Defines the DAC data.
SVGEN_Handle svgenHandle
the handle for the space vector generator
float_t gLs_q_H
Global variable for the stator inductance in the quadrature coordinate direction, Henry...
PI_Obj pi_spd
the speed PI controller object
interrupt void mainISR(void)
The main interrupt service (ISR) routine.
volatile bool gFlag_enableRsRecalc
IPARK_Handle iparkHandle
the handle for the inverse Park transform
static uint32_t HAL_readTimerCnt(HAL_Handle handle, const uint_least8_t timerNumber)
static _iq CAL_getOffsetValue_V(CAL_Handle handle, const uint_least8_t sensorNumber)
static void CLARKE_setNumSensors(CLARKE_Handle handle, const uint_least8_t numSensors)
float_t EST_getRs_Ohm(EST_Handle handle)
CPU_USAGE_Obj cpu_usage
uint_least16_t numCtrlTicksPerSpeedTick
float_t gId_rs_recalc_ref_A
void CPU_USAGE_setParams(CPU_USAGE_Handle handle, const uint32_t timerPeriod_cnts, const uint32_t numDeltaCntsAvg)
PARK_Obj park
the Park transform 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)
HAL_Handle HAL_init(void *pMemory, const size_t numBytes)
PI_Handle piHandle_spd
the handle for the speed PI controller
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
CAL_State_e gCalState
void updateCPUusage(void)
Updates CPU usage.
static CAL_State_e CAL_getState(CAL_Handle handle)
float_t gFlux_Wb
Global variable for the rotor flux estimate, Wb.
MATH_vec2 Iab_A
MATH_vec3 gOffsets_I_A
uint_least32_t ctrlFreq_Hz
CAL_Handle CAL_init(void *pMemory, const size_t numBytes)
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)
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.
MATH_vec2 Vab_V
static uint32_t CPU_USAGE_getMinDeltaCntObserved(CPU_USAGE_Handle handle)
#define MATH_ONE_OVER_SQRT_THREE
static void HAL_initIntVectorTable(HAL_Handle handle)
IPARK_Obj ipark
the inverse Park 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)
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)
PI_Handle piHandle_Id
the handle for the Id PI controller
static _iq CAL_getOffsetValue_I(CAL_Handle handle, const uint_least8_t sensorNumber)
void HAL_setParams(HAL_Handle handle, const USER_Params *pUserParams)
static void CPU_USAGE_run(CPU_USAGE_Handle handle)
bool CAL_updateState(CAL_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 gSpeed_Hz
float_t maxCurrent_resEst_A
static bool CAL_isEnabled(CAL_Handle handle)
CLARKE_Obj clarke_I
the current Clarke transform object
PI_Obj pi_Iq
the Iq PI controller object
float_t gTorque_Nm
Global variable for the estimated torque, N*m.
CPU_USAGE_Handle cpu_usageHandle
float_t motor_Ls_d_H
float_t motor_Ls_q_H
EST_Handle estHandle
the handle for the estimator
volatile bool gFlag_enableForceAngle
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
CAL_Handle calHandle
the handle for the calibrator
uint16_t gCounter_speed
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
float_t gCpuUsagePercentageMin