Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C Program for PID Controller

1,018 views
Skip to first unread message

Eugenio Acevedo

unread,
Jun 28, 2000, 3:00:00 AM6/28/00
to
Hallo!
I am looking for a C Program that works like a PID Controller for the
microcontroller 80167. It is for educational purpose.
Do you know where could I find information or examples?


Stijn Vanorbeek

unread,
Jun 28, 2000, 3:00:00 AM6/28/00
to
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.

Steve Holle

unread,
Jun 28, 2000, 3:00:00 AM6/28/00
to
On Wed, 28 Jun 2000 07:05:03 GMT, st...@easynet.be (Stijn Vanorbeek)
wrote:
Circuit Cellar Inc. had a series of articles some time ago about
programming a micro to do PID to levitate a steel ball using electro
magnets. check out www.circuitcellar.com

marius

unread,
Jun 29, 2000, 3:00:00 AM6/29/00
to
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>...

Zoran Tomicic

unread,
Jun 29, 2000, 3:00:00 AM6/29/00
to
In article <39594E1C...@iei.tu-clausthal.de>,
ace...@iei.tu-clausthal.de says...

>
>Hallo!
>I am looking for a C Program that works like a PID Controller for the
>microcontroller 80167. It is for educational purpose.
>Do you know where could I find information or examples?
>

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

Stijn Vanorbeek

unread,
Jun 30, 2000, 3:00:00 AM6/30/00
to
You should look for AN531 and AN532 (motor control)

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:
>>

Patrick Smout

unread,
Jun 30, 2000, 3:00:00 AM6/30/00
to
Read the book

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...

0 new messages