Question about PID controller in CY8CKIT-037

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
user_3159566
Level 1
Level 1
First like given

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);

}

0 Likes
1 Solution
JobinT_31
Employee
Employee
50 solutions authored 25 solutions authored 10 solutions authored

Hello Manuel,

In PID, Integration represent the accumulation of the errors [multiplied to a constant] over time.

  1. /* Calculate output of intergration */     
  2.     result = (int32 )(speedErr * ki); //PROPORTIONAL???         
  3.     piOut += result;

Here you can see the piOut += result; accumulating all the errors. piOut will have the sum of all the errors.

  1. /* Calculate output of proportional */         
  2.     speedErr2 = (speedErr-speedErrPrev); //DERIVATIVE??? 
  3.     speedErrPrev = speedErr; 
  4.      
  5.     result = (int32)(speedErr2 * kp); 
  6.     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

View solution in original post

2 Replies
JobinT_31
Employee
Employee
50 solutions authored 25 solutions authored 10 solutions authored

Hello Manuel,

In PID, Integration represent the accumulation of the errors [multiplied to a constant] over time.

  1. /* Calculate output of intergration */     
  2.     result = (int32 )(speedErr * ki); //PROPORTIONAL???         
  3.     piOut += result;

Here you can see the piOut += result; accumulating all the errors. piOut will have the sum of all the errors.

  1. /* Calculate output of proportional */         
  2.     speedErr2 = (speedErr-speedErrPrev); //DERIVATIVE??? 
  3.     speedErrPrev = speedErr; 
  4.      
  5.     result = (int32)(speedErr2 * kp); 
  6.     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

Hello Jobi,

Thank you for your answer. Everything is clear now.

Manu.

0 Likes