- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I'm trying to understand the Sensored BLDC Motor Control example project included in Sensored BLDC Motor Control. The PID controller looks like a PD controller to me but everything is explained as a PI controller. Is that ok?
void SpeedPID(void)
{
int16 speedErr;
static int16 speedErrPrev = 0x00;
int16 speedErr2;
int32 result;
uint16 kp,ki;
if(speedRef > MIDDLE_SPEED_CMD) /* Low Speed, Low Coef */
{
kp = UI_Data.kp;
ki = UI_Data.ki;
}
else /* High Speed, High Coef */
{
kp = UI_Data.kp << 1;
ki = UI_Data.ki << 1;
}
speedErr = speedCur - speedRef;
/* Calculate output of intergration */
result = (int32 )(speedErr * ki); //PROPORTIONAL???
piOut += result;
/* Calculate output of proportional */
speedErr2 = (speedErr-speedErrPrev); //DERIVATIVE???
speedErrPrev = speedErr;
result = (int32)(speedErr2 * kp);
piOut += result;
if(piOut>PIOUT_MAX)
piOut= PIOUT_MAX;
if(piOut<PIOUT_MIN)
piOut= PIOUT_MIN;
dutyCycle = piOut>>16;
PWM_Drive_WriteCompare(dutyCycle);
}
Solved! Go to Solution.
- Tags:
- bldc
- cy8ckit-037
- pid
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Manuel,
In PID, Integration represent the accumulation of the errors [multiplied to a constant] over time.
- /* Calculate output of intergration */
- result = (int32 )(speedErr * ki); //PROPORTIONAL???
- piOut += result;
Here you can see the piOut += result; accumulating all the errors. piOut will have the sum of all the errors.
- /* Calculate output of proportional */
- speedErr2 = (speedErr-speedErrPrev); //DERIVATIVE???
- speedErrPrev = speedErr;
- result = (int32)(speedErr2 * kp);
- piOut += result;
Same way here the difference of error is getting accumulated & will get you the proportional term.
[example - taking kp = 1,& ki = 0
T0, speedError =0, speedErr2 = 0 , piout = 0
T1, speedError =2, speedErr2 = [2-0] = 2 , piout = 2+0 = 2
T2, speedError =3, speedErr2 = [3-2] = 1 , piout = 2+1 = 3
T3, speedError =-4,speedErr2 = [-4-3]= -7, piout = 3+ -7 = -4
Now you can see the SpeedError = kp*piout in this example, this is what P have to do in the system. ]
Basically, integrate P, you will get I. Integrate D, you will get P.
Hope this makes sense.
Thanks
Jobin GT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Manuel,
In PID, Integration represent the accumulation of the errors [multiplied to a constant] over time.
- /* Calculate output of intergration */
- result = (int32 )(speedErr * ki); //PROPORTIONAL???
- piOut += result;
Here you can see the piOut += result; accumulating all the errors. piOut will have the sum of all the errors.
- /* Calculate output of proportional */
- speedErr2 = (speedErr-speedErrPrev); //DERIVATIVE???
- speedErrPrev = speedErr;
- result = (int32)(speedErr2 * kp);
- piOut += result;
Same way here the difference of error is getting accumulated & will get you the proportional term.
[example - taking kp = 1,& ki = 0
T0, speedError =0, speedErr2 = 0 , piout = 0
T1, speedError =2, speedErr2 = [2-0] = 2 , piout = 2+0 = 2
T2, speedError =3, speedErr2 = [3-2] = 1 , piout = 2+1 = 3
T3, speedError =-4,speedErr2 = [-4-3]= -7, piout = 3+ -7 = -4
Now you can see the SpeedError = kp*piout in this example, this is what P have to do in the system. ]
Basically, integrate P, you will get I. Integrate D, you will get P.
Hope this makes sense.
Thanks
Jobin GT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Jobi,
Thank you for your answer. Everything is clear now.
Manu.