Hi,

Just because the error is zero doesn't mean the output from PID filter is.
Yes, the proportional term will be zero but the integral term won't neccesarily be. It'll be whatever it took to get the error to zero and therefor the output of the pid filter will be equal to the integral term - which you then continously add to your dutycycle untill a negative error develops, at which point the integral term decreases and eventually goes negative. Again the RPM reaches the setpoint but now the pid filter output is negative so it'll keep deceasing the duty cycle untill a positive error develops and the cycle repeats.

The velocity feedforward basically does what you say. It'll provide a "startingpoint" from which the PID then can add or subtract depending on the dynamic response of the system. That startingpoint then varies depending on the setpoint so you can tweak to work pretty well without any PID at all, then the PID handles the "disturbances" and load varioations only. But now you don't have the velocity feedforward in the code any more ;-)

The Pause 10 was just part of the example. Of course the sample time, how often the filter is executed needs to be adapted to the system you're trying to control. 100Hz will be WAY to fast for controlling the temperature in a house while it'll be WAY to slow for controlling the current thru a motorwinding - for example.

But again, I'm not saying you're doing anything wrong. In fact you may very well be doing it right I'm just trying to explain how I understand it. And, most importantly, as long as it works for you whatever is fine by me!

/Henrik.