Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PID algorithm for PIC18Fxxxx for Speed Control in C18

Status
Not open for further replies.

wael_sal

New Member
Hi,
Referring to Microchip AN957 PID code list in the example code implemented using dsPIC2010, I try to implement it in semilar way for PIC18F, but I do not get good response, and seems the PID not function coz the duty always set to maximum,
and system goes unstable.
Hope to get some help on implementing PID for PIC micro in C.

Regards
 
What is the system you are controlling? What is your PID loop frequency? What are your P, I and D values? How did you tune the controller? What is your method (sensor) to get feedback?
 
Last edited:
Referring to Microchip AN957 PID code, the speed will be calculated from timer 3 value.
Below is the code from micochip AN.



#define Kps 750 // Kp and Ks terms need to be adjusted as per
#define Kis 20 // the motor and load


/*****************************************************************************
CalculateDC, uses the PI algorithm to calculate the new DutyCycle value which
will get loaded into the PDCx registers.

****************************************************************************/

void CalculateDC(void)
{
ActualSpeed = SPEEDMULT/timer3avg;
DesiredSpeed = DesiredSpeed*POTMULT;
SpeedError = DesiredSpeed - ActualSpeed;
SpeedIntegral += SpeedError;
DutyCycle = (((long)Kps*(long)SpeedError + (long)Kis*(long)SpeedIntegral) >> 16);
PDC1 = PDC1 + DutyCycle;
if (PDC1 < 50)
{PDC1 = 50;SpeedIntegral = 0;}
if (PDC1 > 512)
{PDC1 = 512;SpeedIntegral = 0;}
PDC2 = PDC1;
PDC3 = PDC1;

}
 
Have you tried to tune the PID parameters (Kps and Kis)? Every PID controller needs to be tuned for the specific application. You can "make it work" using trial and error method, but there are better methods also. Is your feedback working i.e. is the speed calculated correctly? How much theoretical background do you have on PID controllers?
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top