How often should you compute PID

Hi all,

Is timing required for computing PID position control of DC motors or is it ok to let it compute every loop? Any drawbacks?

If you’re using the usual PID library, it decides for itself when it’s time to calculate. Which means that if you’re calling it too often, it just checks & says, nope, try again later. So calling it every time round loop doesn’t hurt.

It actually helps, because the PID calc there has been optimized and assumes that it will be called every milliseconds, so frequent calling means that it actually does get called (more or less) on time.

If you want to do this right, then you need to first figure out what your "process time constant" is.

In the case of motor speed, that means: how quickly does the shaft speed recover from applying and then suddenly removing a load? You learn this anyway in going through the PID tuning process.

Once you have that time constant, the PID loop should run at least 10 times faster. There are plenty of tutorials on line discussing the design choices, here is one example.