CAD CAM EDM DRO - Yahoo Group Archive

PID in a PIC

on 2000-08-10 14:38:32 UTC
Hi to the List,

I have been researching PID algorithms, and would like to implement a
PID formula in a simple project(?) for my son. The Project is a "line
following robot", and what we want to build is a PIC micro controller
running a PID calculation. The input "error" is calculated from levels
from an array of IR sensors. There are to be three pots digitized for
the Kp, Ki & Kd gains. The output of the calculation will be used to
control an R/C servo via PWM. The R/C servo steers the robot (car).

The sensors, pots, and PWM stuff is all fine, but in trying to implement
the PID calculations, I find that I don't know much about it.

A PID in a PIC has other obvious uses in CNC.

I came up with this 'C' code from an "Embedded Systems Programming"
magazine pseudo code example, am I on the right track?

dt = .001; // 1000 loops/sec?

while(1)
{
Sum = OldSum + Error;
Output = (Kp * Error) + (Ki * Sum * dt) + (Kd * (Error -
OldError)/dt);
OldError = Error;
OldSum = Sum;
}

If you have any comments, or a more thorough example, I would appreciate
seeing it(them). I don't normally program Integral or derivative
equations!

Alan

Discussion Thread

Alan Marconett KM6VV 2000-08-10 14:38:32 UTC PID in a PIC Spehro Pefhany 2000-08-10 16:24:18 UTC Re: [CAD_CAM_EDM_DRO] PID in a PIC Tony Jeffree 2000-08-13 13:34:53 UTC Re: [CAD_CAM_EDM_DRO] PID in a PIC Dave Kowalczyk 2000-08-14 06:21:52 UTC Re: PID in a PIC Alan Marconett KM6VV 2000-08-14 11:28:23 UTC Re: PID in a PIC Dave Kowalczyk 2000-08-29 20:06:40 UTC Re: PID in a PIC