piclist 2001\02\21\173533a >
www.piclist.com/techref/microchip/ios.htm?key=motor
BY : Mike Mansheim email (remove spam text)

> error = wanted - actual
> diff = error - old_error
> if (drive not saturated){integral += error}
> old_error = error

> p = kp * error
> i = ki * integral
> d = kd * diff

> drive = (saturated ls bits of) (p+i+d)

> For the applications I have put it too I have generally found the
integral
> term to be of little use... depends on what you are doing of course.

This is an excellent illustration of how simple it is in concept to
implement a pwm control - until you start have to start tweaking
kp, ki, and kd to make your system behave properly!
However:  a "typical" control system must have an integral term.  For
example, if the output is a pwm signal to drive a motor, if you actually
got to the desired speed, error = 0 and your output would also = 0, and
you would stop driving the motor.  The integral builds over time and
creates a "baseline" output that allows the error to go to zero.  The
other terms modify this baseline to react quickly to changes; by it's
nature, the integral reacts slowly to changes.  One of the things that
can complicate the above simple representation is saving/restoring the
integral under certain conditions - if, for instance, your motor
routinely needs to be stopped temporarily, and you don't want the
integral to have to build all the way back up each time.
Note that since ki is multiplied by the integral, it is very often = 1.
Anything larger quickly makes for very large integral terms.
I think it is more typical to have a PI only system - and only use the
derivative term when absolutely necessary.  It is simply a means to let
the control system react to the rate of change of the error, and often
isn't needed.
Finally, going way back to the original post on this, they said that it
can take a while to get a speed reading.  I just wanted to mention that you
must pay attention to how often the pid calculation is done.  You
absolutely do not want to update the output faster than the system can
respond - you will not be in control.  That's not quite the case here -
you just won't know how the system responded - but you still don't want
to update based on old data.  Probably better to figure out how to get
the speed quicker.
Wow, this is much longer than I intended - I got rambling - sorry for the
length.

--