> error = value - set_value; > p = kp * error; > i += ki * error; > d = kd * (error - last_error); > pid = p + i + d; a couple of (other) common tweaks: the derivative term is sometimes generated from the input, rather than the error. useful if the error term is likely to be noisy, as taking a derivative (= highpass filter) will tend to increase noise. the integral term can be limited to an absolute maximum, in order to combat 'integrator wind-up'; a phenomenon which would otherwise cause big overshoots in slow moving systems. lots of other inventive solutions may be used to acheive the same result. some stuff to remember / realise: the phase (sign) of the constants may be either positive or negative, depending on how the signal is generated. the comments will probably not match the code, they will just give you some hint about what the original programmer was thinking about at the time. the integral & derivative terms may not be calculated prior to summing, but may be inputs to your system (i.e. externally 'calculated') if the code does not in some way add a proportional term, and integral term and a derivative term, then it is not a PID controller. any changes you make to the 'PID' code, will mean the calibration for the system will change. you may even need to change the calibration procedure. a couple of documents I have found useful in the past (first link on each search): http://www.google.com/search?q=pid+without+a+phd http://www.google.com/search?q=motion+control+tutorial+newport hth, simon -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist