Spehro Pefhany 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. > Note that the control output goes DOWN as the PV goes UP. > > y = P * (SP-PV) + K > > Suggest you get this working first. Will do. > Why not just set MIN_PWM to 32 ? The maximum should also be set so it allows > you the measurement time you need. Good point... MAX_PWM is already set to allow about 700us measurement time (the 650us delay, plus 50us processing time). If I remember correctly, that is -- I've just done a reinstall on the PC (prompted by a hardware upgrade) and MPLAB isn't installed yet. Thanks, -- Phil. piclist@philpem.me.uk http://www.philpem.me.uk/ -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist