MotorWare f2806x Module API Documentation
float/ctrl.h
Go to the documentation of this file.
1 #ifndef _CTRL_H_
2 #define _CTRL_H_
3 
9 
10 
11 // **************************************************************************
12 // the includes
13 #ifdef __TMS320C28XX_CLA__
15 #else
16 #include <math.h>
17 #endif
18 
19 
20 // drivers
21 
22 
23 // modules
25 
31 
32 
33 // solutions
34 
35 
40 
41 
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 
48 // **************************************************************************
49 // the defines
50 
51 
52 // **************************************************************************
53 // the typedefs
54 
55 
56 // **************************************************************************
57 // the globals
58 
59 
60 // **************************************************************************
61 // the function prototypes
62 
65 static inline void CTRL_checkForErrors(CTRL_Handle handle)
66 {
67 
68  return;
69 } // end of CTRL_checkForErrors() function
70 
71 
75 static inline void CTRL_computePhasor(const float_t angle_rad,MATH_vec2 *pPhasor)
76 {
77 
78 #ifdef __TMS320C28XX_CLA__
79  pPhasor->value[0] = CLAcos_inline(angle_rad);
80  pPhasor->value[1] = CLAsin_inline(angle_rad);
81 #else
82  pPhasor->value[0] = (float_t)cos(angle_rad);
83  pPhasor->value[1] = (float_t)sin(angle_rad);
84 #endif
85 
86  return;
87 } // end of CTRL_computePhasor() function
88 
89 
92 static inline void CTRL_disable(CTRL_Handle handle)
93 {
94  CTRL_Obj *obj = (CTRL_Obj *)handle;
95 
96  obj->flag_enable = false;
97 
98  return;
99 } // end of CTRL_disable() function
100 
101 
104 static inline void CTRL_enable(CTRL_Handle handle)
105 {
106  CTRL_Obj *obj = (CTRL_Obj *)handle;
107 
108  obj->flag_enable = true;
109 
110  return;
111 } // end of CTRL_enable() function
112 
113 
117 static inline float_t CTRL_getBWc_rps(CTRL_Handle handle)
118 {
119  CTRL_Obj *obj = (CTRL_Obj *)handle;
120 
121  return(obj->BWc_rps);
122 } // end of CTRL_getBWc_rps() function
123 
124 
128 static inline float_t CTRL_getBWdelta(CTRL_Handle handle)
129 {
130  CTRL_Obj *obj = (CTRL_Obj *)handle;
131 
132  return(obj->BWdelta);
133 } // end of CTRL_getBWdelta() function
134 
135 
140 {
141  CTRL_Obj *obj = (CTRL_Obj *)handle;
142 
143  return(obj->Kctrl_Wb_p_kgm2);
144 } // end of CTRL_getKctrl_Wb_p_kgm2() function
145 
146 
150 static inline float_t CTRL_getVd_sf(CTRL_Handle handle)
151 {
152  CTRL_Obj *obj = (CTRL_Obj *)handle;
153 
154  return(obj->Vd_sf);
155 } // end of CTRL_getVd_sf() function
156 
157 
162 {
163  CTRL_Obj *obj = (CTRL_Obj *)handle;
164 
165  return(obj->maxVsMag_V);
166 } // end of CTRL_getMaxVsMag_V() function
167 
168 
173 static inline void CTRL_computeOutputLimits_Id(CTRL_Handle handle,
174  float_t *outMin,float_t *outMax)
175 {
176  float_t Vd_sf = CTRL_getVd_sf(handle);
177  float_t maxVsMag_V = CTRL_getMaxVsMag_V(handle);
178  float_t tmp = Vd_sf * maxVsMag_V;
179 
180  *outMin = -tmp;
181  *outMax = tmp;
182 
183  return;
184 } // end of CTRL_computeOutputLimits_Id() function
185 
186 
192 static inline void CTRL_computeOutputLimits_Iq(CTRL_Handle handle,
193  const float_t Vd_out_V,
194  float_t *outMin,float_t *outMax)
195 {
196  float_t maxVsMag_V = CTRL_getMaxVsMag_V(handle);
197 
198 #ifdef __TMS320C28XX_CLA__
199  float_t tmp = CLAsqrt_inline((maxVsMag_V * maxVsMag_V) - (Vd_out_V * Vd_out_V));
200 #else
201  float_t tmp = (float_t)sqrt((maxVsMag_V * maxVsMag_V) - (Vd_out_V * Vd_out_V));
202 #endif
203 
204  *outMin = -tmp;
205  *outMax = tmp;
206 
207  return;
208 } // end of CTRL_computeOutputLimits_Iq() function
209 
210 
214 static inline int_least16_t CTRL_getCount_current(CTRL_Handle handle)
215 {
216  CTRL_Obj *obj = (CTRL_Obj *)handle;
217 
218  return(obj->counter_current);
219 } // end of CTRL_getCount_current() function
220 
221 
225 static inline int_least16_t CTRL_getCount_isr(CTRL_Handle handle)
226 {
227  CTRL_Obj *obj = (CTRL_Obj *)handle;
228 
229  return(obj->counter_isr);
230 } // end of CTRL_getCount_isr() function
231 
232 
236 static inline int_least16_t CTRL_getCount_speed(CTRL_Handle handle)
237 {
238  CTRL_Obj *obj = (CTRL_Obj *)handle;
239 
240  return(obj->counter_speed);
241 } // end of CTRL_getCount_speed() function
242 
243 
247 static inline int_least32_t CTRL_getCount_state(CTRL_Handle handle)
248 {
249  CTRL_Obj *obj = (CTRL_Obj *)handle;
250 
251  return(obj->counter_state);
252 } // end of CTRL_getCount_state() function
253 
254 
259 {
260  CTRL_Obj *obj = (CTRL_Obj *)handle;
261 
262  return(obj->ctrlFreq_Hz);
263 } // end of CTRL_getCtrlFreq_Hz() function
264 
265 
270 {
271  CTRL_Obj *obj = (CTRL_Obj *)handle;
272 
273  return(obj->currentCtrlPeriod_sec);
274 } // end of CTRL_getCurrentCtrlPeriod_sec() function
275 
276 
280 static inline float_t CTRL_getCtrlPeriod_sec(CTRL_Handle handle)
281 {
282  CTRL_Obj *obj = (CTRL_Obj *)handle;
283 
284  return(obj->ctrlPeriod_sec);
285 } // end of CTRL_getCtrlPeriod_sec() function
286 
287 
291 static inline CTRL_ErrorCode_e CTRL_getErrorCode(CTRL_Handle handle)
292 {
293  CTRL_Obj *obj = (CTRL_Obj *)handle;
294 
295  return(obj->errorCode);
296 } // end of CTRL_getErrorCode() function
297 
298 
302 static inline bool CTRL_getFlag_enable(CTRL_Handle handle)
303 {
304  CTRL_Obj *obj = (CTRL_Obj *)handle;
305 
306  return(obj->flag_enable);
307 } // end of CTRL_getFlag_enable() function
308 
309 
313 static inline bool CTRL_getFlag_enableCurrentCtrl(CTRL_Handle handle)
314 {
315  CTRL_Obj *obj = (CTRL_Obj *)handle;
316 
317  return(obj->flag_enableCurrentCtrl);
318 } // end of CTRL_getFlag_enableCurrentCtrl() function
319 
320 
324 static inline bool CTRL_getFlag_enableSpeedCtrl(CTRL_Handle handle)
325 {
326  CTRL_Obj *obj = (CTRL_Obj *)handle;
327 
328  return(obj->flag_enableSpeedCtrl);
329 } // end of CTRL_getFlag_enableSpeedCtrl() function
330 
331 
335 static inline bool CTRL_getFlag_resetInt_Id(CTRL_Handle handle)
336 {
337  CTRL_Obj *obj = (CTRL_Obj *)handle;
338 
339  return(obj->flag_resetInt_Id);
340 } // end of CTRL_getFlag_resetInt_Id() function
341 
342 
346 static inline bool CTRL_getFlag_resetInt_Iq(CTRL_Handle handle)
347 {
348  CTRL_Obj *obj = (CTRL_Obj *)handle;
349 
350  return(obj->flag_resetInt_Iq);
351 } // end of CTRL_getFlag_resetInt_Iq() function
352 
353 
357 static inline bool CTRL_getFlag_resetInt_spd(CTRL_Handle handle)
358 {
359  CTRL_Obj *obj = (CTRL_Obj *)handle;
360 
361  return(obj->flag_resetInt_spd);
362 } // end of CTRL_getFlag_resetInt_spd() function
363 
364 
368 static inline bool CTRL_getFlag_useZeroIq_ref(CTRL_Handle handle)
369 {
370  CTRL_Obj *obj = (CTRL_Obj *)handle;
371 
372  return(obj->flag_useZeroIq_ref);
373 } // end of CTRL_getFlag_useZeroIq_ref() function
374 
375 
379 static inline float_t CTRL_getId_A(CTRL_Handle handle)
380 {
381  CTRL_Obj *obj = (CTRL_Obj *)handle;
382 
383  return(obj->Idq_A.value[0]);
384 } // end of CTRL_getId_A() function
385 
386 
390 static inline float_t *CTRL_getId_A_addr(CTRL_Handle handle)
391 {
392  CTRL_Obj *obj = (CTRL_Obj *)handle;
393 
394  return(&(obj->Idq_A.value[0]));
395 } // end of CTRL_getId_A_addr() function
396 
397 
402 {
403  CTRL_Obj *obj = (CTRL_Obj *)handle;
404 
405  return(obj->Idq_offset_A.value[0]);
406 } // end of CTRL_getId_offset_A() function
407 
408 
413 {
414  CTRL_Obj *obj = (CTRL_Obj *)handle;
415 
416  return(&(obj->Idq_offset_A.value[0]));
417 } // end of CTRL_getId_offset_A_addr() function
418 
419 
423 static inline float_t CTRL_getId_ref_A(CTRL_Handle handle)
424 {
425  CTRL_Obj *obj = (CTRL_Obj *)handle;
426 
427  return(obj->Idq_ref_A.value[0]);
428 } // end of CTRL_getId_ref_A() function
429 
430 
435 {
436  CTRL_Obj *obj = (CTRL_Obj *)handle;
437 
438  return(&(obj->Idq_ref_A.value[0]));
439 } // end of CTRL_getId_ref_A_addr() function
440 
441 
445 static inline void CTRL_getIdq_A(CTRL_Handle handle,MATH_vec2 *pIdq_A)
446 {
447  CTRL_Obj *obj = (CTRL_Obj *)handle;
448 
449  pIdq_A->value[0] = obj->Idq_A.value[0];
450  pIdq_A->value[1] = obj->Idq_A.value[1];
451 
452  return;
453 } // end of CTRL_getIdq_A() function
454 
455 
460 {
461  CTRL_Obj *obj = (CTRL_Obj *)handle;
462 
463  return(&(obj->Idq_A));
464 } // end of CTRL_getIdq_A_addr() function
465 
466 
470 static inline void CTRL_getIdq_offset_A(CTRL_Handle handle,MATH_vec2 *pIdq_offset_A)
471 {
472  CTRL_Obj *obj = (CTRL_Obj *)handle;
473 
474  pIdq_offset_A->value[0] = obj->Idq_offset_A.value[0];
475  pIdq_offset_A->value[1] = obj->Idq_offset_A.value[1];
476 
477  return;
478 } // end of CTRL_getIdq_offset_A() function
479 
480 
485 {
486  CTRL_Obj *obj = (CTRL_Obj *)handle;
487 
488  return(&(obj->Idq_offset_A));
489 } // end of CTRL_getIdq_offset_A_addr() function
490 
491 
495 static inline void CTRL_getIdq_ref_A(CTRL_Handle handle,MATH_vec2 *pIdq_ref_A)
496 {
497  CTRL_Obj *obj = (CTRL_Obj *)handle;
498 
499  pIdq_ref_A->value[0] = obj->Idq_ref_A.value[0];
500  pIdq_ref_A->value[1] = obj->Idq_ref_A.value[1];
501 
502  return;
503 } // end of CTRL_getIdq_ref_A() function
504 
505 
510 {
511  CTRL_Obj *obj = (CTRL_Obj *)handle;
512 
513  return(&(obj->Idq_ref_A));
514 } // end of CTRL_getIdq_ref_A_addr() function
515 
516 
520 static inline float_t CTRL_getIq_A(CTRL_Handle handle)
521 {
522  CTRL_Obj *obj = (CTRL_Obj *)handle;
523 
524  return(obj->Idq_A.value[1]);
525 } // end of CTRL_getIq_A() function
526 
527 
531 static inline float_t *CTRL_getIq_A_addr(CTRL_Handle handle)
532 {
533  CTRL_Obj *obj = (CTRL_Obj *)handle;
534 
535  return(&(obj->Idq_A.value[1]));
536 } // end of CTRL_getIq_A_addr() function
537 
538 
543 {
544  CTRL_Obj *obj = (CTRL_Obj *)handle;
545 
546  return(obj->Idq_offset_A.value[1]);
547 } // end of CTRL_getIq_offset_A() function
548 
549 
554 {
555  CTRL_Obj *obj = (CTRL_Obj *)handle;
556 
557  return(&(obj->Idq_offset_A.value[1]));
558 } // end of CTRL_getIq_offset_A_addr() function
559 
560 
564 static inline float_t CTRL_getIq_ref_A(CTRL_Handle handle)
565 {
566  CTRL_Obj *obj = (CTRL_Obj *)handle;
567 
568  return(obj->Idq_ref_A.value[1]);
569 } // end of CTRL_getIq_ref_A() function
570 
571 
576 {
577  CTRL_Obj *obj = (CTRL_Obj *)handle;
578 
579  return(&(obj->Idq_ref_A.value[1]));
580 } // end of CTRL_getIq_ref_A_addr() function
581 
582 
587 static inline float_t CTRL_getKi(CTRL_Handle handle,const CTRL_Type_e ctrlType)
588 {
589  CTRL_Obj *obj = (CTRL_Obj *)handle;
590  float_t Ki = (float_t)0.0;
591 
592  if(ctrlType == CTRL_Type_PI_spd)
593  {
594  Ki = obj->Ki_spd_ApHz;
595  }
596  else if(ctrlType == CTRL_Type_PI_Id)
597  {
598  Ki = obj->Ki_Id;
599  }
600  else if(ctrlType == CTRL_Type_PI_Iq)
601  {
602  Ki = obj->Ki_Iq;
603  }
604  else
605  {
606  // do nothing as of now
607  ;
608  }
609 
610  return(Ki);
611 } // end of CTRL_getKi() function
612 
613 
618 static inline float_t CTRL_getKp(CTRL_Handle handle,const CTRL_Type_e ctrlType)
619 {
620  CTRL_Obj *obj = (CTRL_Obj *)handle;
621  float_t Kp = (float_t)0.0;
622 
623  if(ctrlType == CTRL_Type_PI_spd)
624  {
625  Kp = obj->Kp_spd_ApHz;
626  }
627  else if(ctrlType == CTRL_Type_PI_Id)
628  {
629  Kp = obj->Kp_Id_VpA;
630  }
631  else if(ctrlType == CTRL_Type_PI_Iq)
632  {
633  Kp = obj->Kp_Iq_VpA;
634  }
635  else
636  {
637  // do nothing as of now
638  ;
639  }
640 
641  return(Kp);
642 } // end of CTRL_getKp() function
643 
644 
650 static inline void CTRL_getGains(CTRL_Handle handle,const CTRL_Type_e ctrlType,
651  float_t *pKp,float_t *pKi)
652 {
653  *pKp = CTRL_getKp(handle,ctrlType);
654  *pKi = CTRL_getKi(handle,ctrlType);
655 
656  return;
657 } // end of CTRL_getGains() function
658 
659 
663 static inline MOTOR_Type_e CTRL_getMotorType(CTRL_Handle handle)
664 {
665  CTRL_Obj *obj = (CTRL_Obj *)handle;
666 
667  return(obj->motorParams.type);
668 } // end of CTRL_getMotorType() function
669 
670 
674 static inline int_least16_t CTRL_getNumCtrlTicksPerCurrentTick(CTRL_Handle handle)
675 {
676  CTRL_Obj *obj = (CTRL_Obj *)handle;
677 
678  return(obj->numCtrlTicksPerCurrentTick);
679 } // end of CTRL_getNumCtrlTicksPerCurrentTick() function
680 
681 
685 static inline int_least16_t CTRL_getNumCtrlTicksPerSpeedTick(CTRL_Handle handle)
686 {
687  CTRL_Obj *obj = (CTRL_Obj *)handle;
688 
689  return(obj->numCtrlTicksPerSpeedTick);
690 } // end of CTRL_getNumCtrlTicksPerSpeedTick() function
691 
692 
696 static inline int_least16_t CTRL_getNumIsrTicksPerCtrlTick(CTRL_Handle handle)
697 {
698  CTRL_Obj *obj = (CTRL_Obj *)handle;
699 
700  return(obj->numIsrTicksPerCtrlTick);
701 } // end of CTRL_getNumIsrTicksPerCtrlTick() function
702 
703 
708 static inline float_t CTRL_getRefValue(CTRL_Handle handle,const CTRL_Type_e ctrlType)
709 {
710  CTRL_Obj *obj = (CTRL_Obj *)handle;
711  float_t ref = (float_t)0.0;
712 
713  if(ctrlType == CTRL_Type_PI_spd)
714  {
715  ref = PI_getRefValue(obj->piHandle_spd);
716  }
717  else if(ctrlType == CTRL_Type_PI_Id)
718  {
719  ref = PI_getRefValue(obj->piHandle_Id);
720  }
721  else if(ctrlType == CTRL_Type_PI_Iq)
722  {
723  ref = PI_getRefValue(obj->piHandle_Iq);
724  }
725  else
726  {
727  // do nothing as of now
728  ;
729  }
730 
731  return(ref);
732 } // end of CTRL_getRefValue() function
733 
734 
739 {
740  CTRL_Obj *obj = (CTRL_Obj *)handle;
741 
742  return(obj->speed_fb_Hz);
743 } // end of CTRL_getSpeed_fb_Hz() function
744 
745 
750 {
751  CTRL_Obj *obj = (CTRL_Obj *)handle;
752 
753  return(obj->speed_out_A);
754 } // end of CTRL_getSpeed_out_A() function
755 
756 
761 {
762  CTRL_Obj *obj = (CTRL_Obj *)handle;
763 
764  return(&(obj->speed_out_A));
765 } // end of CTRL_getSpeed_out_A_addr() function
766 
767 
772 {
773  CTRL_Obj *obj = (CTRL_Obj *)handle;
774 
775  return(obj->speed_outMax_A);
776 } // end of CTRL_getSpeed_outMax_A() function
777 
778 
783 {
784  CTRL_Obj *obj = (CTRL_Obj *)handle;
785 
786  return(obj->speed_outMin_A);
787 } // end of CTRL_getSpeed_outMin_A() function
788 
789 
794 {
795  CTRL_Obj *obj = (CTRL_Obj *)handle;
796 
797  return(obj->speed_ref_Hz);
798 } // end of CTRL_getSpeed_ref_Hz() function
799 
800 
805 {
806  CTRL_Obj *obj = (CTRL_Obj *)handle;
807 
808  return(obj->speedCtrlPeriod_sec);
809 } // end of CTRL_getSpeedCtrlPeriod_sec() function
810 
811 
815 static inline CTRL_State_e CTRL_getState(CTRL_Handle handle)
816 {
817  CTRL_Obj *obj = (CTRL_Obj *)handle;
818 
819  return(obj->state);
820 } // end of CTRL_getState() function
821 
822 
826 static inline float_t CTRL_getUi(CTRL_Handle handle,const CTRL_Type_e ctrlType)
827 {
828  CTRL_Obj *obj = (CTRL_Obj *)handle;
829  float_t Ui = (float_t)0.0;
830 
831  if(ctrlType == CTRL_Type_PI_spd)
832  {
833  Ui = obj->Ui_spd_A;
834  }
835  else if(ctrlType == CTRL_Type_PI_Id)
836  {
837  Ui = obj->Ui_Id_V;
838  }
839  else if(ctrlType == CTRL_Type_PI_Iq)
840  {
841  Ui = obj->Ui_Iq_V;
842  }
843  else
844  {
845  // do nothing as of now
846  ;
847  }
848 
849  return(Ui);
850 } // end of CTRL_getUi() function
851 
852 
856 static inline float_t CTRL_getVd_V(CTRL_Handle handle)
857 {
858  CTRL_Obj *obj = (CTRL_Obj *)handle;
859 
860  return(obj->Vdq_V.value[0]);
861 } // end of CTRL_getVd_V() function
862 
863 
867 static inline float_t *CTRL_getVd_V_addr(CTRL_Handle handle)
868 {
869  CTRL_Obj *obj = (CTRL_Obj *)handle;
870 
871  return(&(obj->Vdq_V.value[0]));
872 } // end of CTRL_getVd_V_addr() function
873 
874 
879 {
880  CTRL_Obj *obj = (CTRL_Obj *)handle;
881 
882  return(obj->Vdq_offset_V.value[0]);
883 } // end of CTRL_getVd_offset_V() function
884 
885 
890 {
891  CTRL_Obj *obj = (CTRL_Obj *)handle;
892 
893  return(&(obj->Vdq_offset_V.value[0]));
894 } // end of CTRL_getVd_offset_V_addr() function
895 
896 
900 static inline void CTRL_getVdq_V(CTRL_Handle handle,MATH_vec2 *pVdq_V)
901 {
902  CTRL_Obj *obj = (CTRL_Obj *)handle;
903 
904  pVdq_V->value[0] = obj->Vdq_V.value[0];
905  pVdq_V->value[1] = obj->Vdq_V.value[1];
906 
907  return;
908 } // end of CTRL_getVdq_V() function
909 
910 
915 {
916  CTRL_Obj *obj = (CTRL_Obj *)handle;
917 
918  return(&(obj->Vdq_V));
919 } // end of CTRL_getVdq_V_addr() function
920 
921 
925 static inline void CTRL_getVdq_offset_V(CTRL_Handle handle,MATH_vec2 *pVdq_offset_V)
926 {
927  CTRL_Obj *obj = (CTRL_Obj *)handle;
928 
929  pVdq_offset_V->value[0] = obj->Vdq_offset_V.value[0];
930  pVdq_offset_V->value[1] = obj->Vdq_offset_V.value[1];
931 
932  return;
933 } // end of CTRL_getVdq_offset_V() function
934 
935 
940 {
941  CTRL_Obj *obj = (CTRL_Obj *)handle;
942 
943  return(&(obj->Vdq_offset_V));
944 } // end of CTRL_getVdq_offset_V_addr() function
945 
946 
950 extern void CTRL_getVersion(CTRL_Handle handle,CTRL_Version *pVersion);
951 
952 
956 static inline float_t CTRL_getVq_V(CTRL_Handle handle)
957 {
958  CTRL_Obj *obj = (CTRL_Obj *)handle;
959 
960  return(obj->Vdq_V.value[1]);
961 } // end of CTRL_getVq_V() function
962 
963 
967 static inline float_t *CTRL_getVq_V_addr(CTRL_Handle handle)
968 {
969  CTRL_Obj *obj = (CTRL_Obj *)handle;
970 
971  return(&(obj->Vdq_V.value[1]));
972 } // end of CTRL_getVq_V_addr() function
973 
974 
979 {
980  CTRL_Obj *obj = (CTRL_Obj *)handle;
981 
982  return(obj->Vdq_offset_V.value[1]);
983 } // end of CTRL_getVq_offset_V() function
984 
985 
990 {
991  CTRL_Obj *obj = (CTRL_Obj *)handle;
992 
993  return(&(obj->Vdq_offset_V.value[1]));
994 } // end of CTRL_getVq_offset_V_addr() function
995 
996 
1001 static inline int_least32_t CTRL_getWaitTime(CTRL_Handle handle,const CTRL_State_e state)
1002 {
1003  CTRL_Obj *obj = (CTRL_Obj *)handle;
1004 
1005  return(obj->waitTimes[state]);
1006 } // end of CTRL_getWaitTime() function
1007 
1008 
1012 extern void CTRL_getWaitTimes(CTRL_Handle handle,int_least32_t *pWaitTimes);
1013 
1014 
1017 static inline void CTRL_incrCounter_current(CTRL_Handle handle)
1018 {
1019  CTRL_Obj *obj = (CTRL_Obj *)handle;
1020 
1021  int_least16_t count = obj->counter_current;
1022 
1023  // increment the count
1024  count++;
1025 
1026  // limit to 0 to INT_LEAST16_MAX - 1
1027  if(count == INT_LEAST16_MAX)
1028  {
1029  count = 0;
1030  }
1031 
1032  // save the count value
1033  obj->counter_current = count;
1034 
1035  return;
1036 } // end of CTRL_incrCounter_current() function
1037 
1038 
1041 static inline void CTRL_incrCounter_isr(CTRL_Handle handle)
1042 {
1043  CTRL_Obj *obj = (CTRL_Obj *)handle;
1044 
1045  int_least16_t count = obj->counter_isr;
1046 
1047  // increment the count
1048  count++;
1049 
1050  // limit to 0 to INT_LEAST16_MAX - 1
1051  if(count == INT_LEAST16_MAX)
1052  {
1053  count = 0;
1054  }
1055 
1056  // save the count value
1057  obj->counter_isr = count;
1058 
1059  return;
1060 } // end of CTRL_incrCounter_isr() function
1061 
1062 
1065 static inline void CTRL_incrCounter_speed(CTRL_Handle handle)
1066 {
1067  CTRL_Obj *obj = (CTRL_Obj *)handle;
1068 
1069  int_least16_t count = obj->counter_speed;
1070 
1071  // increment the count
1072  count++;
1073 
1074  // limit to 0 to INT_LEAST16_MAX - 1
1075  if(count == INT_LEAST16_MAX)
1076  {
1077  count = 0;
1078  }
1079 
1080  // save the count value
1081  obj->counter_speed = count;
1082 
1083  return;
1084 } // end of CTRL_incrCounter_speed() function
1085 
1086 
1089 static inline void CTRL_incrCounter_state(CTRL_Handle handle)
1090 {
1091  CTRL_Obj *obj = (CTRL_Obj *)handle;
1092 
1093  int_least32_t count = obj->counter_state;
1094 
1095  // increment the count
1096  count++;
1097 
1098  // limit to 0 to INT_LEAST32_MAX - 1
1099  if(count == INT_LEAST32_MAX)
1100  {
1101  count = 0;
1102  }
1103 
1104  // save the count value
1105  obj->counter_state = count;
1106 
1107  return;
1108 } // end of CTRL_incrCounter_state() function
1109 
1110 
1115 extern CTRL_Handle CTRL_init(void *pMemory,const size_t numBytes);
1116 
1117 
1120 static inline bool CTRL_isEnabled(CTRL_Handle handle)
1121 {
1122  CTRL_Obj *obj = (CTRL_Obj *)handle;
1123 
1124  return(obj->flag_enable);
1125 } // end of CTRL_isEnabled() function
1126 
1127 
1131 static inline bool CTRL_isError(CTRL_Handle handle)
1132 {
1133  CTRL_State_e ctrlState = CTRL_getState(handle);
1134  bool state = false;
1135 
1136 
1137  // check for controller errors
1138  if(ctrlState == CTRL_State_Error)
1139  {
1140  state = true;
1141  }
1142 
1143  return(state);
1144 } // end of CTRL_isError() function
1145 
1146 
1150 static inline bool CTRL_isIdle(CTRL_Handle handle)
1151 {
1152  CTRL_State_e state = CTRL_getState(handle);
1153  bool result = false;
1154 
1155  if(state == CTRL_State_Idle)
1156  {
1157  result = true;
1158  }
1159 
1160  return(result);
1161 } // end of CTRL_isIdle() function
1162 
1163 
1167 static inline bool CTRL_isNotIdle(CTRL_Handle handle)
1168 {
1169  CTRL_State_e state = CTRL_getState(handle);
1170  bool result = true;
1171 
1172  if(state == CTRL_State_Idle)
1173  {
1174  result = false;
1175  }
1176 
1177  return(result);
1178 } // end of CTRL_isNotIdle() function
1179 
1180 
1183 extern void CTRL_reset(CTRL_Handle handle);
1184 
1185 
1188 static inline void CTRL_resetCounter_current(CTRL_Handle handle)
1189 {
1190  CTRL_Obj *obj = (CTRL_Obj *)handle;
1191 
1192  obj->counter_current = 0;
1193 
1194  return;
1195 } // end of CTRL_resetCounter_current() function
1196 
1197 
1200 static inline void CTRL_resetCounter_isr(CTRL_Handle handle)
1201 {
1202  CTRL_Obj *obj = (CTRL_Obj *)handle;
1203 
1204  obj->counter_isr = 0;
1205 
1206  return;
1207 } // end of CTRL_resetCounter_isr() function
1208 
1209 
1212 static inline void CTRL_resetCounter_speed(CTRL_Handle handle)
1213 {
1214  CTRL_Obj *obj = (CTRL_Obj *)handle;
1215 
1216  obj->counter_speed = 0;
1217 
1218  return;
1219 } // end of CTRL_resetCounter_speed() function
1220 
1221 
1224 static inline void CTRL_resetCounter_state(CTRL_Handle handle)
1225 {
1226  CTRL_Obj *obj = (CTRL_Obj *)handle;
1227 
1228  obj->counter_state = 0;
1229 
1230  return;
1231 } // end of CTRL_resetCounter_state() function
1232 
1233 
1237 static inline void CTRL_setBWc_rps(CTRL_Handle handle,const float_t BWc_rps)
1238 {
1239  CTRL_Obj *obj = (CTRL_Obj *)handle;
1240 
1241  obj->BWc_rps = BWc_rps;
1242 
1243  return;
1244 } // end of CTRL_setBWc_rps() function
1245 
1246 
1250 static inline void CTRL_setBWdelta(CTRL_Handle handle,const float_t BWdelta)
1251 {
1252  CTRL_Obj *obj = (CTRL_Obj *)handle;
1253 
1254  obj->BWdelta = BWdelta;
1255 
1256  return;
1257 } // end of CTRL_setBWdelta() function
1258 
1259 
1263 static inline void CTRL_setCtrlFreq_Hz(CTRL_Handle handle,const float_t ctrlFreq_Hz)
1264 {
1265  CTRL_Obj *obj = (CTRL_Obj *)handle;
1266 
1267  obj->ctrlFreq_Hz = ctrlFreq_Hz;
1268 
1269  return;
1270 } // end of CTRL_setCtrlFreq_Hz() function
1271 
1272 
1276 static inline void CTRL_setCtrlPeriod_sec(CTRL_Handle handle,const float_t ctrlPeriod_sec)
1277 {
1278  CTRL_Obj *obj = (CTRL_Obj *)handle;
1279 
1280  obj->ctrlPeriod_sec = ctrlPeriod_sec;
1281 
1282  return;
1283 } // end of CTRL_setCtrlPeriod_sec() function
1284 
1285 
1289 static inline void CTRL_setCurrentCtrlPeriod_sec(CTRL_Handle handle,const float_t currentCtrlPeriod_sec)
1290 {
1291  CTRL_Obj *obj = (CTRL_Obj *)handle;
1292 
1293  obj->currentCtrlPeriod_sec = currentCtrlPeriod_sec;
1294 
1295  return;
1296 } // end of CTRL_setCurrentCtrlPeriod_sec() function
1297 
1298 
1302 static inline void CTRL_setErrorCode(CTRL_Handle handle,const CTRL_ErrorCode_e errorCode)
1303 {
1304  CTRL_Obj *obj = (CTRL_Obj *)handle;
1305 
1306  obj->errorCode = errorCode;
1307 
1308  return;
1309 } // end of CTRL_setErrorCode() function
1310 
1311 
1315 static inline void CTRL_setFlag_enable(CTRL_Handle handle,const bool state)
1316 {
1317  CTRL_Obj *obj = (CTRL_Obj *)handle;
1318 
1319  obj->flag_enable = state;
1320 
1321  return;
1322 } // end of CTRL_setFlag_enable() function
1323 
1324 
1328 static inline void CTRL_setFlag_enableCurrentCtrl(CTRL_Handle handle,const bool state)
1329 {
1330  CTRL_Obj *obj = (CTRL_Obj *)handle;
1331 
1332  obj->flag_enableCurrentCtrl = state;
1333 
1334  return;
1335 } // end of CTRL_setFlag_enableCurrentCtrl() function
1336 
1337 
1341 static inline void CTRL_setFlag_enableSpeedCtrl(CTRL_Handle handle,const bool state)
1342 {
1343  CTRL_Obj *obj = (CTRL_Obj *)handle;
1344 
1345  obj->flag_enableSpeedCtrl = state;
1346 
1347  return;
1348 } // end of CTRL_setFlag_enableSpeedCtrl() function
1349 
1350 
1354 static inline void CTRL_setFlag_resetInt_Id(CTRL_Handle handle,const bool state)
1355 {
1356  CTRL_Obj *obj = (CTRL_Obj *)handle;
1357 
1358  obj->flag_resetInt_Id = state;
1359 
1360  return;
1361 } // end of CTRL_setFlag_resetInt_Id() function
1362 
1363 
1367 static inline void CTRL_setFlag_resetInt_Iq(CTRL_Handle handle,const bool state)
1368 {
1369  CTRL_Obj *obj = (CTRL_Obj *)handle;
1370 
1371  obj->flag_resetInt_Iq = state;
1372 
1373  return;
1374 } // end of CTRL_setFlag_resetInt_Iq() function
1375 
1376 
1380 static inline void CTRL_setFlag_resetInt_spd(CTRL_Handle handle,const bool state)
1381 {
1382  CTRL_Obj *obj = (CTRL_Obj *)handle;
1383 
1384  obj->flag_resetInt_spd = state;
1385 
1386  return;
1387 } // end of CTRL_setFlag_resetInt_spd() function
1388 
1389 
1393 static inline void CTRL_setFlag_useZeroIq_ref(CTRL_Handle handle,const bool state)
1394 {
1395  CTRL_Obj *obj = (CTRL_Obj *)handle;
1396 
1397  obj->flag_useZeroIq_ref = state;
1398 
1399  return;
1400 } // end of CTRL_setFlag_userZeroIq_ref() function
1401 
1402 
1406 static inline void CTRL_setId_A(CTRL_Handle handle,const float_t Id_A)
1407 {
1408  CTRL_Obj *obj = (CTRL_Obj *)handle;
1409 
1410  obj->Idq_A.value[0] = Id_A;
1411 
1412  return;
1413 } // end of CTRL_setId_A() function
1414 
1415 
1419 static inline void CTRL_setId_offset_A(CTRL_Handle handle,const float_t Id_offset_A)
1420 {
1421  CTRL_Obj *obj = (CTRL_Obj *)handle;
1422 
1423  obj->Idq_offset_A.value[0] = Id_offset_A;
1424 
1425  return;
1426 } // end of CTRL_setId_offset_A() function
1427 
1428 
1432 static inline void CTRL_setId_ref_A(CTRL_Handle handle,const float_t Id_ref_A)
1433 {
1434  CTRL_Obj *obj = (CTRL_Obj *)handle;
1435 
1436  obj->Idq_ref_A.value[0] = Id_ref_A;
1437 
1438  return;
1439 } // end of CTRL_setId_ref_A() function
1440 
1441 
1445 static inline void CTRL_setIdq_A(CTRL_Handle handle,const MATH_vec2 *pIdq_A)
1446 {
1447  CTRL_Obj *obj = (CTRL_Obj *)handle;
1448 
1449  obj->Idq_A.value[0] = pIdq_A->value[0];
1450  obj->Idq_A.value[1] = pIdq_A->value[1];
1451 
1452  return;
1453 } // end of CTRL_setIdq_A() function
1454 
1455 
1459 static inline void CTRL_setIdq_offset_A(CTRL_Handle handle,const MATH_vec2 *pIdq_offset_A)
1460 {
1461  CTRL_Obj *obj = (CTRL_Obj *)handle;
1462 
1463  obj->Idq_offset_A.value[0] = pIdq_offset_A->value[0];
1464  obj->Idq_offset_A.value[1] = pIdq_offset_A->value[1];
1465 
1466  return;
1467 } // end of CTRL_setIdq_offset_A() function
1468 
1469 
1473 static inline void CTRL_setIdq_ref_A(CTRL_Handle handle,const MATH_vec2 *pIdq_ref_A)
1474 {
1475  CTRL_Obj *obj = (CTRL_Obj *)handle;
1476 
1477  obj->Idq_ref_A.value[0] = pIdq_ref_A->value[0];
1478  obj->Idq_ref_A.value[1] = pIdq_ref_A->value[1];
1479 
1480  return;
1481 } // end of CTRL_setIdq_ref_A() function
1482 
1483 
1487 static inline void CTRL_setIq_A(CTRL_Handle handle,const float_t Iq_A)
1488 {
1489  CTRL_Obj *obj = (CTRL_Obj *)handle;
1490 
1491  obj->Idq_A.value[1] = Iq_A;
1492 
1493  return;
1494 } // end of CTRL_setIq_A() function
1495 
1496 
1500 static inline void CTRL_setIq_offset_pu(CTRL_Handle handle,const float_t Iq_offset_A)
1501 {
1502  CTRL_Obj *obj = (CTRL_Obj *)handle;
1503 
1504  obj->Idq_offset_A.value[1] = Iq_offset_A;
1505 
1506  return;
1507 } // end of CTRL_setIq_offset_A() function
1508 
1509 
1513 static inline void CTRL_setIq_ref_A(CTRL_Handle handle,const float_t Iq_ref_A)
1514 {
1515  CTRL_Obj *obj = (CTRL_Obj *)handle;
1516 
1517  obj->Idq_ref_A.value[1] = Iq_ref_A;
1518 
1519  return;
1520 } // end of CTRL_setIq_ref_A() function
1521 
1522 
1526 static inline void CTRL_setKctrl_Wb_p_kgm2(CTRL_Handle handle,const float_t Kctrl_Wb_p_kgm2)
1527 {
1528  CTRL_Obj *obj = (CTRL_Obj *)handle;
1529 
1530  obj->Kctrl_Wb_p_kgm2 = Kctrl_Wb_p_kgm2;
1531 
1532  return;
1533 } // end of CTRL_setKctrl_Wb_p_kgm2() function
1534 
1535 
1540 static inline void CTRL_setKi(CTRL_Handle handle,const CTRL_Type_e ctrlType,const float_t Ki)
1541 {
1542  CTRL_Obj *obj = (CTRL_Obj *)handle;
1543 
1544  if(ctrlType == CTRL_Type_PI_spd)
1545  {
1546  obj->Ki_spd_ApHz = Ki;
1547  }
1548  else if(ctrlType == CTRL_Type_PI_Id)
1549  {
1550  obj->Ki_Id = Ki;
1551  }
1552  else if(ctrlType == CTRL_Type_PI_Iq)
1553  {
1554  obj->Ki_Iq = Ki;
1555  }
1556  else
1557  {
1558  // do nothing as of now
1559  ;
1560  }
1561 
1562  return;
1563 } // end of CTRL_setKi() function
1564 
1565 
1570 static inline void CTRL_setKp(CTRL_Handle handle,const CTRL_Type_e ctrlType,const float_t Kp)
1571 {
1572  CTRL_Obj *obj = (CTRL_Obj *)handle;
1573 
1574  if(ctrlType == CTRL_Type_PI_spd)
1575  {
1576  obj->Kp_spd_ApHz = Kp;
1577  }
1578  else if(ctrlType == CTRL_Type_PI_Id)
1579  {
1580  obj->Kp_Id_VpA = Kp;
1581  }
1582  else if(ctrlType == CTRL_Type_PI_Iq)
1583  {
1584  obj->Kp_Iq_VpA = Kp;
1585  }
1586  else
1587  {
1588  // do nothing as of now
1589  ;
1590  }
1591 
1592  return;
1593 } // end of CTRL_setKp() function
1594 
1595 
1601 static inline void CTRL_setGains(CTRL_Handle handle,const CTRL_Type_e ctrlType,
1602  const float_t Kp,const float_t Ki)
1603 {
1604  CTRL_setKp(handle,ctrlType,Kp);
1605  CTRL_setKi(handle,ctrlType,Ki);
1606 
1607  return;
1608 } // end of CTRL_setGains() function
1609 
1610 
1614 static inline void CTRL_setMaxVsMag_V(CTRL_Handle handle,const float_t maxVsMag_V)
1615 {
1616  CTRL_Obj *obj = (CTRL_Obj *)handle;
1617 
1618  obj->maxVsMag_V = maxVsMag_V;
1619 
1620  return;
1621 } // end of CTRL_setMaxVsMag_V() function
1622 
1623 
1635 static inline void CTRL_setMotorParams(CTRL_Handle handle,
1636  const MOTOR_Type_e motorType,
1637  const uint_least16_t numPolePairs,
1638  const float_t ratedFlux_Wb,
1639  const float_t Ls_d_H,
1640  const float_t Ls_q_H,
1641  const float_t Rs_d_Ohm,
1642  const float_t Rs_q_Ohm,
1643  const float_t Rr_d_Ohm,
1644  const float_t Rr_q_Ohm)
1645 {
1646  CTRL_Obj *obj = (CTRL_Obj *)handle;
1647 
1648  obj->motorParams.type = motorType;
1649  obj->motorParams.numPolePairs = numPolePairs;
1650  obj->motorParams.ratedFlux_Wb = ratedFlux_Wb;
1651  obj->motorParams.Ls_d_H = Ls_d_H;
1652  obj->motorParams.Ls_q_H = Ls_q_H;
1653  obj->motorParams.Rs_d_Ohm = Rs_d_Ohm;
1654  obj->motorParams.Rs_q_Ohm = Rs_q_Ohm;
1655  obj->motorParams.Rr_d_Ohm = Rr_d_Ohm;
1656  obj->motorParams.Rr_q_Ohm = Rr_q_Ohm;
1657 
1658  return;
1659 } // end of CTRL_setMotorParams() function
1660 
1661 
1666  const int_least16_t numCtrlTicksPerCurrentTick)
1667 {
1668  CTRL_Obj *obj = (CTRL_Obj *)handle;
1669 
1670  obj->numCtrlTicksPerCurrentTick = numCtrlTicksPerCurrentTick;
1671 
1672  return;
1673 } // end of CTRL_setNumCtrlTicksPerCurrentTick() function
1674 
1675 
1680  const int_least16_t numCtrlTicksPerSpeedTick)
1681 {
1682  CTRL_Obj *obj = (CTRL_Obj *)handle;
1683 
1684  obj->numCtrlTicksPerSpeedTick = numCtrlTicksPerSpeedTick;
1685 
1686  return;
1687 } // end of CTRL_setNumCtrlTicksPerSpeedTick() function
1688 
1689 
1694  const int_least16_t numIsrTicksPerCtrlTick)
1695 {
1696  CTRL_Obj *obj = (CTRL_Obj *)handle;
1697 
1698  obj->numIsrTicksPerCtrlTick = numIsrTicksPerCtrlTick;
1699 
1700  return;
1701 } // end of CTRL_setNumIsrTicksPerCtrlTick() function
1702 
1703 
1707 extern void CTRL_setParams(CTRL_Handle handle,USER_Params *pUserParams);
1708 
1709 
1713 static inline void CTRL_setSpeed_fb_Hz(CTRL_Handle handle,const float_t speed_fb_Hz)
1714 {
1715  CTRL_Obj *obj = (CTRL_Obj *)handle;
1716 
1717  obj->speed_fb_Hz = speed_fb_Hz;
1718 
1719  return;
1720 } // end of CTRL_setSpeed_fb_pu() function
1721 
1722 
1726 static inline void CTRL_setSpeed_out_A(CTRL_Handle handle, const float_t speed_out_A)
1727 {
1728  CTRL_Obj *obj = (CTRL_Obj *)handle;
1729 
1730  obj->speed_out_A = speed_out_A;
1731 
1732  return;
1733 } // end of CTRL_setSpeed_out_A() function
1734 
1735 
1739 static inline void CTRL_setSpeed_outMax_A(CTRL_Handle handle,const float_t speed_outMax_A)
1740 {
1741  CTRL_Obj *obj = (CTRL_Obj *)handle;
1742 
1743  obj->speed_outMax_A = speed_outMax_A;
1744 
1745  return;
1746 } // end of CTRL_setSpeed_outMax_A() function
1747 
1748 
1752 static inline void CTRL_setSpeed_outMin_A(CTRL_Handle handle,const float_t speed_outMin_A)
1753 {
1754  CTRL_Obj *obj = (CTRL_Obj *)handle;
1755 
1756  obj->speed_outMin_A = speed_outMin_A;
1757 
1758  return;
1759 } // end of CTRL_setSpeed_outMin_A() function
1760 
1761 
1765 static inline void CTRL_setSpeed_ref_Hz(CTRL_Handle handle,const float_t speed_ref_Hz)
1766 {
1767  CTRL_Obj *obj = (CTRL_Obj *)handle;
1768 
1769  obj->speed_ref_Hz = speed_ref_Hz;
1770 
1771  return;
1772 } // end of CTRL_setSpeed_ref_Hz() function
1773 
1774 
1778 static inline void CTRL_setSpeedCtrlPeriod_sec(CTRL_Handle handle,const float_t speedCtrlPeriod_sec)
1779 {
1780  CTRL_Obj *obj = (CTRL_Obj *)handle;
1781 
1782  obj->speedCtrlPeriod_sec = speedCtrlPeriod_sec;
1783 
1784  return;
1785 } // end of CTRL_setSpeedCtrlPeriod_sec() function
1786 
1787 
1791 static inline void CTRL_setState(CTRL_Handle handle,const CTRL_State_e state)
1792 {
1793  CTRL_Obj *obj = (CTRL_Obj *)handle;
1794 
1795  obj->prevState = obj->state;
1796  obj->state = state;
1797 
1798  return;
1799 } // end of CTRL_setState() function
1800 
1801 
1805 static inline void CTRL_setUi(CTRL_Handle handle,const CTRL_Type_e ctrlType,const float_t Ui)
1806 {
1807  CTRL_Obj *obj = (CTRL_Obj *)handle;
1808 
1809 
1810  if(ctrlType == CTRL_Type_PI_spd)
1811  {
1812  obj->Ui_spd_A = Ui;
1813 
1814  CTRL_setFlag_resetInt_spd(handle,true);
1815  }
1816  else if(ctrlType == CTRL_Type_PI_Id)
1817  {
1818  obj->Ui_Id_V = Ui;
1819 
1820  CTRL_setFlag_resetInt_Id(handle,true);
1821  }
1822  else if(ctrlType == CTRL_Type_PI_Iq)
1823  {
1824  obj->Ui_Iq_V = Ui;
1825 
1826  CTRL_setFlag_resetInt_Iq(handle,true);
1827  }
1828  else
1829  {
1830  // do nothing as of now
1831  ;
1832  }
1833 
1834  return;
1835 } // end of CTRL_setUi() function
1836 
1837 
1841 static inline void CTRL_setVd_sf(CTRL_Handle handle,const float_t Vd_sf)
1842 {
1843  CTRL_Obj *obj = (CTRL_Obj *)handle;
1844 
1845  obj->Vd_sf = Vd_sf;
1846 
1847  return;
1848 } // end of CTRL_setVd_sf() function
1849 
1850 
1854 static inline void CTRL_setVdq_V(CTRL_Handle handle,const MATH_vec2 *pVdq_V)
1855 {
1856  CTRL_Obj *obj = (CTRL_Obj *)handle;
1857 
1858  obj->Vdq_V.value[0] = pVdq_V->value[0];
1859  obj->Vdq_V.value[1] = pVdq_V->value[1];
1860 
1861  return;
1862 } // end of CTRL_setVdq_V() function
1863 
1864 
1868 static inline void CTRL_setVdq_offset_V(CTRL_Handle handle,const MATH_vec2 *pVdq_offset_V)
1869 {
1870  CTRL_Obj *obj = (CTRL_Obj *)handle;
1871 
1872  obj->Vdq_offset_V.value[0] = pVdq_offset_V->value[0];
1873  obj->Vdq_offset_V.value[1] = pVdq_offset_V->value[1];
1874 
1875  return;
1876 } // end of CTRL_setVdq_offset_V() function
1877 
1878 
1879 // TEMP
1885 extern void CTRL_setVersion(CTRL_Handle handle,
1886  const CTRL_TargetProc_e targetProc,
1887  const uint16_t majorReleaseNumber,
1888  const uint16_t minorReleaseNumber);
1889 
1890 
1894 extern void CTRL_setWaitTimes(CTRL_Handle handle,const int_least32_t *pWaitTimes);
1895 
1896 
1900 extern bool CTRL_updateState(CTRL_Handle handle);
1901 
1902 
1913 static inline void CTRL_setup(CTRL_Handle handle,
1914  const float_t speed_ref_Hz,
1915  const float_t speed_fb_Hz,
1916  const MATH_vec2 *pIdq_A,
1917  const MATH_vec2 *pIdq_offset_A,
1918  const MATH_vec2 *pVdq_offset_V,
1919  const bool flag_enableSpeedCtrl,
1920  const bool flag_enableCurrentCtrl,
1921  const bool flag_useZeroIq_ref)
1922 {
1923  CTRL_Obj *obj = (CTRL_Obj *)handle;
1924 
1925 
1926  // set the input values
1927  CTRL_setSpeed_ref_Hz(handle,speed_ref_Hz);
1928  CTRL_setSpeed_fb_Hz(handle,speed_fb_Hz);
1929 
1930  CTRL_setIdq_A(handle,pIdq_A);
1931  CTRL_setIdq_offset_A(handle,pIdq_offset_A);
1932  CTRL_setVdq_offset_V(handle,pVdq_offset_V);
1933 
1934  CTRL_setFlag_enableSpeedCtrl(handle,flag_enableSpeedCtrl);
1935  CTRL_setFlag_enableCurrentCtrl(handle,flag_enableCurrentCtrl);
1936  CTRL_setFlag_useZeroIq_ref(handle,flag_useZeroIq_ref);
1937 
1938 
1939  // if needed, reset the Id integrator
1940  if(CTRL_getFlag_resetInt_Id(handle))
1941  {
1942  float_t Ui = CTRL_getUi(handle,CTRL_Type_PI_Id);
1943 
1944  // set the new integrator value
1945  PI_setUi(obj->piHandle_Id,Ui);
1946 
1947  // reset the flag
1948  CTRL_setFlag_resetInt_Id(handle,false);
1949  }
1950 
1951 
1952  // if needed, reset the Iq integrator
1953  if(CTRL_getFlag_resetInt_Iq(handle))
1954  {
1955  float_t Ui = CTRL_getUi(handle,CTRL_Type_PI_Iq);
1956 
1957  // set the new integrator value
1958  PI_setUi(obj->piHandle_Iq,Ui);
1959 
1960  // reset the flag
1961  CTRL_setFlag_resetInt_Iq(handle,false);
1962  }
1963 
1964 
1965  // if needed, reset the speed integrator
1966  if(CTRL_getFlag_resetInt_spd(handle))
1967  {
1968  float_t Ui = CTRL_getUi(handle,CTRL_Type_PI_spd);
1969 
1970  // set the new integrator value
1971  PI_setUi(obj->piHandle_spd,Ui);
1972 
1973  // reset the flag
1974  CTRL_setFlag_resetInt_spd(handle,false);
1975  }
1976 
1977 
1978  // update the Kp gains
1982 
1983 
1984  // update the Ki gains
1988 
1989 
1990  // increment the counters
1991  CTRL_incrCounter_current(handle);
1992  CTRL_incrCounter_speed(handle);
1993 
1994  return;
1995 } // end of CTRL_setup() function
1996 
1997 
2001 static inline void CTRL_run(CTRL_Handle handle,MATH_vec2 *pVdq_V)
2002 {
2003  CTRL_Obj *obj = (CTRL_Obj *)handle;
2004 
2005 
2006  // when appropriate, run the PI speed controller
2007  if(CTRL_getFlag_enableSpeedCtrl(handle))
2008  {
2009  int_least16_t count = CTRL_getCount_speed(handle);
2010  int_least16_t numCtrlTicksPerSpeedTick = CTRL_getNumCtrlTicksPerSpeedTick(handle);
2011 
2012  if(count >= numCtrlTicksPerSpeedTick)
2013  {
2014  float_t refValue_Hz = CTRL_getSpeed_ref_Hz(handle);
2015  float_t fbackValue_Hz = CTRL_getSpeed_fb_Hz(handle);
2016  float_t ffwdValue_A = (float_t)0.0;
2017  float_t outMax_A = CTRL_getSpeed_outMax_A(handle);
2018  float_t outMin_A = CTRL_getSpeed_outMin_A(handle);
2019 
2020  // reset the speed count
2021  CTRL_resetCounter_speed(handle);
2022 
2023  // set the minimum and maximum values
2024  PI_setMinMax(obj->piHandle_spd,outMin_A,outMax_A);
2025 
2026  // run the speed controller
2027  PI_run_series(obj->piHandle_spd,refValue_Hz,fbackValue_Hz,ffwdValue_A,CTRL_getSpeed_out_A_addr(handle));
2028  }
2029  }
2030  else
2031  {
2032  // zero the speed output value
2033  CTRL_setSpeed_out_A(handle,0.0);
2034  }
2035 
2036 
2037  // when appropriate, run the PI Id and Iq controllers
2038  if(CTRL_getFlag_enableCurrentCtrl(handle))
2039  {
2040  int_least16_t count = CTRL_getCount_current(handle);
2041  int_least16_t numCtrlTicksPerCurrentTick = CTRL_getNumCtrlTicksPerCurrentTick(handle);
2042 
2043  if(count >= numCtrlTicksPerCurrentTick)
2044  {
2045  float_t refValue_A;
2046  float_t fbackValue_A;
2047  float_t ffwdValue_V;
2048  float_t outMin_V,outMax_V;
2049 
2050 
2051  // reset the current count
2052  CTRL_resetCounter_current(handle);
2053 
2054 
2055  // ***********************************
2056  // configure and run the Id controller
2057 
2058  // get the reference value
2059  refValue_A = CTRL_getId_offset_A(handle);
2060 
2061  // get the feedback value
2062  fbackValue_A = CTRL_getId_A(handle);
2063 
2064  // get the feedforward value
2065  ffwdValue_V = CTRL_getVd_offset_V(handle);
2066 
2067  // compute the Id output limits
2068  CTRL_computeOutputLimits_Id(handle,&outMin_V,&outMax_V);
2069 
2070  // set the minimum and maximum values
2071  PI_setMinMax(obj->piHandle_Id,outMin_V,outMax_V);
2072 
2073  // run the Id PI controller
2074  PI_run_series(obj->piHandle_Id,refValue_A,fbackValue_A,ffwdValue_V,&(pVdq_V->value[0]));
2075 
2076  // store the Id reference value
2077  CTRL_setId_ref_A(handle,refValue_A);
2078 
2079 
2080  // ***********************************
2081  // configure and run the Iq controller
2082 
2083  // compute the reference value
2084  if(CTRL_getFlag_enableSpeedCtrl(handle))
2085  {
2086  if(CTRL_getFlag_useZeroIq_ref(handle))
2087  {
2088  refValue_A = 0.0;
2089  }
2090  else
2091  {
2092  refValue_A = CTRL_getSpeed_out_A(handle) + CTRL_getIq_offset_A(handle);
2093  }
2094  }
2095  else
2096  {
2097  // get the Iq offset value
2098  refValue_A = CTRL_getIq_offset_A(handle);
2099  }
2100 
2101  // get the feedback value
2102  fbackValue_A = CTRL_getIq_A(handle);
2103 
2104  // get the feedforward value
2105  ffwdValue_V = CTRL_getVq_offset_V(handle);
2106 
2107  // compute the Iq output limits
2108  CTRL_computeOutputLimits_Iq(handle,pVdq_V->value[0],&outMin_V,&outMax_V);
2109 
2110  // set the minimum and maximum values
2111  PI_setMinMax(obj->piHandle_Iq,outMin_V,outMax_V);
2112 
2113  // run the Iq PI controller
2114  PI_run_series(obj->piHandle_Iq,refValue_A,fbackValue_A,ffwdValue_V,&(pVdq_V->value[1]));
2115 
2116  // store the Iq reference value
2117  CTRL_setIq_ref_A(handle,refValue_A);
2118  }
2119  else
2120  {
2121  CTRL_getVdq_V(handle,pVdq_V);
2122  }
2123  }
2124  else
2125  {
2126  pVdq_V->value[0] = 0.0;
2127  pVdq_V->value[1] = 0.0;
2128  }
2129 
2130 
2131  // store the Vdq value
2132  CTRL_setVdq_V(handle,pVdq_V);
2133 
2134 
2135  // increment the state counter
2136  CTRL_incrCounter_state(handle);
2137 
2138  return;
2139 } // end of CTRL_run() function
2140 
2141 
2142 #ifdef __cplusplus
2143 }
2144 #endif // extern "C"
2145 
2147 
2148 #endif // end of _CTRL_H_ definition
2149 
2150 
2151 
2152 
2153 
static float_t * CTRL_getIq_A_addr(CTRL_Handle handle)
Gets the quadrature current (Iq) memory address from the controller.
Definition: float/ctrl.h:531
static MATH_vec2 * CTRL_getVdq_offset_V_addr(CTRL_Handle handle)
Gets the direct/quadrature offset voltage (Vdq_offset) vector memory address from the controller...
Definition: float/ctrl.h:939
PI Speed controller.
static void CTRL_setIq_ref_A(CTRL_Handle handle, const float_t Iq_ref_A)
Sets the quadrature current (Iq) reference value in the controller.
Definition: float/ctrl.h:1513
float_t speed_outMin_A
the minimum output value for the speed controller, A
Defines the controller (CTRL) version number.
Definition: 32b/ctrl_obj.h:131
static float_t CTRL_getId_ref_A(CTRL_Handle handle)
Gets the direct reference current (Id_ref) value from the controller.
Definition: float/ctrl.h:423
CTRL_ErrorCode_e errorCode
the error code for the controller
Definition: 32b/ctrl_obj.h:152
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
static float_t CTRL_getIq_offset_A(CTRL_Handle handle)
Gets the quadrature offset current (Iq_offset) value from the controller.
Definition: float/ctrl.h:542
static void CTRL_setNumCtrlTicksPerSpeedTick(CTRL_Handle handle, const int_least16_t numCtrlTicksPerSpeedTick)
Sets the number of controller clock ticks per speed controller clock tick.
Definition: float/ctrl.h:1679
static float_t CTRL_getCurrentCtrlPeriod_sec(CTRL_Handle handle)
Gets the current controller period.
Definition: float/ctrl.h:269
float_t speedCtrlPeriod_sec
the period at which the speed controller runs, sec
Contains the public interface to the types definitions.
uint_least16_t numCtrlTicksPerSpeedTick
Defines the number of controller clock ticks per speed controller clock tick.
Definition: 32b/ctrl_obj.h:199
bool flag_enable
a flag to enable the controller
_iq Ki_Iq
the desired Ki_Iq value
Definition: 32b/ctrl_obj.h:236
static float_t * CTRL_getId_ref_A_addr(CTRL_Handle handle)
Gets the direct reference current (Id_ref) memory address from the controller.
Definition: float/ctrl.h:434
MATH_vec2 Idq_offset_A
the Idq offset values, A
static void CTRL_setFlag_enableCurrentCtrl(CTRL_Handle handle, const bool state)
Sets the enable current controllers flag value in the controller.
Definition: float/ctrl.h:1328
static void CTRL_getVdq_offset_V(CTRL_Handle handle, MATH_vec2 *pVdq_offset_V)
Gets the direct/quadrature offset voltage (Vdq_offset) vector values from the controller.
Definition: float/ctrl.h:925
static bool CTRL_getFlag_resetInt_Id(CTRL_Handle handle)
Gets the reset Id integrator flag value from the controller.
Definition: float/ctrl.h:335
void CTRL_resetCounter_state(CTRL_Handle handle)
Resets the state counter.
Definition: 32b/ctrl.h:1107
void CTRL_setWaitTimes(CTRL_Handle handle, const int_least32_t *pWaitTimes)
Sets the wait times for the controller states.
Definition: float/ctrl.c:310
static void CTRL_computePhasor(const float_t angle_rad, MATH_vec2 *pPhasor)
Computes a phasor for a given angle.
Definition: float/ctrl.h:75
MOTOR_Type_e type
Defines the motor type.
Definition: 32b/motor.h:82
static float_t CTRL_getMaxVsMag_V(CTRL_Handle handle)
Gets the maximum stator voltage magnitude value.
Definition: float/ctrl.h:161
float_t maxVsMag_V
the maximum stator voltage magnitude value, V
float_t currentCtrlPeriod_sec
the period at which the current controller runs, sec
CTRL_ErrorCode_e CTRL_getErrorCode(CTRL_Handle handle)
Gets the error code from the controller (CTRL) object.
Definition: 32b/ctrl.h:172
static float_t CTRL_getCtrlFreq_Hz(CTRL_Handle handle)
Gets the controller execution frequency.
Definition: float/ctrl.h:258
_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
PI_Handle piHandle_Id
the handle for the Id PI controller
static void CTRL_getIdq_offset_A(CTRL_Handle handle, MATH_vec2 *pIdq_offset_A)
Gets the direct/quadrature offset current (Idq_offset) vector values from the controller.
Definition: float/ctrl.h:470
float_t Rs_d_Ohm
Defines the direct stator resistance, Ohm.
Definition: float/motor.h:94
static void CTRL_setVdq_offset_V(CTRL_Handle handle, const MATH_vec2 *pVdq_offset_V)
Sets the direct/quadrature offset voltage (Vdq_offset) vector values in the controller.
Definition: float/ctrl.h:1868
_iq Ki_Id
the desired Ki_Id value
Definition: 32b/ctrl_obj.h:235
float_t Ui_spd_A
the start integrator value for the speed controller, A
float_t Ki_spd_ApHz
the desired Ki_spd value, A/Hz
Defines a two element vector.
Definition: 32b/math.h:248
static void CTRL_setIq_A(CTRL_Handle handle, const float_t Iq_A)
Sets the quadrature current (Iq) value in the controller.
Definition: float/ctrl.h:1487
static void CTRL_setCtrlFreq_Hz(CTRL_Handle handle, const float_t ctrlFreq_Hz)
Sets the controller frequency.
Definition: float/ctrl.h:1263
static float_t CTRL_getVd_sf(CTRL_Handle handle)
Gets the direct voltage scale factor.
Definition: float/ctrl.h:150
float_t Vd_sf
the Vd scale factor
float_t Ui_Id_V
the start integrator value for the Id controller, V
static float_t CTRL_getBWc_rps(CTRL_Handle handle)
Gets the current controller bandwidth.
Definition: float/ctrl.h:117
static void CTRL_setId_A(CTRL_Handle handle, const float_t Id_A)
Sets the direct current (Id) value in the controller.
Definition: float/ctrl.h:1406
static float_t CTRL_getBWdelta(CTRL_Handle handle)
Gets the bandwidth scale factor used to maximize phase margin.
Definition: float/ctrl.h:128
void CTRL_incrCounter_current(CTRL_Handle handle)
Increments the current counter.
Definition: 32b/ctrl.h:949
float_t Kctrl_Wb_p_kgm2
the controller constant, Wb/(kg*m^2)
static _iq PI_getRefValue(PI_Handle handle)
Gets the reference value in the PI controller.
Definition: 32b/pi.h:198
void CTRL_getWaitTimes(CTRL_Handle handle, int_least32_t *pWaitTimes)
Gets the wait times from the controller.
Definition: float/ctrl.c:71
bool CTRL_isError(CTRL_Handle handle)
Determines if there is a controller error.
Definition: 32b/ctrl.h:1053
float_t CTRL_getCtrlPeriod_sec(CTRL_Handle handle)
Gets the controller execution period.
Definition: 32b/ctrl.h:161
bool flag_resetInt_Id
a flag to reset the Id integrator
static void PI_setUi(PI_Handle handle, const _iq Ui)
Sets the integrator start value in the PI controller.
Definition: 32b/pi.h:348
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
static void CTRL_setBWdelta(CTRL_Handle handle, const float_t BWdelta)
Sets the bandwidth scale factor used to maximize phase margin.
Definition: float/ctrl.h:1250
Defines the structures for the CTRL object.
the controller idle state
Definition: ctrl_states.h:36
CTRL_ErrorCode_e
Enumeration for the error codes.
Definition: 32b/ctrl_obj.h:98
static void CTRL_getIdq_ref_A(CTRL_Handle handle, MATH_vec2 *pIdq_ref_A)
Gets the direct/quadrature reference current (Idq_ref) vector values from the controller.
Definition: float/ctrl.h:495
float_t ctrlPeriod_sec
Defines the controller period, sec.
Definition: 32b/ctrl_obj.h:209
static void CTRL_setSpeed_outMax_A(CTRL_Handle handle, const float_t speed_outMax_A)
Sets the maximum output value for the speed controller.
Definition: float/ctrl.h:1739
Defines the controller (CTRL) object.
Definition: 32b/ctrl_obj.h:144
Defines a structure for the user parameters.
static float_t CTRL_getSpeedCtrlPeriod_sec(CTRL_Handle handle)
Gets the speed controller period.
Definition: float/ctrl.h:804
bool flag_resetInt_spd
a flag to reset the speed integrator
static float_t * CTRL_getVd_V_addr(CTRL_Handle handle)
Gets the direct voltage (Vd) value memory address from the controller.
Definition: float/ctrl.h:867
static void CTRL_setup(CTRL_Handle handle, const float_t speed_ref_Hz, const float_t speed_fb_Hz, const MATH_vec2 *pIdq_A, const MATH_vec2 *pIdq_offset_A, const MATH_vec2 *pVdq_offset_V, const bool flag_enableSpeedCtrl, const bool flag_enableCurrentCtrl, const bool flag_useZeroIq_ref)
Sets up the user controller (CTRL) object.
Definition: float/ctrl.h:1913
PI_Handle piHandle_Iq
the handle for the Iq PI controller
static void CTRL_getGains(CTRL_Handle handle, const CTRL_Type_e ctrlType, float_t *pKp, float_t *pKi)
Gets the gain values for the specified controller.
Definition: float/ctrl.h:650
static void CTRL_setBWc_rps(CTRL_Handle handle, const float_t BWc_rps)
Sets the current controller bandwidth.
Definition: float/ctrl.h:1237
static float_t CTRL_getIq_ref_A(CTRL_Handle handle)
Gets the quadrature reference current (Iq_ref) value from the controller.
Definition: float/ctrl.h:564
static void CTRL_run(CTRL_Handle handle, MATH_vec2 *pVdq_V)
Run the controller.
Definition: float/ctrl.h:2001
static void CTRL_setSpeed_ref_Hz(CTRL_Handle handle, const float_t speed_ref_Hz)
Sets the output speed reference value in the controller.
Definition: float/ctrl.h:1765
float_t Rs_q_Ohm
Defines the quadrature stator resistance, Ohm.
Definition: float/motor.h:95
CTRL_TargetProc_e
Enumeration for the target processors.
Definition: 32b/ctrl_obj.h:109
static void CTRL_setIdq_ref_A(CTRL_Handle handle, const MATH_vec2 *pIdq_ref_A)
Sets the direct/quadrature current (Idq) reference vector values in the controller.
Definition: float/ctrl.h:1473
void CTRL_setFlag_enableSpeedCtrl(CTRL_Handle handle, const bool state)
Sets the enable speed control value in the estimator.
Definition: 32b/ctrl.h:1284
static MATH_vec2 * CTRL_getIdq_ref_A_addr(CTRL_Handle handle)
Gets the direct/quadrature reference current (Idq_ref) vector memory address from the controller...
Definition: float/ctrl.h:509
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 MATH_vec2 * CTRL_getIdq_offset_A_addr(CTRL_Handle handle)
Gets the direct/quadrature offset current (Idq_offset) vector memory address from the controller...
Definition: float/ctrl.h:484
void CTRL_reset(CTRL_Handle handle)
Resets the controller.
Definition: float/ctrl.c:130
static void PI_setKp(PI_Handle handle, const _iq Kp)
Sets the proportional gain in the PI controller.
Definition: 32b/pi.h:281
static void CTRL_computeOutputLimits_Iq(CTRL_Handle handle, const float_t Vd_out_V, float_t *outMin, float_t *outMax)
Computes the Iq controller output limits.
Definition: float/ctrl.h:192
bool flag_resetInt_Iq
a flag to reset the Iq integrator
static void PI_setKi(PI_Handle handle, const _iq Ki)
Sets the integral gain in the PI controller.
Definition: 32b/pi.h:268
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_setId_offset_A(CTRL_Handle handle, const float_t Id_offset_A)
Sets the direct current (Id) offset value in the controller.
Definition: float/ctrl.h:1419
bool flag_enableCurrentCtrl
a flag to enable the current controllers
Definition: 32b/ctrl_obj.h:277
static void CTRL_setSpeed_fb_Hz(CTRL_Handle handle, const float_t speed_fb_Hz)
Sets the feedback speed value in the controller.
Definition: float/ctrl.h:1713
static void CTRL_setUi(CTRL_Handle handle, const CTRL_Type_e ctrlType, const float_t Ui)
Sets the integrator (Ui) value in the specified controller.
Definition: float/ctrl.h:1805
static void CTRL_setId_ref_A(CTRL_Handle handle, const float_t Id_ref_A)
Sets the direct current (Id) reference value in the controller.
Definition: float/ctrl.h:1432
static bool CTRL_isIdle(CTRL_Handle handle)
Determines if the controller is in the idle state.
Definition: float/ctrl.h:1150
void CTRL_setState(CTRL_Handle handle, const CTRL_State_e state)
Sets the controller state.
Definition: 32b/ctrl.h:1774
static float_t * CTRL_getIq_offset_A_addr(CTRL_Handle handle)
Gets the quadrature offset current (Iq_offset) memory address from the controller.
Definition: float/ctrl.h:553
float_t speed_out_A
the output value from the speed controller, A
static MATH_vec2 * CTRL_getVdq_V_addr(CTRL_Handle handle)
Gets the direct/quadrature voltage (Vdq) vector memory address from the controller.
Definition: float/ctrl.h:914
static MATH_vec2 * CTRL_getIdq_A_addr(CTRL_Handle handle)
Gets the direct/quadrature current (Idq) vector memory address from the controller.
Definition: float/ctrl.h:459
CTRL_Handle CTRL_init(void *pMemory, const size_t numBytes)
Initializes the controller.
Definition: float/ctrl.c:85
static float_t CTRL_getVq_offset_V(CTRL_Handle handle)
Gets the quadrature offset voltage (Vq_offset) value from the controller.
Definition: float/ctrl.h:978
static void CTRL_setFlag_resetInt_Id(CTRL_Handle handle, const bool state)
Sets the reset Id integrator flag value in the controller.
Definition: float/ctrl.h:1354
uint_least16_t numPolePairs
Defines the number of pole pairs.
Definition: 32b/motor.h:84
static void CTRL_setIdq_offset_A(CTRL_Handle handle, const MATH_vec2 *pIdq_offset_A)
Sets the direct/quadrature current (Idq) offset vector values in the controller.
Definition: float/ctrl.h:1459
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 bool CTRL_getFlag_useZeroIq_ref(CTRL_Handle handle)
Gets the use zero Iq reference flag value from the controller.
Definition: float/ctrl.h:368
PI Iq controller.
CTRL_State_e state
the current state of the controller
Definition: 32b/ctrl_obj.h:148
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 value[2]
Definition: 32b/math.h:251
static void CTRL_setMotorParams(CTRL_Handle handle, const MOTOR_Type_e motorType, const uint_least16_t numPolePairs, const float_t ratedFlux_Wb, const float_t Ls_d_H, const float_t Ls_q_H, const float_t Rs_d_Ohm, const float_t Rs_q_Ohm, const float_t Rr_d_Ohm, const float_t Rr_q_Ohm)
Sets the parameters for the motor in the controller.
Definition: float/ctrl.h:1635
static void CTRL_setFlag_enable(CTRL_Handle handle, const bool state)
Sets the enable controller flag value in the controller.
Definition: float/ctrl.h:1315
static void CTRL_setKi(CTRL_Handle handle, const CTRL_Type_e ctrlType, const float_t Ki)
Sets the integral gain (Ki) value for the specified controller.
Definition: float/ctrl.h:1540
void CTRL_incrCounter_state(CTRL_Handle handle)
Increments the state counter.
Definition: 32b/ctrl.h:1003
static float_t CTRL_getKctrl_Wb_p_kgm2(CTRL_Handle handle)
Gets the speed controller constant.
Definition: float/ctrl.h:139
static float_t CTRL_getSpeed_ref_Hz(CTRL_Handle handle)
Gets the output speed reference value from the controller.
Definition: float/ctrl.h:793
CTRL_State_e prevState
the previous state of the controller
Definition: 32b/ctrl_obj.h:150
float_t Kp_Id_VpA
the desired Kp_Id value, V/A
CTRL_State_e CTRL_getState(CTRL_Handle handle)
Gets the controller state.
Definition: 32b/ctrl.h:767
float_t BWdelta
the bandwidth scaling to maximize phase margin
static void CTRL_setSpeed_out_A(CTRL_Handle handle, const float_t speed_out_A)
Sets the maximum output value for the speed controller.
Definition: float/ctrl.h:1726
static void CTRL_setNumCtrlTicksPerCurrentTick(CTRL_Handle handle, const int_least16_t numCtrlTicksPerCurrentTick)
Sets the number of controller clock ticks per current controller clock tick.
Definition: float/ctrl.h:1665
void CTRL_setCtrlPeriod_sec(CTRL_Handle handle, const float_t ctrlPeriod_sec)
Sets the controller execution period.
Definition: 32b/ctrl.h:1176
float_t ratedFlux_Wb
Defines the rated flux, Wb.
Definition: float/motor.h:97
MATH_vec2 Vdq_offset_V
the Vdq offset values, V
uint_least16_t counter_current
the isr counter
Definition: 32b/ctrl_obj.h:255
static float_t * CTRL_getVd_offset_V_addr(CTRL_Handle handle)
Gets the direct offset voltage (Vd_offset) value memory address from the controller.
Definition: float/ctrl.h:889
static void CTRL_setFlag_resetInt_Iq(CTRL_Handle handle, const bool state)
Sets the reset Iq integrator flag value in the controller.
Definition: float/ctrl.h:1367
uint_least32_t waitTimes[CTRL_numStates]
an array of wait times for each state, estimator clock counts
Definition: 32b/ctrl_obj.h:191
_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
static void CTRL_setFlag_useZeroIq_ref(CTRL_Handle handle, const bool state)
Sets the use zero Iq reference flag value in the controller.
Definition: float/ctrl.h:1393
static float_t CTRL_getVd_V(CTRL_Handle handle)
Gets the direct voltage (Vd) value from the controller.
Definition: float/ctrl.h:856
CTRL_State_e
Enumeration for the controller states.
Definition: ctrl_states.h:34
static bool CTRL_isEnabled(CTRL_Handle handle)
Determines if the controller is enabled.
Definition: float/ctrl.h:1120
static float_t CTRL_getSpeed_out_A(CTRL_Handle handle)
Gets the output value from the speed controller.
Definition: float/ctrl.h:749
static bool CTRL_getFlag_resetInt_spd(CTRL_Handle handle)
Gets the reset speed integrator flag value from the controller.
Definition: float/ctrl.h:357
static float_t CTRL_getSpeed_outMin_A(CTRL_Handle handle)
Gets the minimum value for the speed controller.
Definition: float/ctrl.h:782
float_t speed_outMax_A
the maximum output value for the speed controller, A
static float_t * CTRL_getId_offset_A_addr(CTRL_Handle handle)
Gets the direct offset current (Id_offset) memory address from the controller.
Definition: float/ctrl.h:412
MOTOR_Params motorParams
the motor parameters
Definition: 32b/ctrl_obj.h:189
static float_t CTRL_getVd_offset_V(CTRL_Handle handle)
Gets the direct offset voltage (Vd_offset) value from the controller.
Definition: float/ctrl.h:878
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
float_t Ls_q_H
Defines the quadrature stator inductance, H.
Definition: 32b/motor.h:89
float_t speed_fb_Hz
the feedback speed value, Hz
static float_t CTRL_getIq_A(CTRL_Handle handle)
Gets the quadrature current (Iq) value from the controller.
Definition: float/ctrl.h:520
static bool CTRL_getFlag_enable(CTRL_Handle handle)
Gets the enable controller flag value from the controller.
Definition: float/ctrl.h:302
static bool CTRL_isNotIdle(CTRL_Handle handle)
Determines if the controller is not in the idle state.
Definition: float/ctrl.h:1167
static float_t * CTRL_getId_A_addr(CTRL_Handle handle)
Gets the direct current (Id) memory address from the controller.
Definition: float/ctrl.h:390
bool CTRL_updateState(CTRL_Handle handle)
Updates the controller state.
Definition: 32b/ctrl.c:642
float_t Ui_Iq_V
the start integrator value for the Iq controller, V
CTRL_Type_e
Enumeration for the controller (CTRL) types.
Definition: 32b/ctrl_obj.h:121
static float_t CTRL_getId_A(CTRL_Handle handle)
Gets the direct current (Id) value from the controller.
Definition: float/ctrl.h:379
_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
bool flag_useZeroIq_ref
a flag to force a Iq = 0 reference value
float_t Ls_d_H
Defines the direct stator inductance, H.
Definition: 32b/motor.h:88
static float_t CTRL_getSpeed_outMax_A(CTRL_Handle handle)
Gets the maximum value for the speed controller.
Definition: float/ctrl.h:771
float_t Kp_spd_ApHz
the desired Kp_spd value, A/Hz
static float_t CTRL_getSpeed_fb_Hz(CTRL_Handle handle)
Gets the feedback speed value from the controller.
Definition: float/ctrl.h:738
static void CTRL_setIdq_A(CTRL_Handle handle, const MATH_vec2 *pIdq_A)
Sets the direct/quadrature current (Idq) vector values in the controller.
Definition: float/ctrl.h:1445
float_t speed_ref_Hz
the reference speed value, Hz
uint_least32_t ctrlFreq_Hz
Defines the controller frequency, Hz.
Definition: 32b/ctrl_obj.h:203
static void CTRL_setVdq_V(CTRL_Handle handle, const MATH_vec2 *pVdq_V)
Sets the direct/quadrature voltage (Vdq) vector values in the controller.
Definition: float/ctrl.h:1854
float_t Rr_q_Ohm
Defines the quadrature rotor resistance, Ohm.
Definition: float/motor.h:92
float_t Rr_d_Ohm
Defines the direct rotor resistance, Ohm.
Definition: float/motor.h:91
static void CTRL_setSpeed_outMin_A(CTRL_Handle handle, const float_t speed_outMin_A)
Sets the minimum output value for the speed controller.
Definition: float/ctrl.h:1752
static void CTRL_setFlag_resetInt_spd(CTRL_Handle handle, const bool state)
Sets the reset speed integrator flag value in the controller.
Definition: float/ctrl.h:1380
MATH_vec2 Vdq_V
the Vdq values, V
uint_least16_t CTRL_getCount_speed(CTRL_Handle handle)
Gets the speed loop count.
Definition: 32b/ctrl.h:117
static void CTRL_setNumIsrTicksPerCtrlTick(CTRL_Handle handle, const int_least16_t numIsrTicksPerCtrlTick)
Sets the number of Interrupt Service Routine (ISR) clock ticks per controller clock tick...
Definition: float/ctrl.h:1693
uint_least16_t CTRL_getCount_current(CTRL_Handle handle)
Gets the current loop count.
Definition: 32b/ctrl.h:95
static void PI_setMinMax(PI_Handle handle, const _iq outMin, const _iq outMax)
Sets the minimum and maximum output value allowed in the PI controller.
Definition: 32b/pi.h:295
static bool CTRL_getFlag_resetInt_Iq(CTRL_Handle handle)
Gets the reset Iq integrator flag value from the controller.
Definition: float/ctrl.h:346
void CTRL_resetCounter_speed(CTRL_Handle handle)
Resets the speed counter.
Definition: 32b/ctrl.h:1095
static void CTRL_setCurrentCtrlPeriod_sec(CTRL_Handle handle, const float_t currentCtrlPeriod_sec)
Sets the current controller period value.
Definition: float/ctrl.h:1289
static void CTRL_setGains(CTRL_Handle handle, const CTRL_Type_e ctrlType, const float_t Kp, const float_t Ki)
Sets the gain values for the specified controller.
Definition: float/ctrl.h:1601
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
MATH_vec2 Idq_A
the Idq values, A
static void CTRL_getIdq_A(CTRL_Handle handle, MATH_vec2 *pIdq_A)
Gets the direct/quadrature current vector values from the controller.
Definition: float/ctrl.h:445
float_t BWc_rps
the bandwidth of the current controllers, rad/sec
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
void CTRL_getVersion(CTRL_Handle handle, CTRL_Version *pVersion)
Gets the controller version number.
Definition: float/ctrl.c:58
uint_least16_t numCtrlTicksPerCurrentTick
Defines the number of controller clock ticks per current controller clock tick.
Definition: 32b/ctrl_obj.h:197
static void CTRL_setMaxVsMag_V(CTRL_Handle handle, const float_t maxVsMag_V)
Sets the maximum stator voltage magnitude value.
Definition: float/ctrl.h:1614
Contains the public interface to the Proportional-Integral (PI) controller module routines...
void CTRL_setVersion(CTRL_Handle handle, const CTRL_TargetProc_e targetProc, const uint16_t majorReleaseNumber, const uint16_t minorReleaseNumber)
Sets the controller version.
Definition: float/ctrl.c:296
uint_least32_t CTRL_getCount_state(CTRL_Handle handle)
Gets the state count.
Definition: 32b/ctrl.h:128
static void CTRL_enable(CTRL_Handle handle)
Enables the controller.
Definition: float/ctrl.h:104
static float_t CTRL_getId_offset_A(CTRL_Handle handle)
Gets the direct offset current (Id_offset) value from the controller.
Definition: float/ctrl.h:401
static float_t * CTRL_getVq_V_addr(CTRL_Handle handle)
Gets the quadrature voltage (Vq) value memory address from the controller.
Definition: float/ctrl.h:967
static void CTRL_disable(CTRL_Handle handle)
Disables the controller.
Definition: float/ctrl.h:92
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
Contains the user related definitions.
static float_t * CTRL_getSpeed_out_A_addr(CTRL_Handle handle)
Gets the output value memory address from the speed controller.
Definition: float/ctrl.h:760
static void CTRL_getVdq_V(CTRL_Handle handle, MATH_vec2 *pVdq_V)
Gets the direct/quadrature voltage (Vdq) vector values from the controller.
Definition: float/ctrl.h:900
static float_t * CTRL_getIq_ref_A_addr(CTRL_Handle handle)
Gets the quadrature reference current (Iq_ref) memory address from the controller.
Definition: float/ctrl.h:575
PI_Handle piHandle_spd
the handle for the speed PI controller
static void CTRL_setSpeedCtrlPeriod_sec(CTRL_Handle handle, const float_t speedCtrlPeriod_sec)
Sets the speed controller period value.
Definition: float/ctrl.h:1778
float_t Kp_Iq_VpA
the desired Kp_Iq value, V/A
static float_t * CTRL_getVq_offset_V_addr(CTRL_Handle handle)
Gets the quadrature offset voltage (Vq_offset) value memory address from the controller.
Definition: float/ctrl.h:989
static void CTRL_setVd_sf(CTRL_Handle handle, const float_t Vd_sf)
Sets the direct voltage scale factor.
Definition: float/ctrl.h:1841
static void CTRL_setIq_offset_pu(CTRL_Handle handle, const float_t Iq_offset_A)
Sets the quadrature current (Iq) offset value in the controller.
Definition: float/ctrl.h:1500
bool flag_enableSpeedCtrl
a flag to enable the speed controller
Definition: 32b/ctrl_obj.h:267
static void CTRL_setKctrl_Wb_p_kgm2(CTRL_Handle handle, const float_t Kctrl_Wb_p_kgm2)
Sets the speed controller constant.
Definition: float/ctrl.h:1526
static float_t CTRL_getVq_V(CTRL_Handle handle)
Gets the quadrature voltage (Vq) value from the controller.
Definition: float/ctrl.h:956
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
bool CTRL_getFlag_enableCurrentCtrl(CTRL_Handle handle)
Gets the enable current controllers flag value from the controller.
Definition: 32b/ctrl.h:215
PI Id controller.
static void PI_run_series(PI_Handle handle, const _iq refValue, const _iq fbackValue, const _iq ffwdValue, _iq *pOutValue)
Runs the series form of the PI controller.
Definition: 32b/pi.h:397
float float_t
Defines the portable data type for 32 bit, signed floating-point data.
Definition: types.h:121
static float_t CTRL_getRefValue(CTRL_Handle handle, const CTRL_Type_e ctrlType)
Gets the reference value from the specified controller.
Definition: float/ctrl.h:708
static void CTRL_computeOutputLimits_Id(CTRL_Handle handle, float_t *outMin, float_t *outMax)
Computes the Id controller output limits.
Definition: float/ctrl.h:173
MATH_vec2 Idq_ref_A
the Idq reference values, A
static void CTRL_setKp(CTRL_Handle handle, const CTRL_Type_e ctrlType, const float_t Kp)
Sets the proportional gain (Kp) value for the specified controller.
Definition: float/ctrl.h:1570