Hi,
About the sampling rate. The motor and whatever is attached to it has a certain mechanical time constant. If you apply a voltage to it it it takes a certain amount of time for it to "respond". If you sample a lot slower than this time constant you won't be able to get good control.
I'll take a shot at an example:
If we are controlling the temperature in our swimming pool (which probably have a very large time constant) perhaps we should read the actual temperature and calculate a new "drive-value" for the heater once every hour or even slower than that. But if we're controlling the position of the mirror in a laser-scanner we may need to read the actual position and calculate a new "drive-value" tens of thousands of times per second.
Whatever the rate is (once a day or once every uS) it needs to be constant because the final output is based on the error itself (P) the magnitude and amount of time the error has been present (I) and the rate of change of the error (D).
It all depends on how "stiff" you want the control-loop to be. You may get away with a sampling rate of 1s if you can live with very a slow response. If you need to "instantly" respond to the change in load you need to sample much much faster than that.
There was a really good article available on the web called PID without a PhD explaining this a lot better than I can but I can't seem to find it. If you look around a bit you may be able to find it.
EDIT: Here it is.
HTH
/Henrik Olsson
Bookmarks