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