There is a good aplication note at www.microchip.com explaining how to
program PID motioncontrol in C, that one was helpfull for me to
understand how PID is implemented in C.
Stijn Vanorbeek wrote in message
<3959a30d...@news.easynet.be>...
Here is the simple PID code.
/* pid.h */
typedef struct
{
float Kp; // proportional gain
float Ti; // integral time
float Ts; // sampling period
float Integral; // old integration value
float High; // high limit
float Low; // low limit
float Td; // diff. time
float Tf; // first order filter constant for D component
float DifOld; // old D value
float ErrOld; // old error value
} PI_STRUC;
int PidControl (PI_STRUC* pid, int Error);
/* pid.c */
int PidControl (PI_STRUC* pid, int Error)
{
float e,i,y,d,k;
e = (float) Error;
i = pid -> Integral;
i = i + (pid->Ts * e) / pid->Ti;
if (i > pid->High)
i = pid -> High;
else if (i < pid->Low)
i = pid -> Low;
pid -> Integral = i;
if (pid -> Td)
{
k = pid -> Tf + pid -> Ts;
d = ((e - pid -> ErrOld)*pid -> Td + pid -> Tf * pid -> DifOld) /
(pid -> Tf + pid -> Ts);
if (d > pid -> High)
d = pid -> High;
else if (d < - pid -> High)
d = - pid -> High;
pid -> ErrOld = e;
pid -> DifOld = d;
y = i + pid->Kp*e + d;
}
else
y = i + pid->Kp*e;
if (y > pid->High)
y = pid -> High;
else if (y < pid->Low)
y = pid -> Low;
return (int) y;
}
Regards
Zoran
Microtrol Pty Ltd
www.microtrol.com.au
On Thu, 29 Jun 2000 15:33:30 -0400, "marius" <mari...@bellsouth.net>
wrote:
>What is the exact appnote, I tried a search but there's nothing with
>PID in the title or as keyword.
>
>Stijn Vanorbeek wrote in message
><3959a30d...@news.easynet.be>...
>>What would you like to c ontrol by PID : motion ? Temperature ?
>>
>>There is a good aplication note at www.microchip.com explaining how
>to
>>program PID motioncontrol in C, that one was helpfull for me to
>>understand how PID is implemented in C.
>>
>>On Wed, 28 Jun 2000 03:00:12 +0200, Eugenio Acevedo
>><ace...@iei.tu-clausthal.de> wrote:
>>
PID Controllers: Theory, Design and Tuning
K. Äström and T. Hägglund - ISBN 1-55617-516-7
It reveals the theory behind and the implementation of modern PID control
systems. Coding is much easier once you understand the theory.
The Microchip AN531/AN532 DC motor control application uses a basic
implementation of a PID controller. Despite the fact that it is a fine AN,
it is not a good example for implementing a PID controller in a
microcontroller. There are a lot a of real-world topics that are not covered
by the example.
Best regards,
Patrick Smout
Stijn Vanorbeek <st...@easynet.be> schreef in berichtnieuws
395c3cd...@news.easynet.be...