I have a PID loop running at 100Hz and is working reasonably well, for now. However, if I double the speed to 200Hz it no longer works, which isn't much of a surprise. The question is, what changes should be made to the PID values to get it to work at 200Hz? Is it a linear change in values? Can it be calculated? What is the relationship between stability and loop speed?

  • 6
    \$\begingroup\$ You need to adjust your I and D coefficients. Obviously I will now integrate faster, therefore the integral term will accumulate faster. On the other hand, the D term will now be smaller, because you differentiate over a shorter delta-t (unless you are already taking it in account). But this is a theory. The best thing is to re-tune it from scratch, because these might be not the only factors. \$\endgroup\$ – Eugene Sh. Dec 4 '20 at 15:27
  • \$\begingroup\$ It could be linear or otherwise mappable/fittable or it could require calibration data for every operating point, can't tell without knowledge of the system being driven, it's not a PID generic thing. \$\endgroup\$ – crasic Dec 4 '20 at 15:40
  • \$\begingroup\$ Please mention the calculations / expressions you use to find the integral and derivative. If the derivative part directly comes from a dedicated rate sensor (say, a tacho generator), then D gain can also be kept same. It would be good if you could add more details of the setup. \$\endgroup\$ – AJN Dec 4 '20 at 17:16
  • \$\begingroup\$ How does the loop time compare to the process time constant? If you sample far too fast, the measurement noise might become bigger than real process changes. \$\endgroup\$ – Dave X Dec 5 '20 at 1:54
  • \$\begingroup\$ Not sure what the process time constant is for a wobbling balance. I have measured it under some circumstances as being 16Hz \$\endgroup\$ – Dirk Bruere Dec 5 '20 at 12:33

When you execute a PID with higher sampling rate you can encounter two things:

  • The integrator may not work properly if the new delta is very tiny. This is due to the final resolution of floating point number. Using a double precision float numbers significantly improves this problem until certain point (sampling frequency).

  • The differentiator increases its output due to the input noise (also quantization noise). The output follows \$\dfrac{d\varepsilon}{dt}\$ so shorter sample time (higher freq.) means higher output for the same step change (quantization). A way to solve this phenomena is to use 1st order low pass filter on the D-part. However large filter times would also make the D-part unresponsive at high dynamics - right the opposite for what the D-Part is used for. Another countermeasure is to use a dead band on D-part input - a small change in the input signal is therefore neglected ( a good way to eliminate quantization noise)

Let we define a PID function as: $$y=K_p \cdot(\varepsilon+\dfrac{1}{T_i}\int\varepsilon dt+ T_d \dfrac{d\varepsilon}{dt})$$

Then discrete form: $$y=K_p\cdot(\varepsilon + \dfrac{\Delta T}{T_i}\Sigma\varepsilon + T_d\dfrac{\Delta\varepsilon}{\Delta T} )$$

Often is written also in this form: $$y=k_p\varepsilon + k_i\Sigma\varepsilon + k_d\Delta\varepsilon$$

If your PID routine uses last form, you should re-calcuate ki,kd at every change of kp or sample time.

  • \$\begingroup\$ More important than the resolution of the floats is that the integrator will accumulate twice as fast. Thus the I-gain needs to be devided by two \$\endgroup\$ – Sim Son Dec 4 '20 at 17:20
  • \$\begingroup\$ @SimSon If \$k_i=K_p\cdot\dfrac{ T_{sample} }{T_i}\$ then with a new sampling time, which is half of the older, the ki also has to be only the half of the older. I hope that this is understandable from the equations I wrote. \$\endgroup\$ – Marko Buršič Dec 4 '20 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.