MotorWare f2806x Module API Documentation
32b/ctrl.h
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 #ifndef _CTRL_H_
33 #define _CTRL_H_
34 
40 
41 
42 // **************************************************************************
43 // the includes
44 
46 
57 
59 
60 #include "hal_obj.h"
61 
62 
67 
68 
69 
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73 
74 
75 // **************************************************************************
76 // the function prototypes
77 
78 
81 inline void CTRL_addVdq_offset(CTRL_Handle handle)
82 {
83  CTRL_Obj *obj = (CTRL_Obj *)handle;
84 
85  obj->Vdq_out.value[0] += obj->Vdq_offset_pu.value[0];
86  obj->Vdq_out.value[1] += obj->Vdq_offset_pu.value[1];
87 
88  return;
89 } // return CTRL_addVdq_offset() function
90 
91 
95 inline uint_least16_t CTRL_getCount_current(CTRL_Handle handle)
96 {
97  CTRL_Obj *obj = (CTRL_Obj *)handle;
98 
99  return(obj->counter_current);
100 } // end of CTRL_getCount_current() function
101 
102 
106 inline uint_least16_t CTRL_getCount_isr(CTRL_Handle handle)
107 {
108  CTRL_Obj *obj = (CTRL_Obj *)handle;
109 
110  return(obj->counter_isr);
111 } // end of CTRL_getCount_isr() function
112 
113 
117 inline uint_least16_t CTRL_getCount_speed(CTRL_Handle handle)
118 {
119  CTRL_Obj *obj = (CTRL_Obj *)handle;
120 
121  return(obj->counter_speed);
122 } // end of CTRL_getCount_speed() function
123 
124 
128 inline uint_least32_t CTRL_getCount_state(CTRL_Handle handle)
129 {
130  CTRL_Obj *obj = (CTRL_Obj *)handle;
131 
132  return(obj->counter_state);
133 } // end of CTRL_getCount_state() function
134 
135 
139 inline uint_least16_t CTRL_getCount_traj(CTRL_Handle handle)
140 {
141  CTRL_Obj *obj = (CTRL_Obj *)handle;
142 
143  return(obj->counter_traj);
144 } // end of CTRL_getCount_traj() function
145 
146 
150 inline uint_least32_t CTRL_getCtrlFreq(CTRL_Handle handle)
151 {
152  CTRL_Obj *obj = (CTRL_Obj *)handle;
153 
154  return(obj->ctrlFreq_Hz);
155 } // end of CTRL_getCtrlFreq() function
156 
157 
162 {
163  CTRL_Obj *obj = (CTRL_Obj *)handle;
164 
165  return(obj->ctrlPeriod_sec);
166 } // end of CTRL_getCtrlPeriod_sec() function
167 
168 
173 {
174  CTRL_Obj *obj = (CTRL_Obj *)handle;
175 
176  return(obj->errorCode);
177 } // end of CTRL_getErrorCode() function
178 
179 
184 {
185  CTRL_Obj *obj = (CTRL_Obj *)handle;
186 
187  return(obj->estHandle);
188 } // end of CTRL_getEstHandle() function
189 
190 
194 {
195  CTRL_Obj *obj = (CTRL_Obj *)handle;
196 
197  return(obj->speed_fb_pu);
198 } // end of CTRL_getFbackValue_spd_pu() function
199 
200 
205 {
206  CTRL_Obj *obj = (CTRL_Obj *)handle;
207 
208  return(obj->flag_enableCtrl);
209 } // end of CTRL_getFlag_enableCtrl() function
210 
211 
216 {
217  CTRL_Obj *obj = (CTRL_Obj *)handle;
218 
219  return(obj->flag_enableCurrentCtrl);
220 } // end of CTRL_getFlag_enableCurrentCtrl() function
221 
222 
227 {
228  CTRL_Obj *obj = (CTRL_Obj *)handle;
229 
230  return(obj->flag_enableDcBusComp);
231 } // end of CTRL_getFlag_enableDcBusComp() function
232 
233 
238 {
239  CTRL_Obj *obj = (CTRL_Obj *)handle;
240 
241  return(obj->flag_enablePowerWarp);
242 } // end of CTRL_getFlag_enablePowerWarp() function
243 
244 
249 {
250  CTRL_Obj *obj = (CTRL_Obj *)handle;
251 
252  return(obj->flag_enableOffset);
253 } // end of CTRL_getFlag_enableOffset() function
254 
255 
260 {
261  CTRL_Obj *obj = (CTRL_Obj *)handle;
262 
263  return(obj->flag_enableSpeedCtrl);
264 } // end of CTRL_getFlag_enableSpeedCtrl() function
265 
266 
271 {
272  CTRL_Obj *obj = (CTRL_Obj *)handle;
273 
274  return(obj->flag_enableUserMotorParams);
275 } // end of CTRL_getFlag_enableUserMotorParams() function
276 
277 
284 void CTRL_getGains(CTRL_Handle handle,const CTRL_Type_e ctrlType,
285  _iq *pKp,_iq *pKi,_iq *pKd);
286 
287 
291 void CTRL_getIab_filt_pu(CTRL_Handle handle,MATH_vec2 *pIab_filt_pu);
292 
293 
298 {
299  CTRL_Obj *obj = (CTRL_Obj *)handle;
300 
301  return(&(obj->Iab_filt));
302 } // end of CTRL_getIab_filt_addr() function
303 
304 
309 {
310  CTRL_Obj *obj = (CTRL_Obj *)handle;
311 
312  return(&(obj->Iab_in));
313 } // end of CTRL_getIab_in_addr() function
314 
315 
319 void CTRL_getIab_in_pu(CTRL_Handle handle,MATH_vec2 *pIab_in_pu);
320 
321 
326 {
327  CTRL_Obj *obj = (CTRL_Obj *)handle;
328 
329  return(obj->Idq_in.value[0]);
330 } // end of CTRL_getId_in_pu() function
331 
332 
337 {
338  CTRL_Obj *obj = (CTRL_Obj *)handle;
339 
340  return(obj->Idq_ref.value[0]);
341 } // end of CTRL_getId_ref_pu() function
342 
343 
348 {
349  CTRL_Obj *obj = (CTRL_Obj *)handle;
350 
351  return(&(obj->Idq_in));
352 } // end of CTRL_getIdq_in_addr() function
353 
354 
358 void CTRL_getIdq_in_pu(CTRL_Handle handle,MATH_vec2 *pIdq_in_pu);
359 
360 
364 void CTRL_getIdq_ref_pu(CTRL_Handle handle,MATH_vec2 *pIdq_ref_pu);
365 
366 
370 static inline _iq CTRL_getId_offset_pu(CTRL_Handle handle)
371 {
372  CTRL_Obj *obj = (CTRL_Obj *)handle;
373 
374  return(obj->Idq_offset_pu.value[0]);
375 } // end of CTRL_getId_offset_pu() function
376 
377 
382 {
383  CTRL_Obj *obj = (CTRL_Obj *)handle;
384 
385  return(obj->IdRated);
386 } // end of CTRL_getIdRated_pu() function
387 
388 
393 {
394  CTRL_Obj *obj = (CTRL_Obj *)handle;
395 
396  return(obj->Idq_in.value[1]);
397 } // end of CTRL_getIq_in_pu() function
398 
399 
403 static inline _iq CTRL_getIq_offset_pu(CTRL_Handle handle)
404 {
405  CTRL_Obj *obj = (CTRL_Obj *)handle;
406 
407  return(obj->Idq_offset_pu.value[1]);
408 } // end of CTRL_getIq_offset_pu() function
409 
410 
415 {
416  CTRL_Obj *obj = (CTRL_Obj *)handle;
417 
418  return(obj->Idq_ref.value[1]);
419 } // end of CTRL_getIq_ref_pu() function
420 
421 
425 {
426  _iq refValue_pu = CTRL_getIq_ref_pu(handle) + CTRL_getIq_offset_pu(handle);
427 
428  return(refValue_pu);
429 } // end of CTRL_getRefValue_Iq_pu() function
430 
431 
435 static inline _iq *CTRL_getIq_ref_pu_addr(CTRL_Handle handle)
436 {
437  CTRL_Obj *obj = (CTRL_Obj *)handle;
438 
439  return(&(obj->Idq_ref.value[1]));
440 } // end of CTRL_getIq_ref_pu_addr() function
441 
442 
447 inline _iq CTRL_getKi(CTRL_Handle handle,const CTRL_Type_e ctrlType)
448 {
449  CTRL_Obj *obj = (CTRL_Obj *)handle;
450  _iq Ki = _IQ(0.0);
451 
452  if(ctrlType == CTRL_Type_PID_spd)
453  {
454  Ki = obj->Ki_spd;
455  }
456  else if(ctrlType == CTRL_Type_PID_Id)
457  {
458  Ki = obj->Ki_Id;
459  }
460  else if(ctrlType == CTRL_Type_PID_Iq)
461  {
462  Ki = obj->Ki_Iq;
463  }
464 
465  return(Ki);
466 } // end of CTRL_getKi() function
467 
468 
473 inline _iq CTRL_getKd(CTRL_Handle handle,const CTRL_Type_e ctrlType)
474 {
475  CTRL_Obj *obj = (CTRL_Obj *)handle;
476  _iq Kd = _IQ(0.0);
477 
478  if(ctrlType == CTRL_Type_PID_spd)
479  {
480  Kd = obj->Kd_spd;
481  }
482  else if(ctrlType == CTRL_Type_PID_Id)
483  {
484  Kd = obj->Kd_Id;
485  }
486  else if(ctrlType == CTRL_Type_PID_Iq)
487  {
488  Kd = obj->Kd_Iq;
489  }
490 
491  return(Kd);
492 } // end of CTRL_getKd() function
493 
494 
499 inline _iq CTRL_getKp(CTRL_Handle handle,const CTRL_Type_e ctrlType)
500 {
501  CTRL_Obj *obj = (CTRL_Obj *)handle;
502  _iq Kp = _IQ(0.0);
503 
504  if(ctrlType == CTRL_Type_PID_spd)
505  {
506  Kp = obj->Kp_spd;
507  }
508  else if(ctrlType == CTRL_Type_PID_Id)
509  {
510  Kp = obj->Kp_Id;
511  }
512  else if(ctrlType == CTRL_Type_PID_Iq)
513  {
514  Kp = obj->Kp_Iq;
515  }
516 
517  return(Kp);
518 } // end of CTRL_getKp() function
519 
520 
525 {
526  CTRL_Obj *obj = (CTRL_Obj *)handle;
527 
528  return(obj->Lhf);
529 } // end of CTRL_getLhf() function
530 
531 
536 
537 
542 {
543  CTRL_Obj *obj = (CTRL_Obj *)handle;
544 
545  return(obj->maxVsMag_pu);
546 } // end of CTRL_getMaxVsMag_pu() function
547 
548 
553 
554 
559 {
560  CTRL_Obj *obj = (CTRL_Obj *)handle;
561 
562  return(obj->motorParams.ratedFlux_VpHz);
563 } // end of CTRL_getMotorRatedFlux() function
564 
565 
570 {
571  CTRL_Obj *obj = (CTRL_Obj *)handle;
572 
573  return(obj->motorParams.type);
574 } // end of CTRL_getMotorType() function
575 
576 
580 inline uint_least16_t CTRL_getNumCtrlTicksPerCurrentTick(CTRL_Handle handle)
581 {
582  CTRL_Obj *obj = (CTRL_Obj *)handle;
583 
584  return(obj->numCtrlTicksPerCurrentTick);
585 } // end of CTRL_getNumCtrlTicksPerCurrentTick() function
586 
587 
591 inline uint_least16_t CTRL_getNumCtrlTicksPerSpeedTick(CTRL_Handle handle)
592 {
593  CTRL_Obj *obj = (CTRL_Obj *)handle;
594 
595  return(obj->numCtrlTicksPerSpeedTick);
596 } // end of CTRL_getNumCtrlTicksPerSpeedTick() function
597 
598 
602 inline uint_least16_t CTRL_getNumCtrlTicksPerTrajTick(CTRL_Handle handle)
603 {
604  CTRL_Obj *obj = (CTRL_Obj *)handle;
605 
606  return(obj->numCtrlTicksPerTrajTick);
607 } // end of CTRL_getNumCtrlTicksPerTrajTick() function
608 
609 
613 inline uint_least16_t CTRL_getNumIsrTicksPerCtrlTick(CTRL_Handle handle)
614 {
615  CTRL_Obj *obj = (CTRL_Obj *)handle;
616 
617  return(obj->numIsrTicksPerCtrlTick);
618 } // end of CTRL_getNumIsrTicksPerCtrlTick() function
619 
620 
625 inline _iq CTRL_getRefValue_pu(CTRL_Handle handle,const CTRL_Type_e ctrlType)
626 {
627  CTRL_Obj *obj = (CTRL_Obj *)handle;
628  _iq ref = _IQ(0.0);
629 
630  if(ctrlType == CTRL_Type_PID_spd)
631  {
632  ref = PID_getRefValue(obj->pidHandle_spd);
633  }
634  else if(ctrlType == CTRL_Type_PID_Id)
635  {
636  ref = PID_getRefValue(obj->pidHandle_Id);
637  }
638  else if(ctrlType == CTRL_Type_PID_Iq)
639  {
640  ref = PID_getRefValue(obj->pidHandle_Iq);
641  }
642 
643  return(ref);
644 } // end of CTRL_getRefValue_pu() function
645 
646 
650 {
651  _iq refValue_pu = _IQ(0.0);
652 
653  if(CTRL_getFlag_enableSpeedCtrl(handle))
654  {
655  refValue_pu = CTRL_getId_ref_pu(handle) + CTRL_getId_offset_pu(handle);
656  }
657  else
658  {
659  refValue_pu = CTRL_getId_offset_pu(handle);
660  }
661 
662  return(refValue_pu);
663 } // end of CTRL_getRefValue_Id_pu() function
664 
665 
669 {
670  CTRL_Obj *obj = (CTRL_Obj *)handle;
671 
672  return(obj->speed_ref_pu);
673 } // end of CTRL_getRefValue_spd_pu() function
674 
675 
680 {
681  CTRL_Obj *obj = (CTRL_Obj *)handle;
682 
683  return(obj->Rhf);
684 } // end of CTRL_getRhf() function
685 
686 
691 {
692  CTRL_Obj *obj = (CTRL_Obj *)handle;
693 
694  return(obj->RoverL);
695 } // end of CTRL_getRoverL() function
696 
697 
702 {
703  CTRL_Obj *obj = (CTRL_Obj *)handle;
704 
705  return(obj->spd_max);
706 } // end of CTRL_getSpd_max_pu() function
707 
708 
713 {
714  CTRL_Obj *obj = (CTRL_Obj *)handle;
715 
716  return(&(obj->spd_out));
717 } // end of CTRL_getSpd_out_addr() function
718 
719 
724 {
725  CTRL_Obj *obj = (CTRL_Obj *)handle;
726 
727  return(obj->spd_out);
728 } // end of CTRL_getSpd_out_pu() function
729 
730 
735 {
736  CTRL_Obj *obj = (CTRL_Obj *)handle;
737 
738  return(obj->spd_ref);
739 } // end of CTRL_getSpd_ref_pu() function
740 
741 
746 {
747  CTRL_Obj *obj = (CTRL_Obj *)handle;
748 
749  return(TRAJ_getIntValue(obj->trajHandle_spd));
750 } // end of CTRL_getSpd_int_ref_pu() function
751 
752 
757 {
758  CTRL_Obj *obj = (CTRL_Obj *)handle;
759 
760  return(obj->speed_outMax_pu);
761 } // end of CTRL_getSpeed_outMax_pu() function
762 
763 
768 {
769  CTRL_Obj *obj = (CTRL_Obj *)handle;
770 
771  return(obj->state);
772 } // end of CTRL_getState() function
773 
774 
778 inline uint_least32_t CTRL_getTrajFreq(CTRL_Handle handle)
779 {
780  CTRL_Obj *obj = (CTRL_Obj *)handle;
781 
782  return(obj->trajFreq_Hz);
783 } // end of CTRL_getTrajFreq() function
784 
785 
790 {
791  CTRL_Obj *obj = (CTRL_Obj *)handle;
792 
793  return(obj->trajPeriod_sec);
794 } // end of CTRL_getTrajPeriod_sec() function
795 
796 
799 void CTRL_getTrajStep(CTRL_Handle handle);
800 
801 
806 inline _iq CTRL_getUi(CTRL_Handle handle,const CTRL_Type_e ctrlType)
807 {
808  CTRL_Obj *obj = (CTRL_Obj *)handle;
809  _iq Ui = _IQ(0.0);
810 
811  if(ctrlType == CTRL_Type_PID_spd)
812  {
813  Ui = obj->Ui_spd;
814  }
815  else if(ctrlType == CTRL_Type_PID_Id)
816  {
817  Ui = obj->Ui_Id;
818  }
819  else if(ctrlType == CTRL_Type_PID_Iq)
820  {
821  Ui = obj->Ui_Iq;
822  }
823 
824  return(Ui);
825 } // end of CTRL_getUi() function
826 
827 
832 {
833  CTRL_Obj *obj = (CTRL_Obj *)handle;
834 
835  return(&(obj->Vab_in));
836 } // end of CTRL_getVab_in_addr() function
837 
838 
842 void CTRL_getVab_in_pu(CTRL_Handle handle,MATH_vec2 *pVab_in_pu);
843 
844 
849 {
850  CTRL_Obj *obj = (CTRL_Obj *)handle;
851 
852  return(&(obj->Vab_out));
853 } // end of CTRL_getVab_out_addr() function
854 
855 
859 void CTRL_getVab_out_pu(CTRL_Handle handle,MATH_vec2 *pVab_out_pu);
860 
861 
866 {
867  CTRL_Obj *obj = (CTRL_Obj *)handle;
868 
869  return(&(obj->Vdq_out.value[0]));
870 } // end of CTRL_getVd_out_addr() function
871 
872 
877 {
878  CTRL_Obj *obj = (CTRL_Obj *)handle;
879 
880  return(obj->Vdq_out.value[0]);
881 } // end of CTRL_getVd_out_pu() function
882 
883 
888 {
889  CTRL_Obj *obj = (CTRL_Obj *)handle;
890 
891  return(&(obj->Vdq_out));
892 } // end of CTRL_getVdq_out_pu() function
893 
894 
898 void CTRL_getVdq_out_pu(CTRL_Handle handle,MATH_vec2 *pVdq_out_pu);
899 
900 
904 void CTRL_getVersion(CTRL_Handle handle,CTRL_Version *pVersion);
905 
906 
911 {
912  CTRL_Obj *obj = (CTRL_Obj *)handle;
913 
914  return(&(obj->Vdq_out.value[1]));
915 } // end of CTRL_getVq_out_addr() function
916 
917 
922 {
923  CTRL_Obj *obj = (CTRL_Obj *)handle;
924 
925  return(obj->Vdq_out.value[1]);
926 } // end of CTRL_getVq_out_pu() function
927 
928 
933 inline uint_least32_t CTRL_getWaitTime(CTRL_Handle handle,const CTRL_State_e ctrlState)
934 {
935  CTRL_Obj *obj = (CTRL_Obj *)handle;
936 
937  return(obj->waitTimes[ctrlState]);
938 } // end of CTRL_getWaitTime() function
939 
940 
944 void CTRL_getWaitTimes(CTRL_Handle handle,uint_least32_t *pWaitTimes);
945 
946 
950 {
951  CTRL_Obj *obj = (CTRL_Obj *)handle;
952 
953  uint_least16_t count = obj->counter_current;
954 
955  // increment the count
956  count++;
957 
958  // save the count value
959  obj->counter_current = count;
960 
961  return;
962 } // end of CTRL_incrCounter_current() function
963 
964 
968 {
969  CTRL_Obj *obj = (CTRL_Obj *)handle;
970 
971  uint_least16_t count = obj->counter_isr;
972 
973  // increment the count
974  count++;
975 
976  // save the count value
977  obj->counter_isr = count;
978 
979  return;
980 } // end of CTRL_incrCounter_isr() function
981 
982 
986 {
987  CTRL_Obj *obj = (CTRL_Obj *)handle;
988 
989  uint_least16_t count = obj->counter_speed;
990 
991  // increment the count
992  count++;
993 
994  // save the count value
995  obj->counter_speed = count;
996 
997  return;
998 } // end of CTRL_incrCounter_speed() function
999 
1000 
1004 {
1005  CTRL_Obj *obj = (CTRL_Obj *)handle;
1006 
1007  uint_least32_t count = obj->counter_state;
1008 
1009  // increment the count
1010  count++;
1011 
1012  // save the count value
1013  obj->counter_state = count;
1014 
1015  return;
1016 } // end of CTRL_incrCounter_state() function
1017 
1018 
1022 {
1023  CTRL_Obj *obj = (CTRL_Obj *)handle;
1024 
1025  uint_least16_t count = obj->counter_traj;
1026 
1027  // increment the count
1028  count++;
1029 
1030  // save the count value
1031  obj->counter_traj = count;
1032 
1033  return;
1034 } // end of CTRL_incrCounter_traj() function
1035 
1036 
1043 #ifdef FAST_ROM_V1p6
1044 CTRL_Handle CTRL_initCtrl(const uint_least8_t ctrlNumber, const uint_least8_t estNumber);
1045 #else
1046 CTRL_Handle CTRL_initCtrl(const uint_least8_t estNumber,void *pMemory,const size_t numBytes);
1047 #endif
1048 
1049 
1053 inline bool CTRL_isError(CTRL_Handle handle)
1054 {
1055  CTRL_State_e ctrlState = CTRL_getState(handle);
1056  bool state = false;
1057 
1058 
1059  // check for controller errors
1060  if(ctrlState == CTRL_State_Error)
1061  {
1062  state = true;
1063  }
1064 
1065  return(state);
1066 } // end of CTRL_isError() function
1067 
1068 
1072 {
1073  CTRL_Obj *obj = (CTRL_Obj *)handle;
1074 
1075  obj->counter_current = 0;
1076 
1077  return;
1078 } // end of CTRL_resetCounter_current() function
1079 
1080 
1084 {
1085  CTRL_Obj *obj = (CTRL_Obj *)handle;
1086 
1087  obj->counter_isr = 1;
1088 
1089  return;
1090 } // end of CTRL_resetCounter_isr() function
1091 
1092 
1096 {
1097  CTRL_Obj *obj = (CTRL_Obj *)handle;
1098 
1099  obj->counter_speed = 0;
1100 
1101  return;
1102 } // end of CTRL_resetCounter_speed() function
1103 
1104 
1108 {
1109  CTRL_Obj *obj = (CTRL_Obj *)handle;
1110 
1111  obj->counter_state = 0;
1112 
1113  return;
1114 } // end of CTRL_resetCounter_state() function
1115 
1116 
1120 {
1121  CTRL_Obj *obj = (CTRL_Obj *)handle;
1122 
1123  obj->counter_traj = 0;
1124 
1125  return;
1126 } // end of CTRL_resetCounter_traj() function
1127 
1128 
1137 void CTRL_run(CTRL_Handle handle,HAL_Handle halHandle,
1138  const HAL_AdcData_t *pAdcData,
1139  HAL_PwmData_t *pPwmData);
1140 
1141 
1144 void CTRL_runTraj(CTRL_Handle handle);
1145 
1146 
1150 static inline void CTRL_setAngle_pu(CTRL_Handle handle,const _iq angle_pu)
1151 {
1152  CTRL_Obj *obj = (CTRL_Obj *)handle;
1153 
1154  obj->angle_pu = angle_pu;
1155 
1156  return;
1157 } // end of CTRL_setAngle_pu() function
1158 
1159 
1163 inline void CTRL_setCtrlFreq_Hz(CTRL_Handle handle,const uint_least32_t ctrlFreq_Hz)
1164 {
1165  CTRL_Obj *obj = (CTRL_Obj *)handle;
1166 
1167  obj->ctrlFreq_Hz = ctrlFreq_Hz;
1168 
1169  return;
1170 } // end of CTRL_setCtrlFreq_Hz() function
1171 
1172 
1176 inline void CTRL_setCtrlPeriod_sec(CTRL_Handle handle,const float_t ctrlPeriod_sec)
1177 {
1178  CTRL_Obj *obj = (CTRL_Obj *)handle;
1179 
1180  obj->ctrlPeriod_sec = ctrlPeriod_sec;
1181 
1182  return;
1183 } // end of CTRL_setCtrlPeriod_sec() function
1184 
1185 
1189 inline void CTRL_setErrorCode(CTRL_Handle handle,const CTRL_ErrorCode_e errorCode)
1190 {
1191  CTRL_Obj *obj = (CTRL_Obj *)handle;
1192 
1193  obj->errorCode = errorCode;
1194 
1195  return;
1196 } // end of CTRL_setErrorCode() function
1197 
1198 
1204 void CTRL_setEstParams(EST_Handle estHandle,USER_Params *pUserParams);
1205 
1206 
1214 inline void CTRL_setFlag_enableCtrl(CTRL_Handle handle,const bool state)
1215 {
1216  CTRL_Obj *obj = (CTRL_Obj *)handle;
1217 
1218  obj->flag_enableCtrl = state;
1219 
1220  return;
1221 } // end of CTRL_setFlag_enableCtrl() function
1222 
1223 
1227 static inline void CTRL_setFlag_enableCurrentCtrl(CTRL_Handle handle,const bool state)
1228 {
1229  CTRL_Obj *obj = (CTRL_Obj *)handle;
1230 
1231  obj->flag_enableCurrentCtrl = state;
1232 
1233  return;
1234 } // end of CTRL_setFlag_enableCurrentCtrl() function
1235 
1236 
1242 inline void CTRL_setFlag_enableDcBusComp(CTRL_Handle handle,const bool state)
1243 {
1244  CTRL_Obj *obj = (CTRL_Obj *)handle;
1245 
1246  obj->flag_enableDcBusComp = state;
1247 
1248  return;
1249 } // end of CTRL_setFlag_enableDcBusComp() function
1250 
1251 
1258 inline void CTRL_setFlag_enablePowerWarp(CTRL_Handle handle,const bool state)
1259 {
1260  CTRL_Obj *obj = (CTRL_Obj *)handle;
1261 
1262  obj->flag_enablePowerWarp = state;
1263 
1264  return;
1265 } // end of CTRL_setFlag_enablePowerWarp() function
1266 
1267 
1271 inline void CTRL_setFlag_enableOffset(CTRL_Handle handle,const bool state)
1272 {
1273  CTRL_Obj *obj = (CTRL_Obj *)handle;
1274 
1275  obj->flag_enableOffset = state;
1276 
1277  return;
1278 } // end of CTRL_setFlag_enableOffset() function
1279 
1280 
1284 inline void CTRL_setFlag_enableSpeedCtrl(CTRL_Handle handle,const bool state)
1285 {
1286  CTRL_Obj *obj = (CTRL_Obj *)handle;
1287 
1288  obj->flag_enableSpeedCtrl = state;
1289 
1290  return;
1291 } // end of CTRL_setFlag_enableSpeedCtrl() function
1292 
1293 
1300 inline void CTRL_setFlag_enableUserMotorParams(CTRL_Handle handle,const bool state)
1301 {
1302  CTRL_Obj *obj = (CTRL_Obj *)handle;
1303 
1304  obj->flag_enableUserMotorParams = state;
1305 
1306  return;
1307 } // end of CTRL_setFlag_enableUserMotorParams() function
1308 
1309 
1316 void CTRL_setGains(CTRL_Handle handle,const CTRL_Type_e ctrlType,
1317  const _iq Kp,const _iq Ki,const _iq Kd);
1318 
1319 
1323 inline void CTRL_setIab_in_pu(CTRL_Handle handle,const MATH_vec2 *pIab_in_pu)
1324 {
1325  CTRL_Obj *obj = (CTRL_Obj *)handle;
1326 
1327  obj->Iab_in.value[0] = pIab_in_pu->value[0];
1328  obj->Iab_in.value[1] = pIab_in_pu->value[1];
1329 
1330  return;
1331 } // end of CTRL_setIab_in_pu() function
1332 
1333 
1337 void CTRL_setIab_filt_pu(CTRL_Handle handle,const MATH_vec2 *pIab_filt_pu);
1338 
1339 
1343 inline void CTRL_setId_ref_pu(CTRL_Handle handle,const _iq Id_ref_pu)
1344 {
1345  CTRL_Obj *obj = (CTRL_Obj *)handle;
1346 
1347  obj->Idq_ref.value[0] = Id_ref_pu;
1348 
1349  return;
1350 } // end of CTRL_setId_ref_pu() function
1351 
1352 
1356 inline void CTRL_setIdq_in_pu(CTRL_Handle handle,const MATH_vec2 *pIdq_in_pu)
1357 {
1358  CTRL_Obj *obj = (CTRL_Obj *)handle;
1359 
1360  obj->Idq_in.value[0] = pIdq_in_pu->value[0];
1361  obj->Idq_in.value[1] = pIdq_in_pu->value[1];
1362 
1363  return;
1364 } // end of CTRL_setIdq_in_pu() function
1365 
1366 
1370 static inline void CTRL_setIdq_offset_pu(CTRL_Handle handle,const MATH_vec2 *pIdq_offset_pu)
1371 {
1372  CTRL_Obj *obj = (CTRL_Obj *)handle;
1373 
1374  obj->Idq_offset_pu.value[0] = pIdq_offset_pu->value[0];
1375  obj->Idq_offset_pu.value[1] = pIdq_offset_pu->value[1];
1376 
1377  return;
1378 } // end of CTRL_setIdq_offset_pu() function
1379 
1380 
1384 inline void CTRL_setIdq_ref_pu(CTRL_Handle handle,const MATH_vec2 *pIdq_ref_pu)
1385 {
1386  CTRL_Obj *obj = (CTRL_Obj *)handle;
1387 
1388  obj->Idq_ref.value[0] = pIdq_ref_pu->value[0];
1389  obj->Idq_ref.value[1] = pIdq_ref_pu->value[1];
1390 
1391  return;
1392 } // end of CTRL_setIdq_ref_pu() function
1393 
1394 
1398 inline void CTRL_setIdRated_pu(CTRL_Handle handle,const _iq IdRated_pu)
1399 {
1400  CTRL_Obj *obj = (CTRL_Obj *)handle;
1401 
1402  obj->IdRated = IdRated_pu;
1403 
1404  return;
1405 } // end of CTRL_setIdRated_pu() function
1406 
1407 
1411 static inline void CTRL_setImmediateUi(CTRL_Handle handle,const CTRL_Type_e ctrlType,const _iq Ui)
1412 {
1413  CTRL_Obj *obj = (CTRL_Obj *)handle;
1414 
1415  if(ctrlType == CTRL_Type_PID_spd)
1416  {
1417  PID_setUi(obj->pidHandle_spd,Ui);
1418  }
1419  else if(ctrlType == CTRL_Type_PID_Id)
1420  {
1421  PID_setUi(obj->pidHandle_Id,Ui);
1422  }
1423  else if(ctrlType == CTRL_Type_PID_Iq)
1424  {
1425  PID_setUi(obj->pidHandle_Iq,Ui);
1426  }
1427 
1428  return;
1429 } // end of CTRL_setUi() function
1430 
1431 
1435 inline void CTRL_setIq_ref_pu(CTRL_Handle handle,const _iq IqRef_pu)
1436 {
1437  CTRL_Obj *obj = (CTRL_Obj *)handle;
1438 
1439  obj->Idq_ref.value[1] = IqRef_pu;
1440 
1441  return;
1442 } // end of CTRL_setIq_ref_pu() function
1443 
1444 
1449 inline void CTRL_setKd(CTRL_Handle handle,const CTRL_Type_e ctrlType,const _iq Kd)
1450 {
1451  CTRL_Obj *obj = (CTRL_Obj *)handle;
1452 
1453  if(ctrlType == CTRL_Type_PID_spd)
1454  {
1455  obj->Kd_spd = Kd;
1456  }
1457  else if(ctrlType == CTRL_Type_PID_Id)
1458  {
1459  obj->Kd_Id = Kd;
1460  }
1461  else if(ctrlType == CTRL_Type_PID_Iq)
1462  {
1463  obj->Kd_Iq = Kd;
1464  }
1465 
1466  return;
1467 } // end of CTRL_setKd() function
1468 
1469 
1474 inline void CTRL_setKi(CTRL_Handle handle,const CTRL_Type_e ctrlType,const _iq Ki)
1475 {
1476  CTRL_Obj *obj = (CTRL_Obj *)handle;
1477 
1478  if(ctrlType == CTRL_Type_PID_spd)
1479  {
1480  obj->Ki_spd = Ki;
1481  }
1482  else if(ctrlType == CTRL_Type_PID_Id)
1483  {
1484  obj->Ki_Id = Ki;
1485  }
1486  else if(ctrlType == CTRL_Type_PID_Iq)
1487  {
1488  obj->Ki_Iq = Ki;
1489  }
1490 
1491  return;
1492 } // end of CTRL_setKi() function
1493 
1494 
1499 inline void CTRL_setKp(CTRL_Handle handle,const CTRL_Type_e ctrlType,const _iq Kp)
1500 {
1501  CTRL_Obj *obj = (CTRL_Obj *)handle;
1502 
1503  if(ctrlType == CTRL_Type_PID_spd)
1504  {
1505  obj->Kp_spd = Kp;
1506  }
1507  else if(ctrlType == CTRL_Type_PID_Id)
1508  {
1509  obj->Kp_Id = Kp;
1510  }
1511  else if(ctrlType == CTRL_Type_PID_Iq)
1512  {
1513  obj->Kp_Iq = Kp;
1514  }
1515 
1516  return;
1517 } // end of CTRL_setKp() function
1518 
1519 
1523 inline void CTRL_setLhf(CTRL_Handle handle,const float_t Lhf)
1524 {
1525  CTRL_Obj *obj = (CTRL_Obj *)handle;
1526 
1527  obj->Lhf = Lhf;
1528 
1529  return;
1530 } // end of CTRL_setLhf() function
1531 
1532 
1536 void CTRL_setMagCurrent_pu(CTRL_Handle handle,const _iq magCurrent_pu);
1537 
1538 
1542 inline void CTRL_setMaxVsMag_pu(CTRL_Handle handle,const _iq maxVsMag)
1543 {
1544  CTRL_Obj *obj = (CTRL_Obj *)handle;
1545 
1546  obj->maxVsMag_pu = maxVsMag;
1547 
1548  return;
1549 } // end of CTRL_setmaxVsMag_pu() function
1550 
1551 
1556 inline void CTRL_setMaxAccel_pu(CTRL_Handle handle,const _iq maxAccel_pu)
1557 {
1558  CTRL_Obj *obj = (CTRL_Obj *)handle;
1559 
1560  obj->traj_spd.maxDelta = maxAccel_pu;
1561 
1562  return;
1563 } // end of CTRL_setMaxAccel_pu() function
1564 
1565 
1569 void CTRL_setMaximumSpeed_pu(CTRL_Handle handle,const _iq maxSpeed_pu);
1570 
1571 
1582  const MOTOR_Type_e motorType,
1583  const uint_least16_t numPolePairs,
1584  const float_t ratedFlux,
1585  const float_t Ls_d,
1586  const float_t Ls_q,
1587  const float_t Rr,
1588  const float_t Rs)
1589 {
1590  CTRL_Obj *obj = (CTRL_Obj *)handle;
1591 
1592  obj->motorParams.type = motorType;
1593  obj->motorParams.numPolePairs = numPolePairs;
1594  obj->motorParams.ratedFlux_VpHz = ratedFlux;
1595  obj->motorParams.Ls_d_H = Ls_d;
1596  obj->motorParams.Ls_q_H = Ls_q;
1597  obj->motorParams.Rr_Ohm = Rr;
1598  obj->motorParams.Rs_Ohm = Rs;
1599 
1600  return;
1601 } // end of CTRL_setMotorParams() function
1602 
1603 
1609 void CTRL_setParams(CTRL_Handle handle,USER_Params *pUserParams);
1610 
1611 
1616  const uint_least16_t numCtrlTicksPerCurrentTick)
1617 {
1618  CTRL_Obj *obj = (CTRL_Obj *)handle;
1619 
1620  obj->numCtrlTicksPerCurrentTick = numCtrlTicksPerCurrentTick;
1621 
1622  return;
1623 } // end of CTRL_setNumCtrlTicksPerCurrentTick() function
1624 
1625 
1630  const uint_least16_t numCtrlTicksPerSpeedTick)
1631 {
1632  CTRL_Obj *obj = (CTRL_Obj *)handle;
1633 
1634  obj->numCtrlTicksPerSpeedTick = numCtrlTicksPerSpeedTick;
1635 
1636  return;
1637 } // end of CTRL_setNumCtrlTicksPerSpeedTick() function
1638 
1639 
1644  const uint_least16_t numCtrlTicksPerTrajTick)
1645 {
1646  CTRL_Obj *obj = (CTRL_Obj *)handle;
1647 
1648  obj->numCtrlTicksPerTrajTick = numCtrlTicksPerTrajTick;
1649 
1650  return;
1651 } // end of CTRL_setNumCtrlTicksPerTrajTick() function
1652 
1653 
1658  const uint_least16_t numIsrTicksPerCtrlTick)
1659 {
1660  CTRL_Obj *obj = (CTRL_Obj *)handle;
1661 
1662  obj->numIsrTicksPerCtrlTick = numIsrTicksPerCtrlTick;
1663 
1664  return;
1665 } // end of CTRL_setNumIsrTicksPerCtrlTick() function
1666 
1667 
1671 inline void CTRL_setRhf(CTRL_Handle handle,const float_t Rhf)
1672 {
1673  CTRL_Obj *obj = (CTRL_Obj *)handle;
1674 
1675  obj->Rhf = Rhf;
1676 
1677  return;
1678 } // end of CTRL_setRhf() function
1679 
1680 
1684 inline void CTRL_setRoverL(CTRL_Handle handle,const float_t RoverL)
1685 {
1686  CTRL_Obj *obj = (CTRL_Obj *)handle;
1687 
1688  obj->RoverL = RoverL;
1689 
1690  return;
1691 } // end of CTRL_setRoverL() function
1692 
1693 
1697 static inline void CTRL_setSpeed_fb_pu(CTRL_Handle handle,const _iq speed_fb_pu)
1698 {
1699  CTRL_Obj *obj = (CTRL_Obj *)handle;
1700 
1701  obj->speed_fb_pu = speed_fb_pu;
1702 
1703  return;
1704 } // end of CTRL_setSpeed_fb_pu() function
1705 
1706 
1710 inline void CTRL_setSpd_max_pu(CTRL_Handle handle,const _iq maxSpd_pu)
1711 {
1712  CTRL_Obj *obj = (CTRL_Obj *)handle;
1713 
1714  obj->spd_max = maxSpd_pu;
1715 
1716  return;
1717 } // end of CTRL_setSpd_max_pu() function
1718 
1719 
1723 inline void CTRL_setSpd_out_pu(CTRL_Handle handle,const _iq spd_out_pu)
1724 {
1725  CTRL_Obj *obj = (CTRL_Obj *)handle;
1726 
1727  obj->spd_out = spd_out_pu;
1728 
1729  return;
1730 } // end of CTRL_setSpd_out_pu() function
1731 
1732 
1736 static inline void CTRL_setSpeed_outMax_pu(CTRL_Handle handle,const _iq speed_outMax_pu)
1737 {
1738  CTRL_Obj *obj = (CTRL_Obj *)handle;
1739 
1740  obj->speed_outMax_pu = speed_outMax_pu;
1741 
1742  return;
1743 } // end of CTRL_setSpeed_outMax_pu() function
1744 
1745 
1749 static inline void CTRL_setSpeed_ref_pu(CTRL_Handle handle,const _iq speed_ref_pu)
1750 {
1751  CTRL_Obj *obj = (CTRL_Obj *)handle;
1752 
1753  obj->speed_ref_pu = speed_ref_pu;
1754 
1755  return;
1756 } // end of CTRL_setSpeed_ref_pu() function
1757 
1758 
1762 void CTRL_setSpd_ref_pu(CTRL_Handle handle,const _iq spd_ref_pu);
1763 
1764 
1768 void CTRL_setSpd_ref_krpm(CTRL_Handle handle,const _iq spd_ref_krpm);
1769 
1770 
1774 inline void CTRL_setState(CTRL_Handle handle,const CTRL_State_e state)
1775 {
1776  CTRL_Obj *obj = (CTRL_Obj *)handle;
1777 
1778  obj->prevState = obj->state;
1779  obj->state = state;
1780 
1781  return;
1782 } // end of CTRL_setState() function
1783 
1784 
1788 inline void CTRL_setTrajFreq_Hz(CTRL_Handle handle,const uint_least32_t trajFreq_Hz)
1789 {
1790  CTRL_Obj *obj = (CTRL_Obj *)handle;
1791 
1792  obj->trajFreq_Hz = trajFreq_Hz;
1793 
1794  return;
1795 } // end of CTRL_setTrajFreq_Hz() function
1796 
1797 
1801 inline void CTRL_setTrajPeriod_sec(CTRL_Handle handle,const _iq trajPeriod_sec)
1802 {
1803  CTRL_Obj *obj = (CTRL_Obj *)handle;
1804 
1805  obj->trajPeriod_sec = trajPeriod_sec;
1806 
1807  return;
1808 } // end of CTRL_setTrajPeriod_sec() function
1809 
1810 
1815 inline void CTRL_setUi(CTRL_Handle handle,const CTRL_Type_e ctrlType,const _iq Ui)
1816 {
1817  CTRL_Obj *obj = (CTRL_Obj *)handle;
1818 
1819  if(ctrlType == CTRL_Type_PID_spd)
1820  {
1821  obj->Ui_spd = Ui;
1822  }
1823  else if(ctrlType == CTRL_Type_PID_Id)
1824  {
1825  obj->Ui_Id = Ui;
1826  }
1827  else if(ctrlType == CTRL_Type_PID_Iq)
1828  {
1829  obj->Ui_Iq = Ui;
1830  }
1831 
1832  return;
1833 } // end of CTRL_setUi() function
1834 
1835 
1841 void CTRL_setupClarke_I(CTRL_Handle handle,uint_least8_t numCurrentSensors);
1842 
1843 
1849 void CTRL_setupClarke_V(CTRL_Handle handle,uint_least8_t numVoltageSensors);
1850 
1851 
1854 void CTRL_setupEstIdleState(CTRL_Handle handle);
1855 
1856 
1860 
1861 
1863 void CTRL_setup_user(CTRL_Handle handle,
1864  const _iq angle_pu,
1865  const _iq speed_ref_pu,
1866  const _iq speed_fb_pu,
1867  const _iq speed_outMax_pu,
1868  const MATH_vec2 *pIdq_offset_pu,
1869  const MATH_vec2 *pVdq_offset_pu,
1870  const bool flag_enableSpeedCtrl,
1871  const bool flag_enableCurrentCtrl);
1872 
1873 
1877 
1878 
1882 inline void CTRL_setVab_in_pu(CTRL_Handle handle,const MATH_vec2 *pVab_in_pu)
1883 {
1884  CTRL_Obj *obj = (CTRL_Obj *)handle;
1885 
1886  obj->Vab_in.value[0] = pVab_in_pu->value[0];
1887  obj->Vab_in.value[1] = pVab_in_pu->value[1];
1888 
1889  return;
1890 } // end of CTRL_setVab_in_pu() function
1891 
1892 
1896 inline void CTRL_setVab_out_pu(CTRL_Handle handle,const MATH_vec2 *pVab_out_pu)
1897 {
1898  CTRL_Obj *obj = (CTRL_Obj *)handle;
1899 
1900  obj->Vab_out.value[0] = pVab_out_pu->value[0];
1901  obj->Vab_out.value[1] = pVab_out_pu->value[1];
1902 
1903  return;
1904 } // end of CTRL_setVab_out_pu() function
1905 
1906 
1910 static inline void CTRL_setVdq_offset_pu(CTRL_Handle handle,const MATH_vec2 *pVdq_offset_pu)
1911 {
1912  CTRL_Obj *obj = (CTRL_Obj *)handle;
1913 
1914  obj->Vdq_offset_pu.value[0] = pVdq_offset_pu->value[0];
1915  obj->Vdq_offset_pu.value[1] = pVdq_offset_pu->value[1];
1916 
1917  return;
1918 } // end of CTRL_setVdq_offset_pu() function
1919 
1920 
1924 inline void CTRL_setVdq_out_pu(CTRL_Handle handle,const MATH_vec2 *pVdq_out_pu)
1925 {
1926  CTRL_Obj *obj = (CTRL_Obj *)handle;
1927 
1928  obj->Vdq_out.value[0] = pVdq_out_pu->value[0];
1929  obj->Vdq_out.value[1] = pVdq_out_pu->value[1];
1930 
1931  return;
1932 } // end of CTRL_setVdq_out_pu() function
1933 
1934 
1938 void CTRL_setWaitTimes(CTRL_Handle handle,const uint_least32_t *pWaitTimes);
1939 
1940 
1945 void CTRL_setup(CTRL_Handle handle);
1946 
1947 
1950 void CTRL_setupCtrl(CTRL_Handle handle);
1951 
1952 
1955 void CTRL_setupEst(CTRL_Handle handle);
1956 
1957 
1960 void CTRL_setupTraj(CTRL_Handle handle);
1961 
1962 
1966 bool CTRL_updateState(CTRL_Handle handle);
1967 
1968 
1972 inline bool CTRL_useZeroIq_ref(CTRL_Handle handle)
1973 {
1974  CTRL_Obj *obj = (CTRL_Obj *)handle;
1975 
1976  return(EST_useZeroIq_ref(obj->estHandle));
1977 } // end of CTRL_useZeroIq_ref() function
1978 
1979 
1983 {
1984  CTRL_Obj *obj = (CTRL_Obj *)handle;
1985 
1986  // check for estimator errors
1987  if(EST_isError(obj->estHandle))
1988  {
1989  // set the next controller state
1991 
1992  // set the error code
1994  }
1995 
1996  return;
1997 } // end of CTRL_checkForErrors() function
1998 
1999 
2005 static inline void CTRL_computeOutputLimits_Id(CTRL_Handle handle,
2006  const _iq maxVsMag,
2007  _iq *outMin,_iq *outMax)
2008 {
2009 
2010  *outMin = -maxVsMag;
2011  *outMax = maxVsMag;
2012 
2013  return;
2014 } // end of CTRL_computeOutputLimits_Id() function
2015 
2016 
2023 static inline void CTRL_computeOutputLimits_Iq(CTRL_Handle handle,
2024  const _iq maxVsMag,
2025  const _iq Vd_out_pu,
2026  _iq *outMin,_iq *outMax)
2027 {
2028  _iq tmp = _IQsqrt(_IQmpy(maxVsMag,maxVsMag) - _IQmpy(Vd_out_pu,Vd_out_pu));
2029 
2030  *outMin = -tmp;
2031  *outMax = tmp;
2032 
2033  return;
2034 } // end of CTRL_computeOutputLimits_Iq() function
2035 
2036 
2040 inline void CTRL_computePhasor(const _iq angle_pu,MATH_vec2 *pPhasor)
2041 {
2042 
2043  pPhasor->value[0] = _IQcosPU(angle_pu);
2044  pPhasor->value[1] = _IQsinPU(angle_pu);
2045 
2046  return;
2047 } // end of CTRL_computePhasor() function
2048 
2049 
2053 inline bool CTRL_doCurrentCtrl(CTRL_Handle handle)
2054 {
2055  CTRL_Obj *obj = (CTRL_Obj *)handle;
2056  bool result = false;
2057 
2059  {
2060  result = true;
2061  }
2062 
2063  return(result);
2064 } // end of CTRL_doCurrentCtrl() function
2065 
2066 
2070 inline bool CTRL_doSpeedCtrl(CTRL_Handle handle)
2071 {
2072  CTRL_Obj *obj = (CTRL_Obj *)handle;
2073  bool result = false;
2074 
2075  if((obj->counter_speed >= obj->numCtrlTicksPerSpeedTick))
2076  {
2077  result = true;
2078  }
2079 
2080  return(result);
2081 } // end of CTRL_doSpeedCtrl() function
2082 
2083 
2089 inline void CTRL_runOffLine(CTRL_Handle handle,HAL_Handle halHandle,
2090  const HAL_AdcData_t *pAdcData,HAL_PwmData_t *pPwmData)
2091 {
2092 
2093  // run offset estimation
2094  HAL_runOffsetEst(halHandle,pAdcData);
2095 
2096  // create PWM data
2097  pPwmData->Tabc.value[0] = _IQ(0.0);
2098  pPwmData->Tabc.value[1] = _IQ(0.0);
2099  pPwmData->Tabc.value[2] = _IQ(0.0);
2100 
2101  return;
2102 } // end of CTRL_runOffLine() function
2103 
2104 
2108 inline void CTRL_setSpdMax(CTRL_Handle handle, const _iq spdMax)
2109 {
2110  CTRL_Obj *obj = (CTRL_Obj *)handle;
2111 
2112  // set the maximum output of the speed controller, or Maximum Iq reference
2113  TRAJ_setIntValue(obj->trajHandle_spdMax, spdMax);
2114 
2115  return;
2116 } // end of CTRL_setSpdMax() function
2117 
2118 
2126 inline _iq CTRL_angleDelayComp(CTRL_Handle handle, const _iq angle_pu)
2127 {
2128  CTRL_Obj *obj = (CTRL_Obj *)handle;
2129  _iq angleDelta_pu = _IQmpy(EST_getFm_pu(obj->estHandle),_IQ(USER_IQ_FULL_SCALE_FREQ_Hz/(USER_PWM_FREQ_kHz*1000.0)));
2130  _iq angleUncomp_pu = angle_pu;
2131  _iq angleCompFactor = _IQ(1.0 + (float_t)USER_NUM_PWM_TICKS_PER_ISR_TICK * (float_t)USER_NUM_ISR_TICKS_PER_CTRL_TICK * ((float_t)USER_NUM_CTRL_TICKS_PER_EST_TICK - 0.5));
2132  _iq angleDeltaComp_pu = _IQmpy(angleDelta_pu, angleCompFactor);
2133  uint32_t angleMask = ((uint32_t)0xFFFFFFFF >> (32 - GLOBAL_Q));
2134  _iq angleTmp_pu;
2135  _iq angleComp_pu;
2136 
2137  // increment the angle
2138  angleTmp_pu = angleUncomp_pu + angleDeltaComp_pu;
2139 
2140  // mask the angle for wrap around
2141  // note: must account for the sign of the angle
2142  angleComp_pu = _IQabs(angleTmp_pu) & angleMask;
2143 
2144  // account for sign
2145  if(angleTmp_pu < 0)
2146  {
2147  angleComp_pu = -angleComp_pu;
2148  }
2149 
2150  return(angleComp_pu);
2151 }
2152 
2153 
2158 inline void CTRL_runOnLine(CTRL_Handle handle,
2159  const HAL_AdcData_t *pAdcData,HAL_PwmData_t *pPwmData)
2160 {
2161  CTRL_Obj *obj = (CTRL_Obj *)handle;
2162 
2163  _iq angle_pu;
2164 
2165  MATH_vec2 phasor;
2166 
2167 
2168  // run Clarke transform on current
2169  CLARKE_run(obj->clarkeHandle_I,&pAdcData->I,CTRL_getIab_in_addr(handle));
2170 
2171 
2172  // run Clarke transform on voltage
2173  CLARKE_run(obj->clarkeHandle_V,&pAdcData->V,CTRL_getVab_in_addr(handle));
2174 
2175 
2176  // run the estimator
2178  pAdcData->dcBus,TRAJ_getIntValue(obj->trajHandle_spd));
2179 
2180 
2181  // generate the motor electrical angle
2182  angle_pu = EST_getAngle_pu(obj->estHandle);
2183 
2184 
2185  // compute the sin/cos phasor
2186  CTRL_computePhasor(angle_pu,&phasor);
2187 
2188 
2189  // set the phasor in the Park transform
2190  PARK_setPhasor(obj->parkHandle,&phasor);
2191 
2192 
2193  // run the Park transform
2195 
2196 
2197  // when appropriate, run the PID speed controller
2198  if(EST_doSpeedCtrl(obj->estHandle))
2199  {
2200  if(CTRL_doSpeedCtrl(handle))
2201  {
2202  _iq refValue = TRAJ_getIntValue(obj->trajHandle_spd);
2203  _iq fbackValue = EST_getFm_pu(obj->estHandle);
2204  _iq outMax = TRAJ_getIntValue(obj->trajHandle_spdMax);
2205  _iq outMin = -outMax;
2206 
2207  // reset the speed count
2208  CTRL_resetCounter_speed(handle);
2209 
2210  PID_setMinMax(obj->pidHandle_spd,outMin,outMax);
2211 
2212  PID_run_spd(obj->pidHandle_spd,refValue,fbackValue,CTRL_getSpd_out_addr(handle));
2213  }
2214  }
2215  else
2216  {
2217  // zero the speed command
2218  CTRL_setSpd_out_pu(handle,_IQ(0.0));
2219 
2220  // reset the integrator
2221  PID_setUi(obj->pidHandle_spd,_IQ(0.0));
2222  }
2223 
2224 
2225  // when appropriate, run the PID Id and Iq controllers
2226  if(CTRL_doCurrentCtrl(handle) && EST_doCurrentCtrl(obj->estHandle))
2227  {
2228  _iq Kp_Id = CTRL_getKp(handle,CTRL_Type_PID_Id);
2229  _iq Kp_Iq = CTRL_getKp(handle,CTRL_Type_PID_Iq);
2230  _iq refValue;
2231  _iq fbackValue;
2232  _iq outMin,outMax;
2233 
2234  _iq maxVsMag = CTRL_getMaxVsMag_pu(handle);
2235 
2236  // reset the current count
2237  CTRL_resetCounter_current(handle);
2238 
2239  // ***********************************
2240  // configure and run the Id controller
2241 
2242  // compute the Kp gain
2243  // Scale Kp instead of output to prevent saturation issues
2244  if(CTRL_getFlag_enableDcBusComp(handle))
2245  {
2246  Kp_Id = _IQmpy(Kp_Id,EST_getOneOverDcBus_pu(obj->estHandle));
2247  }
2248 
2249  PID_setKp(obj->pidHandle_Id,Kp_Id);
2250 
2251  // compute the reference value
2252  refValue = TRAJ_getIntValue(obj->trajHandle_Id) + CTRL_getId_ref_pu(handle);
2253 
2254  // update the Id reference value
2255  EST_updateId_ref_pu(obj->estHandle,&refValue);
2256 
2257  // get the feedback value
2258  fbackValue = CTRL_getId_in_pu(handle);
2259 
2260  // set minimum and maximum for Id controller output
2261  outMax = maxVsMag;
2262  outMin = -outMax;
2263 
2264  // set the minimum and maximum values
2265  PID_setMinMax(obj->pidHandle_Id,outMin,outMax);
2266 
2267  // run the Id PID controller
2268  PID_run(obj->pidHandle_Id,refValue,fbackValue,CTRL_getVd_out_addr(handle));
2269 
2270  // set the Id reference value in the estimator
2271  EST_setId_ref_pu(obj->estHandle,refValue);
2272 
2273  // ***********************************
2274  // configure and run the Iq controller
2275 
2276  // compute the Kp gain
2277  // Scale Kp instead of output to prevent saturation issues
2278  if(CTRL_getFlag_enableDcBusComp(handle))
2279  {
2280  Kp_Iq = _IQmpy(Kp_Iq,EST_getOneOverDcBus_pu(obj->estHandle));
2281  }
2282 
2283  PID_setKp(obj->pidHandle_Iq,Kp_Iq);
2284 
2285  // get the reference value
2286  if(CTRL_getFlag_enableSpeedCtrl(handle))
2287  {
2288  if(!CTRL_useZeroIq_ref(handle))
2289  {
2290  refValue = CTRL_getSpd_out_pu(handle);
2291  }
2292  else
2293  {
2294  refValue = _IQ(0.0);
2295  }
2296  }
2297  else
2298  {
2299  // get the Iq reference value
2300  refValue = CTRL_getIq_ref_pu(handle);
2301  }
2302 
2303  // get the feedback value
2304  fbackValue = CTRL_getIq_in_pu(handle);
2305 
2306  // generate the Iq PID output limits without square root
2307  outMax = maxVsMag - _IQabs(CTRL_getVd_out_pu(handle));
2308  outMin = -outMax;
2309 
2310  // set the minimum and maximum values
2311  PID_setMinMax(obj->pidHandle_Iq,outMin,outMax);
2312 
2313  // run the Iq PID controller
2314  PID_run(obj->pidHandle_Iq,refValue,fbackValue,CTRL_getVq_out_addr(handle));
2315 
2316  // set the Iq reference value in the estimator
2317  EST_setIq_ref_pu(obj->estHandle,refValue);
2318  }
2319 
2320 
2321  // set the phasor in the inverse Park transform
2322  IPARK_setPhasor(obj->iparkHandle,&phasor);
2323 
2324 
2325  // run the inverse Park module
2327 
2328 
2329  // run the space Vector Generator (SVGEN) module
2330  SVGEN_run(obj->svgenHandle,CTRL_getVab_out_addr(handle),&(pPwmData->Tabc));
2331 
2332  return;
2333 } // end of CTRL_runOnLine() function
2334 
2335 
2344  const HAL_AdcData_t *pAdcData,HAL_PwmData_t *pPwmData)
2345 {
2346  CTRL_Obj *obj = (CTRL_Obj *)handle;
2347 
2348  _iq angle_pu;
2349 
2350  MATH_vec2 phasor;
2351 
2352 
2353  // run Clarke transform on current
2354  CLARKE_run(obj->clarkeHandle_I,&pAdcData->I,CTRL_getIab_in_addr(handle));
2355 
2356 
2357  // run Clarke transform on voltage
2358  CLARKE_run(obj->clarkeHandle_V,&pAdcData->V,CTRL_getVab_in_addr(handle));
2359 
2360 
2361  // run the estimator
2363  pAdcData->dcBus,TRAJ_getIntValue(obj->trajHandle_spd));
2364 
2365 
2366  // generate the motor electrical angle
2367  angle_pu = EST_getAngle_pu(obj->estHandle);
2368 
2369 
2370  // compute the sin/cos phasor
2371  CTRL_computePhasor(angle_pu,&phasor);
2372 
2373 
2374  // set the phasor in the Park transform
2375  PARK_setPhasor(obj->parkHandle,&phasor);
2376 
2377 
2378  // run the Park transform
2380 
2381 
2382  // when appropriate, run the PID speed controller
2383  if(CTRL_doSpeedCtrl(handle))
2384  {
2385  _iq refValue = TRAJ_getIntValue(obj->trajHandle_spd);
2386  _iq fbackValue = EST_getFm_pu(obj->estHandle);
2387  _iq outMax = TRAJ_getIntValue(obj->trajHandle_spdMax);
2388  _iq outMin = -outMax;
2389 
2390  // reset the speed count
2391  CTRL_resetCounter_speed(handle);
2392 
2393  PID_setMinMax(obj->pidHandle_spd,outMin,outMax);
2394 
2395  PID_run_spd(obj->pidHandle_spd,refValue,fbackValue,CTRL_getSpd_out_addr(handle));
2396  }
2397 
2398 
2399  // when appropriate, run the PID Id and Iq controllers
2400  if(CTRL_doCurrentCtrl(handle))
2401  {
2402  _iq Kp_Id = CTRL_getKp(handle,CTRL_Type_PID_Id);
2403  _iq Kp_Iq = CTRL_getKp(handle,CTRL_Type_PID_Iq);
2404  _iq refValue;
2405  _iq fbackValue;
2406  _iq outMin,outMax;
2407 
2408  // read max voltage vector to set proper limits to current controllers
2409  _iq maxVsMag = CTRL_getMaxVsMag_pu(handle);
2410 
2411 
2412  // reset the current count
2413  CTRL_resetCounter_current(handle);
2414 
2415  // ***********************************
2416  // configure and run the Id controller
2417 
2418  // compute the Kp gain
2419  // Scale Kp instead of output to prevent saturation issues
2420  if(CTRL_getFlag_enableDcBusComp(handle))
2421  {
2422  Kp_Id = _IQmpy(Kp_Id,EST_getOneOverDcBus_pu(obj->estHandle));
2423  }
2424 
2425  PID_setKp(obj->pidHandle_Id,Kp_Id);
2426 
2427  // compute the reference value
2428  refValue = TRAJ_getIntValue(obj->trajHandle_Id) + CTRL_getId_ref_pu(handle);
2429 
2430  // update the Id reference value
2431  EST_updateId_ref_pu(obj->estHandle,&refValue);
2432 
2433  // get the feedback value
2434  fbackValue = CTRL_getId_in_pu(handle);
2435 
2436  // set minimum and maximum for Id controller output
2437  outMax = maxVsMag;
2438  outMin = -outMax;
2439 
2440  // set the minimum and maximum values
2441  PID_setMinMax(obj->pidHandle_Id,outMin,outMax);
2442 
2443  // run the Id PID controller
2444  PID_run(obj->pidHandle_Id,refValue,fbackValue,CTRL_getVd_out_addr(handle));
2445 
2446  // ***********************************
2447  // configure and run the Iq controller
2448 
2449  // compute the Kp gain
2450  // Scale Kp instead of output to prevent saturation issues
2451  if(CTRL_getFlag_enableDcBusComp(handle))
2452  {
2453  Kp_Iq = _IQmpy(Kp_Iq,EST_getOneOverDcBus_pu(obj->estHandle));
2454  }
2455 
2456  PID_setKp(obj->pidHandle_Iq,Kp_Iq);
2457 
2458  // get the reference value
2459  if(CTRL_getFlag_enableSpeedCtrl(handle))
2460  {
2461  refValue = CTRL_getSpd_out_pu(handle);
2462  }
2463  else
2464  {
2465  // get the Iq reference value
2466  refValue = CTRL_getIq_ref_pu(handle);
2467  }
2468 
2469  // get the feedback value
2470  fbackValue = CTRL_getIq_in_pu(handle);
2471 
2472  // set minimum and maximum for Id controller output
2473  outMax = _IQsqrt(_IQmpy(maxVsMag,maxVsMag) - _IQmpy(CTRL_getVd_out_pu(handle),CTRL_getVd_out_pu(handle)));
2474  outMin = -outMax;
2475 
2476  // set the minimum and maximum values
2477  PID_setMinMax(obj->pidHandle_Iq,outMin,outMax);
2478 
2479  // run the Iq PID controller
2480  PID_run(obj->pidHandle_Iq,refValue,fbackValue,CTRL_getVq_out_addr(handle));
2481  }
2482 
2483  {
2484  _iq angleComp_pu;
2485 
2486 
2487  // compensate angle delay
2488  angleComp_pu = CTRL_angleDelayComp(handle, angle_pu);
2489 
2490 
2491  // compute the sin/cos phasor
2492  CTRL_computePhasor(angleComp_pu,&phasor);
2493  }
2494 
2495 
2496  // set the phasor in the inverse Park transform
2497  IPARK_setPhasor(obj->iparkHandle,&phasor);
2498 
2499 
2500  // run the inverse Park module
2502 
2503 
2504  // run the space Vector Generator (SVGEN) module
2505  SVGEN_run(obj->svgenHandle,CTRL_getVab_out_addr(handle),&(pPwmData->Tabc));
2506 
2507  return;
2508 } // end of CTRL_runOnLine_User() function
2509 
2510 
2513 inline void CTRL_runPiOnly(CTRL_Handle handle) //,const HAL_AdcData_t *pAdcData,HAL_PwmData_t *pPwmData)
2514 {
2515  CTRL_Obj *obj = (CTRL_Obj *)handle;
2516 
2517 
2518  // when appropriate, run the PID speed controller
2519  if(CTRL_getFlag_enableSpeedCtrl(handle))
2520  {
2521  if(CTRL_doSpeedCtrl(handle))
2522  {
2523  _iq refValue = CTRL_getRefValue_spd_pu(handle);
2524  _iq fbackValue = CTRL_getFbackValue_spd_pu(handle);
2525  _iq outMax = CTRL_getSpeed_outMax_pu(handle);
2526  _iq outMin = -outMax;
2527 
2528  // reset the speed count
2529  CTRL_resetCounter_speed(handle);
2530 
2531  PID_setMinMax(obj->pidHandle_spd,outMin,outMax);
2532 
2533  PID_run_spd(obj->pidHandle_spd,refValue,fbackValue,CTRL_getIq_ref_pu_addr(handle));
2534  }
2535  }
2536  else
2537  {
2538  // zero the speed command
2539  CTRL_setIq_ref_pu(handle,_IQ(0.0));
2540 
2541  // reset the integrator
2542  PID_setUi(obj->pidHandle_spd,_IQ(0.0));
2543  }
2544 
2545 
2546  // when appropriate, run the PID Id and Iq controllers
2547  if(CTRL_doCurrentCtrl(handle))
2548  {
2549  _iq Kp_Id = CTRL_getKp(handle,CTRL_Type_PID_Id);
2550  _iq Kp_Iq = CTRL_getKp(handle,CTRL_Type_PID_Iq);
2551  _iq refValue;
2552  _iq fbackValue;
2553  _iq outMin,outMax;
2554 
2555  _iq maxVsMag = CTRL_getMaxVsMag_pu(handle);
2556 
2557  // reset the current count
2558  CTRL_resetCounter_current(handle);
2559 
2560  // ***********************************
2561  // configure and run the Id controller
2562 
2563  // compute the Kp gain
2564  // Scale Kp instead of output to prevent saturation issues
2565  if(CTRL_getFlag_enableDcBusComp(handle))
2566  {
2567  Kp_Id = _IQmpy(Kp_Id,EST_getOneOverDcBus_pu(obj->estHandle));
2568  }
2569 
2570  PID_setKp(obj->pidHandle_Id,Kp_Id);
2571 
2572  // compute the reference value
2573  refValue = CTRL_getRefValue_Id_pu(handle);
2574 
2575  // update the Id reference value
2576  EST_updateId_ref_pu(obj->estHandle,&refValue);
2577 
2578  // get the feedback value
2579  fbackValue = CTRL_getId_in_pu(handle);
2580 
2581  // compute the Id output limits
2582  CTRL_computeOutputLimits_Id(handle,maxVsMag,&outMin,&outMax);
2583 
2584  // set the minimum and maximum values
2585  PID_setMinMax(obj->pidHandle_Id,outMin,outMax);
2586 
2587  // run the Id PID controller
2588  PID_run(obj->pidHandle_Id,refValue,fbackValue,CTRL_getVd_out_addr(handle));
2589 
2590  // set the Id reference value in the estimator
2591  EST_setId_ref_pu(obj->estHandle,refValue);
2592 
2593  // ***********************************
2594  // configure and run the Iq controller
2595 
2596  // compute the Kp gain
2597  // Scale Kp instead of output to prevent saturation issues
2598  if(CTRL_getFlag_enableDcBusComp(handle))
2599  {
2600  Kp_Iq = _IQmpy(Kp_Iq,EST_getOneOverDcBus_pu(obj->estHandle));
2601  }
2602 
2603  PID_setKp(obj->pidHandle_Iq,Kp_Iq);
2604 
2605  // get the Iq reference value
2606  refValue = CTRL_getRefValue_Iq_pu(handle); //CTRL_getIq_ref_pu(handle);
2607 
2608  // get the feedback value
2609  fbackValue = CTRL_getIq_in_pu(handle);
2610 
2611  // compute the Iq output limits
2612  CTRL_computeOutputLimits_Iq(handle,maxVsMag,CTRL_getVd_out_pu(handle),&outMin,&outMax);
2613 
2614  // set the minimum and maximum values
2615  PID_setMinMax(obj->pidHandle_Iq,outMin,outMax);
2616 
2617  // run the Iq PID controller
2618  PID_run(obj->pidHandle_Iq,refValue,fbackValue,CTRL_getVq_out_addr(handle));
2619 
2620  // set the Iq reference value in the estimator
2621  EST_setIq_ref_pu(obj->estHandle,refValue);
2622 
2623  // add voltage offsets
2624  CTRL_addVdq_offset(handle);
2625  }
2626 
2627 
2628  return;
2629 
2630 } // end of CTRL_runPiOnly() function
2631 
2632 
2633 #ifdef __cplusplus
2634 }
2635 #endif // extern "C"
2636 
2638 #endif // end of _CTRL_H_ definition
2639 
2640 
2641 
2642 
MATH_vec2 Vdq_offset_pu
the Vdq offset values, pu
Definition: 32b/ctrl_obj.h:272
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
bool EST_isError(EST_Handle handle)
Determines if there is an estimator error.
PID Speed controller.
Definition: 32b/ctrl_obj.h:123
_iq maxVsMag_pu
the maximum voltage vector that is allowed, pu
Definition: 32b/ctrl_obj.h:211
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
Defines the controller (CTRL) version number.
Definition: 32b/ctrl_obj.h:131
CTRL_ErrorCode_e errorCode
the error code for the controller
Definition: 32b/ctrl_obj.h:152
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
the controller error state
Definition: ctrl_states.h:35
void CTRL_incrCounter_isr(CTRL_Handle handle)
Increments the isr counter.
Definition: 32b/ctrl.h:967
MATH_vec2 * CTRL_getIab_in_addr(CTRL_Handle handle)
Gets the alpha/beta current input vector memory address from the controller.
Definition: 32b/ctrl.h:308
_iq CTRL_getIq_ref_pu(CTRL_Handle handle)
Gets the quadrature current (Iq) reference value from the controller.
Definition: 32b/ctrl.h:414
#define _IQsinPU(A)
static _iq PID_getRefValue(PID_Handle handle)
Gets the reference value in the PID controller.
Definition: 32b/pid.h:200
void CTRL_setupEstOnLineState(CTRL_Handle handle)
Sets up the controller and trajectory generator for the estimator online state.
IPARK_Handle iparkHandle
the handle for the inverse Park transform
Definition: 32b/ctrl_obj.h:174
Contains the public interface to the types definitions.
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
bool CTRL_getFlag_enableDcBusComp(CTRL_Handle handle)
Gets the enable DC bus compensation flag value from the estimator.
Definition: 32b/ctrl.h:226
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
uint_least16_t numCtrlTicksPerSpeedTick
Defines the number of controller clock ticks per speed controller clock tick.
Definition: 32b/ctrl_obj.h:199
_iq Kd_Id
the desired Kd_Id value
Definition: 32b/ctrl_obj.h:239
float_t RoverL
the R/L value
Definition: 32b/ctrl_obj.h:229
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
_iq Ki_Iq
the desired Ki_Iq value
Definition: 32b/ctrl_obj.h:236
CLARKE_Handle clarkeHandle_I
the handle for the current Clarke transform
Definition: 32b/ctrl_obj.h:154
#define _IQ(A)
void CTRL_resetCounter_state(CTRL_Handle handle)
Resets the state counter.
Definition: 32b/ctrl.h:1107
_iq maxDelta
the maximum delta value for the trajectory generator
Definition: 32b/traj.h:73
MOTOR_Type_e type
Defines the motor type.
Definition: 32b/motor.h:82
float_t ratedFlux_VpHz
Defines the rated flux, V/Hz.
Definition: 32b/motor.h:95
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 EST_setId_ref_pu(EST_Handle handle, const _iq Id_ref_pu)
Sets the direct current (Id) reference value in the estimator in per unit (pu), IQ24.
static void PARK_setPhasor(PARK_Handle handle, const MATH_vec2 *pPhasor)
Sets the cosine/sine phasor for the inverse Park transform.
Definition: 32b/park.h:171
_iq speed_ref_pu
the speed reference, pu
Definition: 32b/ctrl_obj.h:274
void CTRL_setEstParams(EST_Handle estHandle, USER_Params *pUserParams)
Sets the default estimator parameters.
CTRL_ErrorCode_e CTRL_getErrorCode(CTRL_Handle handle)
Gets the error code from the controller (CTRL) object.
Definition: 32b/ctrl.h:172
void EST_setIq_ref_pu(EST_Handle handle, const _iq Iq_ref_pu)
Sets the quadrature current (Iq) reference value in the estimator in per unit (pu), IQ24.
_iq CTRL_getUi(CTRL_Handle handle, const CTRL_Type_e ctrlType)
Gets the integrator (Ui) value from the specified controller.
Definition: 32b/ctrl.h:806
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
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 Ki_Id
the desired Ki_Id value
Definition: 32b/ctrl_obj.h:235
_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
uint_least16_t numCtrlTicksPerTrajTick
Defines the number of controller clock ticks per trajectory clock tick.
Definition: 32b/ctrl_obj.h:201
Defines a two element vector.
Definition: 32b/math.h:248
static void CTRL_setImmediateUi(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Ui)
Sets the integrator (Ui) value in the specified controller immediately.
Definition: 32b/ctrl.h:1411
_iq CTRL_getTrajPeriod_sec(CTRL_Handle handle)
Gets the trajectory execution period.
Definition: 32b/ctrl.h:789
Contains the public interface to the offset (OFFSET) module routines.
_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
float_t CTRL_getLhf(CTRL_Handle handle)
Gets the high frequency inductance (Lhf) value from the controller.
Definition: 32b/ctrl.h:524
_iq angle_pu
the angle value, pu
Definition: 32b/ctrl_obj.h:273
_iq Kp_spd
the desired Kp_spd value
Definition: 32b/ctrl_obj.h:233
_iq spd_max
the maximum speed, pu
Definition: 32b/ctrl_obj.h:253
void CTRL_incrCounter_current(CTRL_Handle handle)
Increments the current counter.
Definition: 32b/ctrl.h:949
struct _EST_Obj_ * EST_Handle
Defines the estimator (EST) handle.
Definition: 32b/est.h:52
TRAJ_Handle trajHandle_Id
the handle for the Id trajectory generator
Definition: 32b/ctrl_obj.h:180
_iq CTRL_getId_in_pu(CTRL_Handle handle)
Gets the direct current input value from the controller.
Definition: 32b/ctrl.h:325
uint_least16_t CTRL_getNumCtrlTicksPerTrajTick(CTRL_Handle handle)
Gets the number of controller clock ticks per trajectory clock tick.
Definition: 32b/ctrl.h:602
bool CTRL_isError(CTRL_Handle handle)
Determines if there is a controller error.
Definition: 32b/ctrl.h:1053
Contains the public interface to the Proportional-Integral-Derivative (PID) controller module routine...
float_t CTRL_getCtrlPeriod_sec(CTRL_Handle handle)
Gets the controller execution period.
Definition: 32b/ctrl.h:161
_iq * CTRL_getVd_out_addr(CTRL_Handle handle)
Gets the direct voltage output value memory address from the controller.
Definition: 32b/ctrl.h:865
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
_iq CTRL_getSpd_out_pu(CTRL_Handle handle)
Gets the output speed value from the controller.
Definition: 32b/ctrl.h:723
MATH_vec2 Vab_out
the Vab output values
Definition: 32b/ctrl_obj.h:223
PID_Handle pidHandle_Id
the handle for the Id PID controller
Definition: 32b/ctrl_obj.h:165
CTRL_ErrorCode_e
Enumeration for the error codes.
Definition: 32b/ctrl_obj.h:98
float_t ctrlPeriod_sec
Defines the controller period, sec.
Definition: 32b/ctrl_obj.h:209
EST_Handle CTRL_getEstHandle(CTRL_Handle handle)
Gets the estimator handle for a given controller.
Definition: 32b/ctrl.h:183
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
#define _IQcosPU(A)
Defines a structure for the user parameters.
_iq Kp_Id
the desired Kp_Id value
Definition: 32b/ctrl_obj.h:231
uint_least16_t CTRL_getCount_traj(CTRL_Handle handle)
Gets the trajectory loop count.
Definition: 32b/ctrl.h:139
_iq CTRL_getSpd_ref_pu(CTRL_Handle handle)
Gets the output speed reference value from the controller.
Definition: 32b/ctrl.h:734
_iq CTRL_angleDelayComp(CTRL_Handle handle, const _iq angle_pu)
Runs angle delay compensation.
Definition: 32b/ctrl.h:2126
estimator error code
Definition: 32b/ctrl_obj.h:102
Contains the public interface to the estimator (EST) module routines.
EST_Handle estHandle
the handle for the parameter estimator
Definition: 32b/ctrl_obj.h:160
void CTRL_getTrajStep(CTRL_Handle handle)
Gets the trajectory step size.
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
MATH_vec2 Idq_offset_pu
the Idq offset values, pu
Definition: 32b/ctrl_obj.h:271
static _iq CTRL_getId_offset_pu(CTRL_Handle handle)
Gets the direct current (Id) offset value from the controller.
Definition: 32b/ctrl.h:370
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
static void SVGEN_run(SVGEN_Handle handle, const MATH_vec2 *pVab, MATH_vec3 *pT)
Implements a SVM that saturates at the level of MaxModulation.
Definition: 32b/svgen.h:124
void CTRL_setFlag_enableCtrl(CTRL_Handle handle, const bool state)
Sets the enable controller flag value in the estimator.
Definition: 32b/ctrl.h:1214
Defines the structures for the CTRL object.
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 CTRL_getMotorRatedFlux(CTRL_Handle handle)
Gets the motor rated flux from the controller.
Definition: 32b/ctrl.h:558
bool flag_enableDcBusComp
a flag to enable the DC bus compensation in the controller
Definition: 32b/ctrl_obj.h:264
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
static _iq CTRL_getRefValue_spd_pu(CTRL_Handle handle)
Gets the reference value for the speed controller.
Definition: 32b/ctrl.h:668
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
MATH_vec2 * CTRL_getVab_out_addr(CTRL_Handle handle)
Gets the alpha/beta voltage output vector memory address from the controller.
Definition: 32b/ctrl.h:848
MATH_vec2 * CTRL_getIdq_in_addr(CTRL_Handle handle)
Gets the direct/quadrature current input vector memory address from the controller.
Definition: 32b/ctrl.h:347
bool CTRL_doSpeedCtrl(CTRL_Handle handle)
Determines if the speed controller should be executed.
Definition: 32b/ctrl.h:2070
_iq Kd_Iq
the desired Kd_Iq value
Definition: 32b/ctrl_obj.h:240
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
bool flag_enableOffset
a flag to enable offset estimation after idle state
Definition: 32b/ctrl_obj.h:266
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
bool flag_enableCurrentCtrl
a flag to enable the current controllers
Definition: 32b/ctrl_obj.h:277
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
_iq speed_fb_pu
the feedback speed value, pu
Definition: 32b/ctrl_obj.h:275
_iq Ui_spd
the desired Ui_spd value
Definition: 32b/ctrl_obj.h:245
float_t CTRL_getRhf(CTRL_Handle handle)
Gets the high frequency resistance (Rhf) value from the controller.
Definition: 32b/ctrl.h:679
void CTRL_setupTraj(CTRL_Handle handle)
Sets up the trajectory (TRAJ) object.
void CTRL_setMaxAccel_pu(CTRL_Handle handle, const _iq maxAccel_pu)
Sets the maximum acceleration of the speed controller.
Definition: 32b/ctrl.h:1556
void CTRL_setState(CTRL_Handle handle, const CTRL_State_e state)
Sets the controller state.
Definition: 32b/ctrl.h:1774
static _iq CTRL_getRefValue_Iq_pu(CTRL_Handle handle)
Gets the reference value for the Iq current controller.
Definition: 32b/ctrl.h:424
void CTRL_addVdq_offset(CTRL_Handle handle)
Adds the Vdq offset to the Vdq values.
Definition: 32b/ctrl.h:81
_iq CTRL_getIq_in_pu(CTRL_Handle handle)
Gets the quadrature current input value from the controller.
Definition: 32b/ctrl.h:392
static void TRAJ_setIntValue(TRAJ_Handle handle, const _iq intValue)
Sets the intermediate value for the trajectory.
Definition: 32b/traj.h:154
uint_least16_t numPolePairs
Defines the number of pole pairs.
Definition: 32b/motor.h:84
MATH_vec3 Tabc
the PWM time-durations for each motor phase
_iq * CTRL_getVq_out_addr(CTRL_Handle handle)
Gets the quadrature voltage output value memory address from the controller.
Definition: 32b/ctrl.h:910
MOTOR_Type_e
Enumeration for the motor types.
Definition: 32b/motor.h:71
uint_least32_t counter_state
the state counter
Definition: 32b/ctrl_obj.h:193
void CTRL_setParams(CTRL_Handle handle, USER_Params *pUserParams)
Sets the controller parameters.
Definition: 32b/ctrl.c:292
bool CTRL_getFlag_enableSpeedCtrl(CTRL_Handle handle)
Gets the enable speed control flag value from the controller.
Definition: 32b/ctrl.h:259
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
bool CTRL_useZeroIq_ref(CTRL_Handle handle)
Determines if a zero Iq current reference should be used in the controller.
Definition: 32b/ctrl.h:1972
_iq CTRL_getSpd_max_pu(CTRL_Handle handle)
Gets the maximum speed value from the controller.
Definition: 32b/ctrl.h:701
CTRL_State_e state
the current state of the controller
Definition: 32b/ctrl_obj.h:148
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
uint_least16_t counter_isr
the isr counter
Definition: 32b/ctrl_obj.h:257
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 Kd_spd
the desired Kd_spd value
Definition: 32b/ctrl_obj.h:241
_iq value[2]
Definition: 32b/math.h:251
bool EST_doSpeedCtrl(EST_Handle handle)
Determines if speed control should be performed during motor identification.
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
_iq * CTRL_getSpd_out_addr(CTRL_Handle handle)
Gets the output speed memory address from the controller.
Definition: 32b/ctrl.h:712
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
static _iq CTRL_getSpeed_outMax_pu(CTRL_Handle handle)
Gets the maximum output value for the speed controller.
Definition: 32b/ctrl.h:756
MATH_vec2 Idq_in
the Idq input values
Definition: 32b/ctrl_obj.h:217
bool flag_enablePowerWarp
a flag to enable PowerWarp
Definition: 32b/ctrl_obj.h:265
_iq speed_outMax_pu
the maximum output of the speed PI control, pu
Definition: 32b/ctrl_obj.h:276
PID_Handle pidHandle_spd
the handle for the speed PID controller
Definition: 32b/ctrl_obj.h:171
_iq trajPeriod_sec
Defines the trajectory period, sec.
Definition: 32b/ctrl_obj.h:207
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
void HAL_runOffsetEst(HAL_Handle handle, const HAL_AdcData_t *pAdcData)
Runs offset estimation.
_iq EST_getOneOverDcBus_pu(EST_Handle handle)
Gets the inverse of the DC bus voltage in per unit (pu), IQ24.
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
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 prevState
the previous state of the controller
Definition: 32b/ctrl_obj.h:150
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
void CTRL_setCtrlPeriod_sec(CTRL_Handle handle, const float_t ctrlPeriod_sec)
Sets the controller execution period.
Definition: 32b/ctrl.h:1176
static void IPARK_run(IPARK_Handle handle, const MATH_vec2 *pInVec, MATH_vec2 *pOutVec)
Runs the inverse Park transform module.
Definition: 32b/ipark.h:137
uint_least32_t CTRL_getCtrlFreq(CTRL_Handle handle)
Gets the controller execution frequency.
Definition: 32b/ctrl.h:150
_iq Kp_Iq
the desired Kp_Iq value
Definition: 32b/ctrl_obj.h:232
PARK_Handle parkHandle
the handle for the Park object
Definition: 32b/ctrl_obj.h:162
_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
bool CTRL_doCurrentCtrl(CTRL_Handle handle)
Determines if the current controllers should be run.
Definition: 32b/ctrl.h:2053
_iq EST_getFm_pu(EST_Handle handle)
Gets the mechanical frequency of the motor in per unit (pu), IQ24.
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
uint_least16_t counter_current
the isr counter
Definition: 32b/ctrl_obj.h:255
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
bool EST_useZeroIq_ref(EST_Handle handle)
Determines if a zero Iq current reference should be used in the controller.
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
static void CTRL_computeOutputLimits_Id(CTRL_Handle handle, const _iq maxVsMag, _iq *outMin, _iq *outMax)
Computes the Id controller output limits.
Definition: 32b/ctrl.h:2005
_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
_iq CTRL_getVd_out_pu(CTRL_Handle handle)
Gets the direct voltage output value from the controller.
Definition: 32b/ctrl.h:876
CTRL_State_e
Enumeration for the controller states.
Definition: ctrl_states.h:34
#define _IQabs(A)
static _iq CTRL_getIq_offset_pu(CTRL_Handle handle)
Gets the quadrature current (Iq) offset value from the controller.
Definition: 32b/ctrl.h:403
static void CTRL_computeOutputLimits_Iq(CTRL_Handle handle, const _iq maxVsMag, const _iq Vd_out_pu, _iq *outMin, _iq *outMax)
Computes the Iq controller output limits.
Definition: 32b/ctrl.h:2023
_iq spd_out
the speed output value
Definition: 32b/ctrl_obj.h:221
CLARKE_Handle clarkeHandle_V
the handle for the voltage Clarke transform
Definition: 32b/ctrl_obj.h:157
MATH_vec2 * CTRL_getVdq_out_addr(CTRL_Handle handle)
Gets the direct/quadrature voltage output vector memory address from the controller.
Definition: 32b/ctrl.h:887
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
_iq CTRL_getMaxVsMag_pu(CTRL_Handle handle)
Gets the maximum voltage vector.
Definition: 32b/ctrl.h:541
uint_least16_t counter_traj
the traj counter
Definition: 32b/ctrl_obj.h:261
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
MOTOR_Params motorParams
the motor parameters
Definition: 32b/ctrl_obj.h:189
void CTRL_setSpdMax(CTRL_Handle handle, const _iq spdMax)
Sets maximum speed controller output.
Definition: 32b/ctrl.h:2108
uint_least16_t counter_speed
the speed counter
Definition: 32b/ctrl_obj.h:259
void CTRL_setErrorCode(CTRL_Handle handle, const CTRL_ErrorCode_e errorCode)
Sets the error code in the controller.
Definition: 32b/ctrl.h:1189
CTRL_Handle CTRL_initCtrl(const uint_least8_t estNumber, void *pMemory, const size_t numBytes)
Initializes a specified controller.
MATH_vec2 * CTRL_getIab_filt_addr(CTRL_Handle handle)
Gets the alpha/beta filtered current vector memory address from the controller.
Definition: 32b/ctrl.h:297
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
float_t Ls_q_H
Defines the quadrature stator inductance, H.
Definition: 32b/motor.h:89
_iq CTRL_getId_ref_pu(CTRL_Handle handle)
Gets the direct current (Id) reference value from the controller.
Definition: 32b/ctrl.h:336
void CTRL_resetCounter_traj(CTRL_Handle handle)
Resets the trajectory counter.
Definition: 32b/ctrl.h:1119
bool EST_doCurrentCtrl(EST_Handle handle)
Determines if current control should be performed during motor identification.
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
_iq IdRated
the Id rated current, pu
Definition: 32b/ctrl_obj.h:249
_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
static void IPARK_setPhasor(IPARK_Handle handle, const MATH_vec2 *pPhasor)
Sets the cosine/sine phasor for the inverse Park transform.
Definition: 32b/ipark.h:171
Contains public interface to various functions related to the trajectory (TRAJ) object.
bool CTRL_updateState(CTRL_Handle handle)
Updates the controller state.
Definition: 32b/ctrl.c:642
void CTRL_setIab_filt_pu(CTRL_Handle handle, const MATH_vec2 *pIab_filt_pu)
Sets the alpha/beta filtered current vector values in the controller.
_iq EST_getAngle_pu(EST_Handle handle)
Gets the angle value from the estimator in per unit (pu), IQ24.
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
void CTRL_runPiOnly(CTRL_Handle handle)
Runs the online controller.
Definition: 32b/ctrl.h:2513
bool CTRL_getFlag_enableCtrl(CTRL_Handle handle)
Gets the enable controller flag value from the estimator.
Definition: 32b/ctrl.h:204
float_t Ls_d_H
Defines the direct stator inductance, H.
Definition: 32b/motor.h:88
bool flag_enableCtrl
a flag to enable the controller
Definition: 32b/ctrl_obj.h:263
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
_iq Ui_Iq
the desired Ui_Iq value
Definition: 32b/ctrl_obj.h:244
void CTRL_setFlag_enableOffset(CTRL_Handle handle, const bool state)
Sets the enable offset flag value in the estimator.
Definition: 32b/ctrl.h:1271
static void CLARKE_run(CLARKE_Handle handle, const MATH_vec3 *pInVec, MATH_vec2 *pOutVec)
Runs the Clarke transform module for three inputs.
Definition: 32b/clarke.h:119
uint_least32_t ctrlFreq_Hz
Defines the controller frequency, Hz.
Definition: 32b/ctrl_obj.h:203
float_t Rs_Ohm
Defines the stator resistance, Ohm.
Definition: 32b/motor.h:93
static void PARK_run(PARK_Handle handle, const MATH_vec2 *pInVec, MATH_vec2 *pOutVec)
Runs the Park transform module.
Definition: 32b/park.h:137
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
#define _IQsqrt(A)
uint_least16_t CTRL_getCount_speed(CTRL_Handle handle)
Gets the speed loop count.
Definition: 32b/ctrl.h:117
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_least16_t CTRL_getCount_current(CTRL_Handle handle)
Gets the current loop count.
Definition: 32b/ctrl.h:95
Contains the public interface to the Park transform module routines.
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
bool flag_enableUserMotorParams
a flag to use known motor parameters from user.h file
Definition: 32b/ctrl_obj.h:268
void CTRL_setIq_ref_pu(CTRL_Handle handle, const _iq IqRef_pu)
Sets the quadrature current (Iq) reference value in the controller.
Definition: 32b/ctrl.h:1435
static void PID_run_spd(PID_Handle handle, const _iq refValue, const _iq fbackValue, _iq *pOutValue)
Runs the PID controller for speed.
Definition: 32b/pid.h:260
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_least32_t trajFreq_Hz
Defines the trajectory frequency, Hz.
Definition: 32b/ctrl_obj.h:205
void CTRL_resetCounter_speed(CTRL_Handle handle)
Resets the speed counter.
Definition: 32b/ctrl.h:1095
uint_least32_t CTRL_getTrajFreq(CTRL_Handle handle)
Gets the trajectory execution frequency.
Definition: 32b/ctrl.h:778
_iq CTRL_getSpd_int_ref_pu(CTRL_Handle handle)
Gets the output speed intermediate reference value from the controller.
Definition: 32b/ctrl.h:745
float_t Rr_Ohm
Defines the rotor resistance, Ohm.
Definition: 32b/motor.h:91
void CTRL_setId_ref_pu(CTRL_Handle handle, const _iq Id_ref_pu)
Sets the direct current (Id) reference value in the controller.
Definition: 32b/ctrl.h:1343
Contains the public interface to the Clarke transform (CLARKE) module routines.
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
Contains the public interface to the inverse Park transform (IPARK) module routines.
void CTRL_setMaximumSpeed_pu(CTRL_Handle handle, const _iq maxSpeed_pu)
Sets the maximum speed value in the controller.
Definition: 32b/ctrl.c:283
static _iq CTRL_getFbackValue_spd_pu(CTRL_Handle handle)
Gets the feedback value for the speed controller.
Definition: 32b/ctrl.h:193
static _iq CTRL_getRefValue_Id_pu(CTRL_Handle handle)
Gets the reference value for the Id current controller.
Definition: 32b/ctrl.h:649
uint_least16_t CTRL_getNumCtrlTicksPerSpeedTick(CTRL_Handle handle)
Gets the number of controller clock ticks per speed controller clock tick.
Definition: 32b/ctrl.h:591
Contains the public interface to the Space Vector Generator (SVGEN) module routines.
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
void CTRL_getVersion(CTRL_Handle handle, CTRL_Version *pVersion)
Gets the controller version number.
Definition: float/ctrl.c:58
float_t CTRL_getRoverL(CTRL_Handle handle)
Gets the R/L value from the controller.
Definition: 32b/ctrl.h:690
MATH_vec2 Iab_in
the Iab input values
Definition: 32b/ctrl_obj.h:213
uint_least16_t numCtrlTicksPerCurrentTick
Defines the number of controller clock ticks per current controller clock tick.
Definition: 32b/ctrl_obj.h:197
uint_least32_t CTRL_getCount_state(CTRL_Handle handle)
Gets the state count.
Definition: 32b/ctrl.h:128
void CTRL_setupEst(CTRL_Handle handle)
Sets up the estimator (CTRL) object.
void CTRL_computePhasor(const _iq angle_pu, MATH_vec2 *pPhasor)
Computes a phasor for a given angle.
Definition: 32b/ctrl.h:2040
void EST_updateId_ref_pu(EST_Handle handle, _iq *pId_ref_pu)
Updates the Id reference value used for online stator resistance estimation in per unit (pu)...
uint_least16_t numIsrTicksPerCtrlTick
Defines the number of isr clock ticks per controller clock tick.
Definition: 32b/ctrl_obj.h:195
MOTOR_Type_e CTRL_getMotorType(CTRL_Handle handle)
Gets the motor type from the controller.
Definition: 32b/ctrl.h:569
_iq CTRL_getRefValue_pu(CTRL_Handle handle, const CTRL_Type_e ctrlType)
Gets the reference value from the specified controller.
Definition: 32b/ctrl.h:625
float_t Rhf
the Rhf value
Definition: 32b/ctrl_obj.h:227
void CTRL_setRoverL(CTRL_Handle handle, const float_t RoverL)
Sets the R/L value in the controller.
Definition: 32b/ctrl.h:1684
_iq Ki_spd
the desired Ki_spd value
Definition: 32b/ctrl_obj.h:237
TRAJ_Obj traj_spd
the speed trajectory generator object
Definition: 32b/ctrl_obj.h:184
float_t Lhf
the Lhf value
Definition: 32b/ctrl_obj.h:228
bool CTRL_getFlag_enablePowerWarp(CTRL_Handle handle)
Gets the PowerWarp enable flag value from the estimator.
Definition: 32b/ctrl.h:237
void CTRL_incrCounter_traj(CTRL_Handle handle)
Increments the trajectory counter.
Definition: 32b/ctrl.h:1021
void CTRL_setUi(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Ui)
Sets the integrator (Ui) value in the specified controller.
Definition: 32b/ctrl.h:1815
_iq Ui_Id
the desired Ui_Id value
Definition: 32b/ctrl_obj.h:243
bool flag_enableSpeedCtrl
a flag to enable the speed controller
Definition: 32b/ctrl_obj.h:267
_iq CTRL_getVq_out_pu(CTRL_Handle handle)
Gets the quadrature voltage output value from the controller.
Definition: 32b/ctrl.h:921
uint_least16_t CTRL_getNumCtrlTicksPerCurrentTick(CTRL_Handle handle)
Gets the number of controller clock ticks per current controller clock tick.
Definition: 32b/ctrl.h:580
static _iq * CTRL_getIq_ref_pu_addr(CTRL_Handle handle)
Gets the quadrature current (Iq) reference memory address from the controller.
Definition: 32b/ctrl.h:435
#define GLOBAL_Q
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
bool CTRL_getFlag_enableCurrentCtrl(CTRL_Handle handle)
Gets the enable current controllers flag value from the controller.
Definition: 32b/ctrl.h:215
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
static void PID_setKp(PID_Handle handle, const _iq Kp)
Sets the proportional gain in the PID controller.
Definition: 32b/pid.h:342
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
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121
void CTRL_setupCtrl(CTRL_Handle handle)
Sets up the controllers.
Defines the hardware abstraction layer (HAL) data.
void CTRL_runOnLine(CTRL_Handle handle, const HAL_AdcData_t *pAdcData, HAL_PwmData_t *pPwmData)
Runs the online controller.
Definition: 32b/ctrl.h:2158
MATH_vec2 * CTRL_getVab_in_addr(CTRL_Handle handle)
Gets the alpha/beta voltage input vector memory address from the controller.
Definition: 32b/ctrl.h:831
static void PID_run(PID_Handle handle, const _iq refValue, const _iq fbackValue, _iq *pOutValue)
Runs the PID controller.
Definition: 32b/pid.h:231
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)
Runs the estimator.
SVGEN_Handle svgenHandle
the handle for the space vector generator
Definition: 32b/ctrl_obj.h:177
bool CTRL_getFlag_enableOffset(CTRL_Handle handle)
Gets the enable offset flag value from the controller.
Definition: 32b/ctrl.h:248