MotorWare f2806x Module API Documentation

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

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