MotorWare f2806x Module API Documentation
32b/ctrl.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2012, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 
33 
34 
39 
40 
41 // **************************************************************************
42 // the includes
43 
44 #include <math.h>
45 
46 
47 // drivers
48 
49 
50 // modules
53 
54 
55 // platforms
57 #include "hal.h"
58 #include "user.h"
59 
60 
61 #ifdef FLASH
62 #pragma CODE_SECTION(CTRL_run,"ramfuncs");
63 #pragma CODE_SECTION(CTRL_setup,"ramfuncs");
64 #endif
65 
66 
67 // **************************************************************************
68 // the defines
69 
70 
71 // **************************************************************************
72 // the globals
73 
74 
75 // **************************************************************************
76 // the function prototypes
77 
78 void CTRL_getGains(CTRL_Handle handle,const CTRL_Type_e ctrlType,
79  _iq *pKp,_iq *pKi,_iq *pKd)
80 {
81 
82  *pKp = CTRL_getKp(handle,ctrlType);
83  *pKi = CTRL_getKi(handle,ctrlType);
84  *pKd = CTRL_getKd(handle,ctrlType);
85 
86  return;
87 } // end of CTRL_getGains() function
88 
89 
90 void CTRL_getIab_filt_pu(CTRL_Handle handle,MATH_vec2 *pIab_filt_pu)
91 {
92  CTRL_Obj *obj = (CTRL_Obj *)handle;
93 
94  pIab_filt_pu->value[0] = obj->Iab_filt.value[0];
95  pIab_filt_pu->value[1] = obj->Iab_filt.value[1];
96 
97  return;
98 } // end of CTRL_getIab_filt_pu() function
99 
100 
101 void CTRL_getIab_in_pu(CTRL_Handle handle,MATH_vec2 *pIab_in_pu)
102 {
103  CTRL_Obj *obj = (CTRL_Obj *)handle;
104 
105  pIab_in_pu->value[0] = obj->Iab_in.value[0];
106  pIab_in_pu->value[1] = obj->Iab_in.value[1];
107 
108  return;
109 } // end of CTRL_getIab_in_pu() function
110 
111 
112 void CTRL_getIdq_in_pu(CTRL_Handle handle,MATH_vec2 *pIdq_in_pu)
113 {
114  CTRL_Obj *obj = (CTRL_Obj *)handle;
115 
116  pIdq_in_pu->value[0] = obj->Idq_in.value[0];
117  pIdq_in_pu->value[1] = obj->Idq_in.value[1];
118 
119  return;
120 } // end of CTRL_getIdq_in_pu() function
121 
122 
123 void CTRL_getIdq_ref_pu(CTRL_Handle handle,MATH_vec2 *pIdq_ref_pu)
124 {
125  CTRL_Obj *obj = (CTRL_Obj *)handle;
126 
127  pIdq_ref_pu->value[0] = obj->Idq_ref.value[0];
128  pIdq_ref_pu->value[1] = obj->Idq_ref.value[1];
129 
130  return;
131 } // end of CTRL_getIdq_ref_pu() function
132 
133 
135 {
136 
137  return(CTRL_getIdRated_pu(handle));
138 } // end of CTRL_getMagCurrent_pu() function
139 
140 
142 {
143 
144  return(CTRL_getSpd_max_pu(handle));
145 } // end of CTRL_getMaximumSpeed_pu() function
146 
147 
148 void CTRL_getVab_in_pu(CTRL_Handle handle,MATH_vec2 *pVab_in_pu)
149 {
150  CTRL_Obj *obj = (CTRL_Obj *)handle;
151 
152  pVab_in_pu->value[0] = obj->Vab_in.value[0];
153  pVab_in_pu->value[1] = obj->Vab_in.value[1];
154 
155  return;
156 } // end of CTRL_getVab_in_pu() function
157 
158 
159 void CTRL_getVab_out_pu(CTRL_Handle handle,MATH_vec2 *pVab_out_pu)
160 {
161  CTRL_Obj *obj = (CTRL_Obj *)handle;
162 
163  pVab_out_pu->value[0] = obj->Vab_out.value[0];
164  pVab_out_pu->value[1] = obj->Vab_out.value[1];
165 
166  return;
167 } // end of CTRL_getVab_out_pu() function
168 
169 
170 void CTRL_getVdq_out_pu(CTRL_Handle handle,MATH_vec2 *pVdq_out_pu)
171 {
172  CTRL_Obj *obj = (CTRL_Obj *)handle;
173 
174  pVdq_out_pu->value[0] = obj->Vdq_out.value[0];
175  pVdq_out_pu->value[1] = obj->Vdq_out.value[1];
176 
177  return;
178 } // end of CTRL_getVdq_out_pu() function
179 
180 
181 void CTRL_getWaitTimes(CTRL_Handle handle,uint_least32_t *pWaitTimes)
182 {
183  CTRL_Obj *obj = (CTRL_Obj *)handle;
184  uint_least16_t stateCnt;
185 
186  for(stateCnt=0;stateCnt<CTRL_numStates;stateCnt++)
187  {
188  pWaitTimes[stateCnt] = obj->waitTimes[stateCnt];
189  }
190 
191  return;
192 } // end of CTRL_getWaitTimes() function
193 
194 
195 void CTRL_run(CTRL_Handle handle,HAL_Handle halHandle,
196  const HAL_AdcData_t *pAdcData,
197  HAL_PwmData_t *pPwmData)
198 {
199  uint_least16_t count_isr = CTRL_getCount_isr(handle);
200  uint_least16_t numIsrTicksPerCtrlTick = CTRL_getNumIsrTicksPerCtrlTick(handle);
201 
202 
203  // if needed, run the controller
204  if(count_isr >= numIsrTicksPerCtrlTick)
205  {
206  CTRL_State_e ctrlState = CTRL_getState(handle);
207 
208  // reset the isr count
209  CTRL_resetCounter_isr(handle);
210 
211  // increment the state counter
212  CTRL_incrCounter_state(handle);
213 
214  // increment the trajectory count
215  CTRL_incrCounter_traj(handle);
216 
217  // run the appropriate controller
218  if(ctrlState == CTRL_State_OnLine)
219  {
220  CTRL_Obj *obj = (CTRL_Obj *)handle;
221 
222  // increment the current count
223  CTRL_incrCounter_current(handle);
224 
225  // increment the speed count
226  CTRL_incrCounter_speed(handle);
227 
229  {
230  // run the online controller
231  CTRL_runOnLine_User(handle,pAdcData,pPwmData);
232  }
233  else
234  {
235  // run the online controller
236  CTRL_runOnLine(handle,pAdcData,pPwmData);
237  }
238  }
239  else if(ctrlState == CTRL_State_OffLine)
240  {
241  // run the offline controller
242  CTRL_runOffLine(handle,halHandle,pAdcData,pPwmData);
243  }
244  else if(ctrlState == CTRL_State_Idle)
245  {
246  // set all pwm outputs to zero
247  pPwmData->Tabc.value[0] = _IQ(0.0);
248  pPwmData->Tabc.value[1] = _IQ(0.0);
249  pPwmData->Tabc.value[2] = _IQ(0.0);
250  }
251  }
252  else
253  {
254  // increment the isr count
255  CTRL_incrCounter_isr(handle);
256  }
257 
258  return;
259 } // end of CTRL_run() function
260 
261 
262 void CTRL_setGains(CTRL_Handle handle,const CTRL_Type_e ctrlType,
263  const _iq Kp,const _iq Ki,const _iq Kd)
264 {
265 
266  CTRL_setKp(handle,ctrlType,Kp);
267  CTRL_setKi(handle,ctrlType,Ki);
268  CTRL_setKd(handle,ctrlType,Kd);
269 
270  return;
271 } // end of CTRL_setGains() function
272 
273 
274 void CTRL_setMagCurrent_pu(CTRL_Handle handle,const _iq magCurrent_pu)
275 {
276 
277  CTRL_setIdRated_pu(handle,magCurrent_pu);
278 
279  return;
280 } // end of CTRL_setMagCurrent_pu() function
281 
282 
283 void CTRL_setMaximumSpeed_pu(CTRL_Handle handle,const _iq maxSpeed_pu)
284 {
285 
286  CTRL_setSpd_max_pu(handle,maxSpeed_pu);
287 
288  return;
289 } // end of CTRL_setMaximumSpeed_pu() function
290 
291 
292 void CTRL_setParams(CTRL_Handle handle,USER_Params *pUserParams)
293 {
294  CTRL_Obj *obj = (CTRL_Obj *)handle;
295 
296  _iq Kp,Ki,Kd;
297  _iq outMin,outMax;
298  _iq maxModulation;
299 
300  MATH_vec2 Iab_out_pu = {_IQ(0.0),_IQ(0.0)};
301  MATH_vec2 Idq_out_pu = {_IQ(0.0),_IQ(0.0)};
302  MATH_vec2 Idq_ref_pu = {_IQ(0.0),_IQ(0.0)};
303  MATH_vec2 Vab_in_pu = {_IQ(0.0),_IQ(0.0)};
304  MATH_vec2 Vab_out_pu = {_IQ(0.0),_IQ(0.0)};
305  MATH_vec2 Vdq_out_pu = {_IQ(0.0),_IQ(0.0)};
306 
307 
308  // assign the motor type
309  CTRL_setMotorParams(handle,pUserParams->motor_type,
310  pUserParams->motor_numPolePairs,
311  pUserParams->motor_ratedFlux,
312  pUserParams->motor_Ls_d,
313  pUserParams->motor_Ls_q,
314  pUserParams->motor_Rr,
315  pUserParams->motor_Rs);
316 
317 
318  // assign other controller parameters
323 
324  CTRL_setCtrlFreq_Hz(handle,pUserParams->ctrlFreq_Hz);
325  CTRL_setTrajFreq_Hz(handle,pUserParams->trajFreq_Hz);
326  CTRL_setTrajPeriod_sec(handle,_IQ(1.0/pUserParams->trajFreq_Hz));
327 
328  CTRL_setCtrlPeriod_sec(handle,pUserParams->ctrlPeriod_sec);
329 
330  CTRL_setMaxVsMag_pu(handle,_IQ(pUserParams->maxVsMag_pu));
331 
332  CTRL_setIab_in_pu(handle,&Iab_out_pu);
333  CTRL_setIdq_in_pu(handle,&Idq_out_pu);
334  CTRL_setIdq_ref_pu(handle,&Idq_ref_pu);
335 
336  CTRL_setIdRated_pu(handle,_IQ(pUserParams->IdRated/pUserParams->iqFullScaleCurrent_A));
337 
338  CTRL_setVab_in_pu(handle,&Vab_in_pu);
339  CTRL_setVab_out_pu(handle,&Vab_out_pu);
340  CTRL_setVdq_out_pu(handle,&Vdq_out_pu);
341 
342  CTRL_setSpd_out_pu(handle,_IQ(0.0));
343 
344  CTRL_setRhf(handle,0.0);
345  CTRL_setLhf(handle,0.0);
346  CTRL_setRoverL(handle,0.0);
347 
348 
349  // reset the counters
351  CTRL_resetCounter_isr(handle);
352  CTRL_resetCounter_speed(handle);
353  CTRL_resetCounter_state(handle);
354  CTRL_resetCounter_traj(handle);
355 
356 
357  // set the wait times for each state
358  CTRL_setWaitTimes(handle,&pUserParams->ctrlWaitTime[0]);
359 
360 
361  // set flags
362  CTRL_setFlag_enablePowerWarp(handle,false);
363  CTRL_setFlag_enableCtrl(handle,false);
364  CTRL_setFlag_enableOffset(handle,true);
365  CTRL_setFlag_enableSpeedCtrl(handle,true);
367  CTRL_setFlag_enableDcBusComp(handle,true);
368 
369 
370  // initialize the controller error code
372 
373 
374  // set the default controller state
376 
377 
378  // set the number of current sensors
379  CTRL_setupClarke_I(handle,pUserParams->numCurrentSensors);
380 
381 
382  // set the number of voltage sensors
383  CTRL_setupClarke_V(handle,pUserParams->numVoltageSensors);
384 
385 
386  // set the default Id PID controller parameters
387  Kp = _IQ(0.1);
388  Ki = _IQ(pUserParams->ctrlPeriod_sec/0.004);
389  Kd = _IQ(0.0);
390  outMin = _IQ(-0.95);
391  outMax = _IQ(0.95);
392 
393  PID_setGains(obj->pidHandle_Id,Kp,Ki,Kd);
394  PID_setUi(obj->pidHandle_Id,_IQ(0.0));
395  PID_setMinMax(obj->pidHandle_Id,outMin,outMax);
396  CTRL_setGains(handle,CTRL_Type_PID_Id,Kp,Ki,Kd);
397 
398 
399  // set the default the Iq PID controller parameters
400  Kp = _IQ(0.1);
401  Ki = _IQ(pUserParams->ctrlPeriod_sec/0.004);
402  Kd = _IQ(0.0);
403  outMin = _IQ(-0.95);
404  outMax = _IQ(0.95);
405 
406  PID_setGains(obj->pidHandle_Iq,Kp,Ki,Kd);
407  PID_setUi(obj->pidHandle_Iq,_IQ(0.0));
408  PID_setMinMax(obj->pidHandle_Iq,outMin,outMax);
409  CTRL_setGains(handle,CTRL_Type_PID_Iq,Kp,Ki,Kd);
410 
411 
412  // set the default speed PID controller parameters
413  Kp = _IQ(0.02*pUserParams->maxCurrent*pUserParams->iqFullScaleFreq_Hz/pUserParams->iqFullScaleCurrent_A);
414  Ki = _IQ(2.0*pUserParams->maxCurrent*pUserParams->iqFullScaleFreq_Hz*pUserParams->ctrlPeriod_sec/pUserParams->iqFullScaleCurrent_A);
415  Kd = _IQ(0.0);
416  outMin = _IQ(-1.0);
417  outMax = _IQ(1.0);
418 
419  PID_setGains(obj->pidHandle_spd,Kp,Ki,Kd);
420  PID_setUi(obj->pidHandle_spd,_IQ(0.0));
421  PID_setMinMax(obj->pidHandle_spd,outMin,outMax);
422  CTRL_setGains(handle,CTRL_Type_PID_spd,Kp,Ki,Kd);
423 
424 
425  // set the speed reference
426  CTRL_setSpd_ref_pu(handle,_IQ(0.0));
427 
428 
429  // set the default Id current trajectory module parameters
435 
436 
437  // set the default the speed trajectory module parameters
443 
444 
445  // set the default maximum speed trajectory module parameters
448  TRAJ_setMinValue(obj->trajHandle_spdMax,_IQ(0.0)); // not used
449  TRAJ_setMaxValue(obj->trajHandle_spdMax,_IQ(0.0)); // not used
450  TRAJ_setMaxDelta(obj->trajHandle_spdMax,_IQ(0.0)); // not used
451 
452 
453  // set the default estimator parameters
454  CTRL_setEstParams(obj->estHandle,pUserParams);
455 
456 
457  // set the maximum modulation for the SVGEN module
458  maxModulation = _IQ(MATH_TWO_OVER_THREE);
459  SVGEN_setMaxModulation(obj->svgenHandle,maxModulation);
460 
461  return;
462 } // end of CTRL_setParams() function
463 
464 
465 void CTRL_setSpd_ref_pu(CTRL_Handle handle,const _iq spd_ref_pu)
466 {
467  CTRL_Obj *obj = (CTRL_Obj *)handle;
468 
469  obj->spd_ref = spd_ref_pu;
470 
471  return;
472 } // end of CTRL_setSpd_ref_pu() function
473 
474 
475 void CTRL_setSpd_ref_krpm(CTRL_Handle handle,const _iq spd_ref_krpm)
476 {
477  CTRL_Obj *obj = (CTRL_Obj *)handle;
478 
479  _iq krpm_to_pu_sf = EST_get_krpm_to_pu_sf(obj->estHandle);
480 
481  _iq spd_ref_pu = _IQmpy(spd_ref_krpm,krpm_to_pu_sf);
482 
483  obj->spd_ref = spd_ref_pu;
484 
485  return;
486 } // end of CTRL_setSpd_ref_krpm() function
487 
488 
490 {
491  CTRL_Obj *obj = (CTRL_Obj *)handle;
492 
493  uint_least16_t count_traj = CTRL_getCount_traj(handle);
494  uint_least16_t numCtrlTicksPerTrajTick = CTRL_getNumCtrlTicksPerTrajTick(handle);
495 
496 
497  // as needed, update the trajectory
498  if(count_traj >= numCtrlTicksPerTrajTick)
499  {
500  _iq intValue_Id = TRAJ_getIntValue(obj->trajHandle_Id);
501 
502  // reset the trajectory count
503  CTRL_resetCounter_traj(handle);
504 
505  // run the trajectories
506  CTRL_runTraj(handle);
507  } // end of if(gFlag_traj) block
508 
509  return;
510 } // end of CTRL_setup() function
511 
512 
513 void CTRL_setupClarke_I(CTRL_Handle handle,uint_least8_t numCurrentSensors)
514 {
515  CTRL_Obj *obj = (CTRL_Obj *)handle;
516  _iq alpha_sf,beta_sf;
517 
518 
519  // initialize the Clarke transform module for current
520  if(numCurrentSensors == 3)
521  {
522  alpha_sf = _IQ(MATH_ONE_OVER_THREE);
523  beta_sf = _IQ(MATH_ONE_OVER_SQRT_THREE);
524  }
525  else if(numCurrentSensors == 2)
526  {
527  alpha_sf = _IQ(1.0);
528  beta_sf = _IQ(MATH_ONE_OVER_SQRT_THREE);
529  }
530  else
531  {
532  alpha_sf = _IQ(0.0);
533  beta_sf = _IQ(0.0);
534  }
535 
536  // set the parameters
537  CLARKE_setScaleFactors(obj->clarkeHandle_I,alpha_sf,beta_sf);
538  CLARKE_setNumSensors(obj->clarkeHandle_I,numCurrentSensors);
539 
540  return;
541 } // end of CTRL_setupClarke_I() function
542 
543 
544 void CTRL_setupClarke_V(CTRL_Handle handle,uint_least8_t numVoltageSensors)
545 {
546  CTRL_Obj *obj = (CTRL_Obj *)handle;
547  _iq alpha_sf,beta_sf;
548 
549 
550  // initialize the Clarke transform module for current
551  if(numVoltageSensors == 3)
552  {
553  alpha_sf = _IQ(MATH_ONE_OVER_THREE);
554  beta_sf = _IQ(MATH_ONE_OVER_SQRT_THREE);
555  }
556  else
557  {
558  alpha_sf = _IQ(0.0);
559  beta_sf = _IQ(0.0);
560  }
561 
562  // set the parameters
563  CLARKE_setScaleFactors(obj->clarkeHandle_V,alpha_sf,beta_sf);
564  CLARKE_setNumSensors(obj->clarkeHandle_V,numVoltageSensors);
565 
566  return;
567 } // end of CTRL_setupClarke_V() function
568 
569 
571  const _iq angle_pu,
572  const _iq speed_ref_pu,
573  const _iq speed_fb_pu,
574  const _iq speed_outMax_pu,
575  const MATH_vec2 *pIdq_offset_pu,
576  const MATH_vec2 *pVdq_offset_pu,
577  const bool flag_enableSpeedCtrl,
578  const bool flag_enableCurrentCtrl)
579 {
580  CTRL_State_e ctrlState = CTRL_getState(handle);
581  uint_least16_t count_traj = CTRL_getCount_traj(handle);
582  uint_least16_t numCtrlTicksPerTrajTick = CTRL_getNumCtrlTicksPerTrajTick(handle);
583 
584 
585  // increment the state counter
586  CTRL_incrCounter_state(handle);
587 
588  // increment the trajectory count
589  CTRL_incrCounter_traj(handle);
590 
591  // run the appropriate controller
592  if(ctrlState == CTRL_State_OnLine)
593  {
594  // increment the current count
595  CTRL_incrCounter_current(handle);
596 
597  // increment the speed count
598  CTRL_incrCounter_speed(handle);
599  }
600 
601  // as needed, update the trajectory
602  if(count_traj >= numCtrlTicksPerTrajTick)
603  {
604  // reset the trajectory count
605  CTRL_resetCounter_traj(handle);
606 
607  // run the trajectories
608  CTRL_runTraj(handle);
609  } // end of if(gFlag_traj) block
610 
611 
612  CTRL_setAngle_pu(handle,angle_pu);
613  CTRL_setSpeed_ref_pu(handle,speed_ref_pu);
614  CTRL_setSpeed_fb_pu(handle,speed_fb_pu);
615  CTRL_setSpeed_outMax_pu(handle,speed_outMax_pu);
616 
617  CTRL_setIdq_offset_pu(handle,pIdq_offset_pu);
618  CTRL_setVdq_offset_pu(handle,pVdq_offset_pu);
619 
620  CTRL_setFlag_enableSpeedCtrl(handle,flag_enableSpeedCtrl);
621  CTRL_setFlag_enableCurrentCtrl(handle,flag_enableCurrentCtrl);
622 
623 
624  return;
625 } // end of CTRL_setup_user() function
626 
627 
628 void CTRL_setWaitTimes(CTRL_Handle handle,const uint_least32_t *pWaitTimes)
629 {
630  CTRL_Obj *obj = (CTRL_Obj *)handle;
631  uint_least16_t stateCnt;
632 
633  for(stateCnt=0;stateCnt<CTRL_numStates;stateCnt++)
634  {
635  obj->waitTimes[stateCnt] = pWaitTimes[stateCnt];
636  }
637 
638  return;
639 } // end of CTRL_setWaitTimes() function
640 
641 
643 {
644  CTRL_State_e ctrlState = CTRL_getState(handle);
645  bool flag_enableCtrl = CTRL_getFlag_enableCtrl(handle);
646  bool stateChanged = false;
647 
648 
649  if(flag_enableCtrl)
650  {
651  uint_least32_t waitTime = CTRL_getWaitTime(handle,ctrlState);
652  uint_least32_t counter_ctrlState = CTRL_getCount_state(handle);
653 
654 
655  // check for errors
656  CTRL_checkForErrors(handle);
657 
658 
659  if(counter_ctrlState >= waitTime)
660  {
661  // reset the counter
662  CTRL_resetCounter_state(handle);
663 
664 
665  if(ctrlState == CTRL_State_OnLine)
666  {
667  CTRL_Obj *obj = (CTRL_Obj *)handle;
668  _iq Id_target = TRAJ_getTargetValue(obj->trajHandle_Id);
669 
670  // update the estimator state
671  bool flag_estStateChanged = EST_updateState(obj->estHandle,Id_target);
672 
673  if(flag_estStateChanged)
674  {
675  // setup the controller
676  CTRL_setupCtrl(handle);
677 
678  // setup the trajectory
679  CTRL_setupTraj(handle);
680  }
681 
682  if(EST_isOnLine(obj->estHandle))
683  {
684  // setup the estimator for online state
685  CTRL_setupEstOnLineState(handle);
686  }
687 
688  if(EST_isLockRotor(obj->estHandle) ||
690  {
691  // set the enable controller flag to false
692  CTRL_setFlag_enableCtrl(handle,false);
693 
694  // set the next controller state
696  }
697  }
698  else if(ctrlState == CTRL_State_OffLine)
699  {
700  // set the next controller state
702  }
703  else if(ctrlState == CTRL_State_Idle)
704  {
705  CTRL_Obj *obj = (CTRL_Obj *)handle;
706  bool flag_enableUserMotorParams = CTRL_getFlag_enableUserMotorParams(handle);
707 
708  if(flag_enableUserMotorParams)
709  {
710  // initialize the motor parameters using values from the user.h file
711  CTRL_setUserMotorParams(handle);
712  }
713 
714  if(EST_isIdle(obj->estHandle))
715  {
716  // setup the estimator for idle state
717  CTRL_setupEstIdleState(handle);
718 
720  {
721  if(CTRL_getFlag_enableOffset(handle))
722  {
723  // set the next controller state
725  }
726  else
727  {
728  // set the next controller state
730  }
731  }
732  else
733  {
734  // set the next controller state
736  }
737  }
738  else if(EST_isLockRotor(obj->estHandle))
739  {
740  // set the next controller state
742  }
743  }
744  } // if(counter_ctrlState >= waitTime) loop
745  }
746  else
747  {
748  CTRL_Obj *obj = (CTRL_Obj *)handle;
749 
750  // set the next controller state
752 
753  // set the estimator to idle
754  if(!EST_isLockRotor(obj->estHandle))
755  {
757  {
758  EST_setIdle(obj->estHandle);
759  }
760  else
761  {
763 
764  EST_setRs_pu(obj->estHandle,_IQ30(0.0));
765  }
766  }
767  }
768 
769 
770  // check to see if the state changed
771  if(ctrlState != CTRL_getState(handle))
772  {
773  stateChanged = true;
774  }
775 
776  return(stateChanged);
777 } // end of CTRL_updateState() function
778 
779 // end of file
static void CTRL_setSpeed_outMax_pu(CTRL_Handle handle, const _iq speed_outMax_pu)
Sets the maximum output value for the speed controller.
Definition: 32b/ctrl.h:1736
PID Speed controller.
Definition: 32b/ctrl_obj.h:123
void CTRL_getGains(CTRL_Handle handle, const CTRL_Type_e ctrlType, _iq *pKp, _iq *pKi, _iq *pKd)
Gets the gain values for the specified controller.
Definition: 32b/ctrl.c:78
static void CTRL_setIdq_offset_pu(CTRL_Handle handle, const MATH_vec2 *pIdq_offset_pu)
Sets the direct/quadrature current (Idq) offset vector values in the controller.
Definition: 32b/ctrl.h:1370
void CTRL_incrCounter_isr(CTRL_Handle handle)
Increments the isr counter.
Definition: 32b/ctrl.h:967
static void TRAJ_setTargetValue(TRAJ_Handle handle, const _iq targetValue)
Sets the target value for the trajectory.
Definition: 32b/traj.h:206
float_t motor_Ls_q
Defines the quadrature stator inductance, H.
void CTRL_setupEstOnLineState(CTRL_Handle handle)
Sets up the controller and trajectory generator for the estimator online state.
void CTRL_getIdq_ref_pu(CTRL_Handle handle, MATH_vec2 *pIdq_ref_pu)
Gets the direct/quadrature current reference vector values from the controller.
Definition: 32b/ctrl.c:123
void CTRL_run(CTRL_Handle handle, HAL_Handle halHandle, const HAL_AdcData_t *pAdcData, HAL_PwmData_t *pPwmData)
Runs the controller.
Definition: 32b/ctrl.c:195
MATH_vec2 Vab_in
the Vab input values
Definition: 32b/ctrl_obj.h:219
MATH_vec2 Idq_ref
the Idq reference values, pu
Definition: 32b/ctrl_obj.h:247
void CTRL_getIab_filt_pu(CTRL_Handle handle, MATH_vec2 *pIab_filt_pu)
Gets the alpha/beta filtered current vector values from the controller.
Definition: 32b/ctrl.c:90
CLARKE_Handle clarkeHandle_I
the handle for the current Clarke transform
Definition: 32b/ctrl_obj.h:154
#define _IQ(A)
static void TRAJ_setMaxDelta(TRAJ_Handle handle, const _iq maxDelta)
Sets the maximum delta value for the trajectory.
Definition: 32b/traj.h:167
void CTRL_resetCounter_state(CTRL_Handle handle)
Resets the state counter.
Definition: 32b/ctrl.h:1107
float_t iqFullScaleCurrent_A
Defines the full scale current for the IQ variables, A.
float_t IdRated
Defines the Id rated current value, A.
motor identified state
Definition: est_states.h:68
static void PID_setUi(PID_Handle handle, const _iq Ui)
Sets the integrator start value in the PID controller.
Definition: 32b/pid.h:409
void CTRL_setupClarke_V(CTRL_Handle handle, uint_least8_t numVoltageSensors)
Sets the number of voltage sensors.
Definition: 32b/ctrl.c:544
void CTRL_setEstParams(EST_Handle estHandle, USER_Params *pUserParams)
Sets the default estimator parameters.
void CTRL_setMotorParams(CTRL_Handle handle, const MOTOR_Type_e motorType, const uint_least16_t numPolePairs, const float_t ratedFlux, const float_t Ls_d, const float_t Ls_q, const float_t Rr, const float_t Rs)
Sets the parameters for the motor in the controller.
Definition: 32b/ctrl.h:1581
#define MATH_TWO_OVER_THREE
Defines 2/3.
Definition: 32b/math.h:77
static _iq TRAJ_getIntValue(TRAJ_Handle handle)
Gets the intermediate value for the trajectory.
Definition: 32b/traj.h:92
void CTRL_setIab_in_pu(CTRL_Handle handle, const MATH_vec2 *pIab_in_pu)
Sets the alpha/beta current (Iab) input vector values in the controller.
Definition: 32b/ctrl.h:1323
_iq spd_ref
the speed reference, pu
Definition: 32b/ctrl_obj.h:251
void CTRL_getVdq_out_pu(CTRL_Handle handle, MATH_vec2 *pVdq_out_pu)
Gets the direct/quadrature voltage output vector values from the controller.
Definition: 32b/ctrl.c:170
float_t motor_Rr
Defines the rotor resistance, ohm.
Defines a two element vector.
Definition: 32b/math.h:248
the number of controller states
Definition: ctrl_states.h:39
bool EST_isOnLine(EST_Handle handle)
Determines if the estimator is ready for online control.
_iq CTRL_getKd(CTRL_Handle handle, const CTRL_Type_e ctrlType)
Gets the derivative gain (Kd) value from the specified controller.
Definition: 32b/ctrl.h:473
_iq value[3]
Definition: 32b/math.h:261
void CTRL_incrCounter_current(CTRL_Handle handle)
Increments the current counter.
Definition: 32b/ctrl.h:949
float_t ctrlPeriod_sec
Defines the controller execution period, sec.
TRAJ_Handle trajHandle_Id
the handle for the Id trajectory generator
Definition: 32b/ctrl_obj.h:180
void EST_setIdle(EST_Handle handle)
Sets the estimator to idle.
uint_least16_t CTRL_getNumCtrlTicksPerTrajTick(CTRL_Handle handle)
Gets the number of controller clock ticks per trajectory clock tick.
Definition: 32b/ctrl.h:602
uint_least16_t CTRL_getNumIsrTicksPerCtrlTick(CTRL_Handle handle)
Gets the number of Interrupt Service Routine (ISR) clock ticks per controller clock tick...
Definition: 32b/ctrl.h:613
TRAJ_Handle trajHandle_spd
the handle for the speed trajectory generator
Definition: 32b/ctrl_obj.h:183
void CTRL_setVab_in_pu(CTRL_Handle handle, const MATH_vec2 *pVab_in_pu)
Sets the alpha/beta voltage input vector values in the controller.
Definition: 32b/ctrl.h:1882
void CTRL_setSpd_max_pu(CTRL_Handle handle, const _iq maxSpd_pu)
Sets the maximum speed value in the controller.
Definition: 32b/ctrl.h:1710
MATH_vec2 Vab_out
the Vab output values
Definition: 32b/ctrl_obj.h:223
the controller idle state
Definition: ctrl_states.h:36
PID_Handle pidHandle_Id
the handle for the Id PID controller
Definition: 32b/ctrl_obj.h:165
uint_least32_t ctrlWaitTime[CTRL_numStates]
Defines the wait times for each controller state, estimator ticks.
Defines the controller (CTRL) object.
Definition: 32b/ctrl_obj.h:144
void CTRL_setTrajPeriod_sec(CTRL_Handle handle, const _iq trajPeriod_sec)
Sets the trajectory execution period.
Definition: 32b/ctrl.h:1801
void CTRL_setMagCurrent_pu(CTRL_Handle handle, const _iq magCurrent_pu)
Sets the magnetizing current value in the controller.
Definition: 32b/ctrl.c:274
Defines a structure for the user parameters.
uint_least8_t numCurrentSensors
Defines the number of current sensors.
uint_least16_t CTRL_getCount_traj(CTRL_Handle handle)
Gets the trajectory loop count.
Definition: 32b/ctrl.h:139
EST_Handle estHandle
the handle for the parameter estimator
Definition: 32b/ctrl_obj.h:160
void CTRL_setKi(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Ki)
Sets the integral gain (Ki) value for the specified controller.
Definition: 32b/ctrl.h:1474
static void PID_setMinMax(PID_Handle handle, const _iq outMin, const _iq outMax)
Sets the minimum and maximum output value allowed in the PID controller.
Definition: 32b/pid.h:356
void CTRL_setFlag_enableCtrl(CTRL_Handle handle, const bool state)
Sets the enable controller flag value in the estimator.
Definition: 32b/ctrl.h:1214
void CTRL_setFlag_enableSpeedCtrl(CTRL_Handle handle, const bool state)
Sets the enable speed control value in the estimator.
Definition: 32b/ctrl.h:1284
void CTRL_getIab_in_pu(CTRL_Handle handle, MATH_vec2 *pIab_in_pu)
Gets the alpha/beta current input vector values from the controller.
Definition: 32b/ctrl.c:101
float_t maxCurrent
Defines the maximum current value, A.
uint_least32_t CTRL_getWaitTime(CTRL_Handle handle, const CTRL_State_e ctrlState)
Gets the wait time for a given state.
Definition: 32b/ctrl.h:933
void CTRL_runTraj(CTRL_Handle handle)
Runs the trajectory.
void CTRL_setIdq_ref_pu(CTRL_Handle handle, const MATH_vec2 *pIdq_ref_pu)
Sets the direct/quadrature current (Idq) reference vector values in the controller.
Definition: 32b/ctrl.h:1384
long _iq
uint_least16_t numCtrlTicksPerCurrentTick
Defines the number of controller clock ticks per current controller clock tick.
#define MATH_ONE_OVER_THREE
Defines 1/3.
Definition: 32b/math.h:81
void CTRL_resetCounter_current(CTRL_Handle handle)
Resets the current counter.
Definition: 32b/ctrl.h:1071
uint_least16_t CTRL_getCount_isr(CTRL_Handle handle)
Gets the isr count.
Definition: 32b/ctrl.h:106
static void CTRL_setFlag_enableCurrentCtrl(CTRL_Handle handle, const bool state)
Sets the enable current controllers flag value in the controller.
Definition: 32b/ctrl.h:1227
TRAJ_Handle trajHandle_spdMax
the handle for the maximum speed trajectory generator
Definition: 32b/ctrl_obj.h:186
void CTRL_setGains(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Kp, const _iq Ki, const _iq Kd)
Sets the gain values for the specified controller.
Definition: 32b/ctrl.c:262
static void CLARKE_setScaleFactors(CLARKE_Handle handle, const _iq alpha_sf, const _iq beta_sf)
Sets the scale factors.
Definition: 32b/clarke.h:180
void CTRL_setupTraj(CTRL_Handle handle)
Sets up the trajectory (TRAJ) object.
void CTRL_setState(CTRL_Handle handle, const CTRL_State_e state)
Sets the controller state.
Definition: 32b/ctrl.h:1774
static _iq TRAJ_getTargetValue(TRAJ_Handle handle)
Gets the target value for the trajectory.
Definition: 32b/traj.h:136
static void TRAJ_setIntValue(TRAJ_Handle handle, const _iq intValue)
Sets the intermediate value for the trajectory.
Definition: 32b/traj.h:154
MATH_vec3 Tabc
the PWM time-durations for each motor phase
static void PID_setGains(PID_Handle handle, const _iq Kp, const _iq Ki, const _iq Kd)
Sets the gains in the PID controller.
Definition: 32b/pid.h:301
void CTRL_setParams(CTRL_Handle handle, USER_Params *pUserParams)
Sets the controller parameters.
Definition: 32b/ctrl.c:292
MOTOR_Type_e motor_type
Defines the motor type.
static void CTRL_setAngle_pu(CTRL_Handle handle, const _iq angle_pu)
Sets the angle value, pu.
Definition: 32b/ctrl.h:1150
#define _IQmpy(A, B)
void CTRL_getIdq_in_pu(CTRL_Handle handle, MATH_vec2 *pIdq_in_pu)
Gets the direct/quadrature current input vector values from the controller.
Definition: 32b/ctrl.c:112
void CTRL_setWaitTimes(CTRL_Handle handle, const uint_least32_t *pWaitTimes)
Sets the wait times for the controller states.
Definition: 32b/ctrl.c:628
_iq CTRL_getSpd_max_pu(CTRL_Handle handle)
Gets the maximum speed value from the controller.
Definition: 32b/ctrl.h:701
void CTRL_setVdq_out_pu(CTRL_Handle handle, const MATH_vec2 *pVdq_out_pu)
Sets the direct/quadrature voltage output vector values in the controller.
Definition: 32b/ctrl.h:1924
void CTRL_incrCounter_speed(CTRL_Handle handle)
Increments the speed counter.
Definition: 32b/ctrl.h:985
void CTRL_resetCounter_isr(CTRL_Handle handle)
Resets the isr counter.
Definition: 32b/ctrl.h:1083
_iq value[2]
Definition: 32b/math.h:251
void CTRL_runOnLine_User(CTRL_Handle handle, const HAL_AdcData_t *pAdcData, HAL_PwmData_t *pPwmData)
Runs the online user controller.
Definition: 32b/ctrl.h:2343
void CTRL_setNumCtrlTicksPerTrajTick(CTRL_Handle handle, const uint_least16_t numCtrlTicksPerTrajTick)
Sets the number of controller clock ticks per trajectory clock tick.
Definition: 32b/ctrl.h:1643
MATH_vec2 Idq_in
the Idq input values
Definition: 32b/ctrl_obj.h:217
PID_Handle pidHandle_spd
the handle for the speed PID controller
Definition: 32b/ctrl_obj.h:171
void CTRL_setIdq_in_pu(CTRL_Handle handle, const MATH_vec2 *pIdq_in_pu)
Sets the direct/quadrature current (Idq) input vector values in the controller.
Definition: 32b/ctrl.h:1356
uint_least32_t trajFreq_Hz
Defines the trajectory frequency, Hz.
void CTRL_setSpd_out_pu(CTRL_Handle handle, const _iq spd_out_pu)
Sets the output speed value in the controller.
Definition: 32b/ctrl.h:1723
uint_least8_t numVoltageSensors
Defines the number of voltage sensors.
bool CTRL_getFlag_enableUserMotorParams(CTRL_Handle handle)
Gets the enable user motor parameters flag value from the controller.
Definition: 32b/ctrl.h:270
void CTRL_incrCounter_state(CTRL_Handle handle)
Increments the state counter.
Definition: 32b/ctrl.h:1003
void CTRL_setupEstIdleState(CTRL_Handle handle)
Sets up the controller and trajectory generator for the estimator idle state.
CTRL_State_e CTRL_getState(CTRL_Handle handle)
Gets the controller state.
Definition: 32b/ctrl.h:767
void CTRL_setUserMotorParams(CTRL_Handle handle)
Sets the controller and estimator with motor parameters from the user.h file.
void CTRL_setLhf(CTRL_Handle handle, const float_t Lhf)
Sets the high frequency inductance (Lhf) value in the controller.
Definition: 32b/ctrl.h:1523
Contains the public interface to the math (MATH) module routines.
void CTRL_setCtrlPeriod_sec(CTRL_Handle handle, const float_t ctrlPeriod_sec)
Sets the controller execution period.
Definition: 32b/ctrl.h:1176
static void SVGEN_setMaxModulation(SVGEN_Handle handle, const _iq maxModulation)
Sets the maximum modulation in the space vector generator module.
Definition: 32b/svgen.h:174
EST_State_e EST_getState(EST_Handle handle)
Gets the state of the estimator.
_iq CTRL_getMaximumSpeed_pu(CTRL_Handle handle)
Gets the maximum speed value from the controller.
Definition: 32b/ctrl.c:141
MATH_vec2 Iab_filt
the Iab filtered values
Definition: 32b/ctrl_obj.h:215
static void CTRL_setVdq_offset_pu(CTRL_Handle handle, const MATH_vec2 *pVdq_offset_pu)
Sets the direct/quadrature voltage (Vdq) offset vector values in the controller.
Definition: 32b/ctrl.h:1910
MATH_vec2 Vdq_out
the Vdq output values
Definition: 32b/ctrl_obj.h:225
uint_least32_t waitTimes[CTRL_numStates]
an array of wait times for each state, estimator clock counts
Definition: 32b/ctrl_obj.h:191
void CTRL_setNumCtrlTicksPerCurrentTick(CTRL_Handle handle, const uint_least16_t numCtrlTicksPerCurrentTick)
Sets the number of controller clock ticks per current controller clock tick.
Definition: 32b/ctrl.h:1615
_iq CTRL_getKp(CTRL_Handle handle, const CTRL_Type_e ctrlType)
Gets the proportional gain (Kp) value from the specified controller.
Definition: 32b/ctrl.h:499
void CTRL_setup(CTRL_Handle handle)
Sets up the controller (CTRL) object and all of the subordinate objects.
Definition: 32b/ctrl.c:489
void CTRL_getVab_out_pu(CTRL_Handle handle, MATH_vec2 *pVab_out_pu)
Gets the alpha/beta voltage output vector values from the controller.
Definition: 32b/ctrl.c:159
void CTRL_setSpd_ref_pu(CTRL_Handle handle, const _iq spd_ref_pu)
Sets the output speed reference value in the controller.
Definition: 32b/ctrl.c:465
CTRL_State_e
Enumeration for the controller states.
Definition: ctrl_states.h:34
the controller online state
Definition: ctrl_states.h:38
CLARKE_Handle clarkeHandle_V
the handle for the voltage Clarke transform
Definition: 32b/ctrl_obj.h:157
void CTRL_setTrajFreq_Hz(CTRL_Handle handle, const uint_least32_t trajFreq_Hz)
Sets the trajectory execution frequency.
Definition: 32b/ctrl.h:1788
static void CTRL_setSpeed_fb_pu(CTRL_Handle handle, const _iq speed_fb_pu)
Sets the feedback speed value in the controller.
Definition: 32b/ctrl.h:1697
void CTRL_runOffLine(CTRL_Handle handle, HAL_Handle halHandle, const HAL_AdcData_t *pAdcData, HAL_PwmData_t *pPwmData)
Runs the offline controller.
Definition: 32b/ctrl.h:2089
void CTRL_setErrorCode(CTRL_Handle handle, const CTRL_ErrorCode_e errorCode)
Sets the error code in the controller.
Definition: 32b/ctrl.h:1189
static void CLARKE_setNumSensors(CLARKE_Handle handle, const uint_least8_t numSensors)
Sets the number of sensors.
Definition: 32b/clarke.h:166
void CTRL_setVab_out_pu(CTRL_Handle handle, const MATH_vec2 *pVab_out_pu)
Sets the alpha/beta current output vector values in the controller.
Definition: 32b/ctrl.h:1896
void CTRL_setMaxVsMag_pu(CTRL_Handle handle, const _iq maxVsMag)
Sets the maximum voltage vector in the controller.
Definition: 32b/ctrl.h:1542
void CTRL_resetCounter_traj(CTRL_Handle handle)
Resets the trajectory counter.
Definition: 32b/ctrl.h:1119
#define _IQ30(A)
uint_least16_t numCtrlTicksPerTrajTick
Defines the number of controller clock ticks per trajectory clock tick.
PID_Handle pidHandle_Iq
the handle for the Iq PID controller
Definition: 32b/ctrl_obj.h:168
void CTRL_setup_user(CTRL_Handle handle, const _iq angle_pu, const _iq speed_ref_pu, const _iq speed_fb_pu, const _iq speed_outMax_pu, const MATH_vec2 *pIdq_offset_pu, const MATH_vec2 *pVdq_offset_pu, const bool flag_enableSpeedCtrl, const bool flag_enableCurrentCtrl)
Sets up the speed and current controllers.
Definition: 32b/ctrl.c:570
uint_least16_t numCtrlTicksPerSpeedTick
Defines the number of controller clock ticks per speed controller clock tick.
_iq CTRL_getIdRated_pu(CTRL_Handle handle)
Gets the Id rated current value from the controller.
Definition: 32b/ctrl.h:381
void CTRL_setFlag_enablePowerWarp(CTRL_Handle handle, const bool state)
Sets the PowerWarp enable flag value in the estimator.
Definition: 32b/ctrl.h:1258
no error error code
Definition: 32b/ctrl_obj.h:100
bool CTRL_updateState(CTRL_Handle handle)
Updates the controller state.
Definition: 32b/ctrl.c:642
CTRL_Type_e
Enumeration for the controller (CTRL) types.
Definition: 32b/ctrl_obj.h:121
_iq CTRL_getKi(CTRL_Handle handle, const CTRL_Type_e ctrlType)
Gets the integral gain (Ki) value from the specified controller.
Definition: 32b/ctrl.h:447
void CTRL_getWaitTimes(CTRL_Handle handle, uint_least32_t *pWaitTimes)
Gets the wait times from the estimator.
Definition: 32b/ctrl.c:181
static void TRAJ_setMaxValue(TRAJ_Handle handle, const _iq maxValue)
Sets the maximum value for the trajectory.
Definition: 32b/traj.h:180
bool CTRL_getFlag_enableCtrl(CTRL_Handle handle)
Gets the enable controller flag value from the estimator.
Definition: 32b/ctrl.h:204
bool EST_isMotorIdentified(EST_Handle handle)
Determines if the motor has been identified.
void CTRL_setRhf(CTRL_Handle handle, const float_t Rhf)
Sets the high frequency resistance (Rhf) value in the controller.
Definition: 32b/ctrl.h:1671
void CTRL_setFlag_enableOffset(CTRL_Handle handle, const bool state)
Sets the enable offset flag value in the estimator.
Definition: 32b/ctrl.h:1271
float_t motor_Rs
Defines the stator resistance, ohm.
bool EST_isLockRotor(EST_Handle handle)
Determines if the estimator is waiting for the rotor to be locked.
uint_least16_t numIsrTicksPerCtrlTick
Defines the number of Interrupt Service Routine (ISR) clock ticks per controller clock tick...
void CTRL_setFlag_enableDcBusComp(CTRL_Handle handle, const bool state)
Sets the enable DC bus compensation flag value in the estimator.
Definition: 32b/ctrl.h:1242
void EST_setRs_pu(EST_Handle handle, const _iq Rs_pu)
Sets the stator resistance value used in the estimator in per unit (pu), IQ30.
PID Iq controller.
Definition: 32b/ctrl_obj.h:125
void CTRL_setFlag_enableUserMotorParams(CTRL_Handle handle, const bool state)
Sets the enable user motor parameters flag value in the estimator.
Definition: 32b/ctrl.h:1300
void CTRL_setKd(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Kd)
Sets the derivative gain (Kd) value for the specified controller.
Definition: 32b/ctrl.h:1449
_iq CTRL_getMagCurrent_pu(CTRL_Handle handle)
Gets the magnetizing current value from the controller.
Definition: 32b/ctrl.c:134
uint_least32_t ctrlFreq_Hz
Defines the controller frequency, Hz.
static void CTRL_setSpeed_ref_pu(CTRL_Handle handle, const _iq speed_ref_pu)
Sets the output speed reference value in the controller.
Definition: 32b/ctrl.h:1749
void CTRL_setIdRated_pu(CTRL_Handle handle, const _iq IdRated_pu)
Sets the Id rated current value in the controller.
Definition: 32b/ctrl.h:1398
_iq EST_get_krpm_to_pu_sf(EST_Handle handle)
Gets the krpm to pu scale factor in per unit (pu), IQ24.
bool EST_isIdle(EST_Handle handle)
Determines if the estimator is idle.
void CTRL_setCtrlFreq_Hz(CTRL_Handle handle, const uint_least32_t ctrlFreq_Hz)
Sets the controller frequency.
Definition: 32b/ctrl.h:1163
PID Id controller.
Definition: 32b/ctrl_obj.h:124
uint_least16_t motor_numPolePairs
Defines the number of pole pairs for the motor.
void CTRL_resetCounter_speed(CTRL_Handle handle)
Resets the speed counter.
Definition: 32b/ctrl.h:1095
#define MATH_ONE_OVER_SQRT_THREE
Defines 1/sqrt(3)
Definition: 32b/math.h:89
void CTRL_checkForErrors(CTRL_Handle handle)
Checks for any controller errors and, if found, sets the controller state to the error state...
Definition: 32b/ctrl.h:1982
void CTRL_getVab_in_pu(CTRL_Handle handle, MATH_vec2 *pVab_in_pu)
Gets the alpha/beta voltage input vector values from the controller.
Definition: 32b/ctrl.c:148
void CTRL_setMaximumSpeed_pu(CTRL_Handle handle, const _iq maxSpeed_pu)
Sets the maximum speed value in the controller.
Definition: 32b/ctrl.c:283
void EST_setIdle_all(EST_Handle handle)
Sets the estimator and all of the subordinate estimators to idle.
void CTRL_setNumCtrlTicksPerSpeedTick(CTRL_Handle handle, const uint_least16_t numCtrlTicksPerSpeedTick)
Sets the number of controller clock ticks per speed controller clock tick.
Definition: 32b/ctrl.h:1629
MATH_vec2 Iab_in
the Iab input values
Definition: 32b/ctrl_obj.h:213
uint_least32_t CTRL_getCount_state(CTRL_Handle handle)
Gets the state count.
Definition: 32b/ctrl.h:128
bool EST_updateState(EST_Handle handle, const _iq Id_target_pu)
Updates the estimator state.
Contains the public interface to the data logging (DLOG) module routines.
void CTRL_setRoverL(CTRL_Handle handle, const float_t RoverL)
Sets the R/L value in the controller.
Definition: 32b/ctrl.h:1684
the controller offline state
Definition: ctrl_states.h:37
void CTRL_incrCounter_traj(CTRL_Handle handle)
Increments the trajectory counter.
Definition: 32b/ctrl.h:1021
void CTRL_setNumIsrTicksPerCtrlTick(CTRL_Handle handle, const uint_least16_t numIsrTicksPerCtrlTick)
Sets the number of Interrupt Service Routine (ISR) clock ticks per controller clock tick...
Definition: 32b/ctrl.h:1657
float_t iqFullScaleFreq_Hz
Defines the full scale frequency for IQ variable, Hz.
void CTRL_setSpd_ref_krpm(CTRL_Handle handle, const _iq spd_ref_krpm)
Sets the output speed reference value in the controller.
Definition: 32b/ctrl.c:475
void CTRL_setupClarke_I(CTRL_Handle handle, uint_least8_t numCurrentSensors)
Sets the number of current sensors.
Definition: 32b/ctrl.c:513
void CTRL_setKp(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Kp)
Sets the proportional gain (Kp) value for the specified controller.
Definition: 32b/ctrl.h:1499
void CTRL_setupCtrl(CTRL_Handle handle)
Sets up the controllers.
float_t motor_Ls_d
Defines the direct stator inductance, H.
Defines the hardware abstraction layer (HAL) data.
float_t motor_ratedFlux
Defines the rated flux of the motor, V/Hz.
void CTRL_runOnLine(CTRL_Handle handle, const HAL_AdcData_t *pAdcData, HAL_PwmData_t *pPwmData)
Runs the online controller.
Definition: 32b/ctrl.h:2158
static void TRAJ_setMinValue(TRAJ_Handle handle, const _iq minValue)
Sets the minimum value for the trajectory.
Definition: 32b/traj.h:193
SVGEN_Handle svgenHandle
the handle for the space vector generator
Definition: 32b/ctrl_obj.h:177
float_t maxVsMag_pu
Defines the maximum voltage magnitude, pu.
bool CTRL_getFlag_enableOffset(CTRL_Handle handle)
Gets the enable offset flag value from the controller.
Definition: 32b/ctrl.h:248