Philip Pemberton wrote: >>> I also didn't update cur_pwm correctly -- it seems the P+I+D value is >>> supposed to be added to the output control variable, not used as the >>> control variable. That makes sense, as it's based on the error >>> (delta-V), not the absolute value. >> >> No it doesn't make sense (unless you're trying to use the so-called >> 'velocity (PID) algorithm', which I don't suggest. If you add the error >> to the last control output, you'll always have integration, right? > > Ah. OK. But what about this situation: > > Target = 2V > Input = 2V > Error = 0 > Current P = 123 (example) > P = (Kp * Error) = 0 > > So as soon as it hits the target, it's going to reduce the output to 0. In > other words, it's always going to oscillate. Not really oscillate forever, generally, just a bit (or maybe not at all, or maybe a lot and forever if Kp is too high) until it settles at an value for Error that produces just enough output (P) for the whole thing to be stable. That's the deal with P only: you always have an error, and that's the reason why you may want an I part eventually, probably (depending on your precision requirements). However, that then will introduce additional oscillation tendencies if not adjusted right. A good starting point: http://en.wikipedia.org/wiki/PID_controller Look at Ziegler-Nichols once you get to the point of tuning (that is, once the basics work). Gerhard -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist