Tuning PID Controller

How to Tune a PID Controller

Tuning a PID controller can be difficult knowing where to start, and what direction to go. This article will provide solutions to both of these, setting up a PID controller from scratch and more!

To start, read “PID Controller Explained“, to learn what a PID controller is and how it works. And also the PID Simulator page to use a live PID Simulator!

It is good to note early in this post, that there can be many values that work for the same device. The important thing is not to find the “perfect” values, but to find ones that meet the requirements, and provide desired control.

Finding Initial PID Values

First ensure everything is mechanically sound with the device being controlled. More times than not, people will try to”tune” PID values to fix an issue, but the issue is a physical one, not an automation one. Once everything is verified, we can start to program! 

Proportional

Tuning Proportional
Tuning the Proportional Gain

Start by setting the Integral and Derivative values to 0. Then increase the proportional until the controller starts to become unstable and oscillate.

A controller where the oscillations become smaller is considered a “stable” controller, as eventually it will stabilize, and when the oscillations start getting larger is an”unstable” controller.

Once the proportional value that causes the controller to oscillate is found, take this value and divide it in half. This will be the starting P value.

Example: in the picture, the proportional gain that causes the controller to become unstable is 1000, so the starting proportional value will be 500.

Integral

Tuning Integral
Tuning the Integral Gain

Once the proportional value is found, we can start to tune the integral. Always start with small steps when adjusting a PID controller, and give time between each adjustment to see how the controller reacts.

Increase the integral gain in small increments, and with each adjustment, change the set point to see how the controller reacts.

The goal of tuning the integral value, is to achieve an adequate controller response or reaction time (after the initial response from the proportional is set).

If the controller starts to oscillate, or become unstable, adjust the I value in the opposite direction until the controller becomes stable again. Once the controller is stable, and responding desirably… congrats! you now have a  working PI controller.

I will post a video at the bottom of this article that shows these steps inside the automated PID Simulator to provide a practical example for those (like myself) who are more visual learners.

For the hands on learners, download the PID Simulator app from the Microsoft Store to put these steps into practice!

Derivative

Derivative
Tuning the Derivative Gain

There are many PI controllers out there, and for certain applications, this is all that is required. But if your application could benefit from the dampening effects of the derivative, you will need to find the value that works!

Now that you have a stable PI controller, start by increasing the derivative value slowly, changing the set point, and allowing time for the controller to stabilize.

The purpose of the D value, is to monitor the ramp rate of the process value, and prevent it from overshooting the set point.

Continue to change the set point and increase the derivative until the overshoot has been dampened to an acceptable level. If the controller starts to react in a negative way (unexpected changes in the output, poor control, or oscillation) lessen the D value until the controller is stable again.

Be careful when adjusting the derivative value, as a higher value is tempting – everyone wants a smooth controller don’t they? – but too high of a derivative will start to effect the output in a negative way and “fight” what the P and I values are trying to accomplish.

The other concern with a high D value,is if there is noise or distortion of the process value feedback, the derivative may see this as a fast change in the ramp rate, and bias the output at an undesired time.

For more on tuning the derivative check out the video below.

Advanced Tuning of a PID Controller

Once the initial values are found (by following the steps above), you can start to change the set point, and put the controller through some simulations to see how it react.

There is no set formula for advanced tuning of a PID controller, and no step-by-step process that will work in every scenario, but with an understanding of how a PID controller works, and enough practice, it is definitely possible. To practice tuning a PID controller, download the great PID Simulator app from the Microsoft Store!

Watching how the controller reacts, will lead you towards which value (or values) should be changed.

The PID controller is not reacting fast enough:

Watch the initial response of the PID controller output, if the initial response is fast (a steep peak in the output) but the following few seconds seems to be slower reacting, then the integral value will need adjusting. Increase the integral gain until the desired reaction time is reached, but be careful not to go too high and cause oscillations.

If the initial PID controller response (immediate response of the output), try increasing the proportional value. Note, if the proportional gain is increased, put the controller through some tests, to see if the derivative gain will also need increased to prevent the overshooting that may occur.

The PID controller is overshooting:

Look at the initial response of the PID controller, if the initial response is too high, then decreasing the proportional (or possibly the integral) could correct the overshoot. However, if the reaction time is good an the PID controller is stable, then increasing the derivative slightly may be all that is required, to dampen the overshoot.

The PID controller is not stable, or oscillating:

An unstable or oscillating PID controller can be one of the most difficult to address. Before adjusting, double check that there is no external or physical forces causing the issue.

If the oscillations are caused by the output spiking instantly to 100% then down to 0% and back, likely the proportional gain is set too high. Start by decreasing the derivative gain to a low setting (to ensure it is not causing the instability), then decrease the proportional gain until the controller becomes more stable.

If the output is not spiking instantly, but seems to be over and undershooting, then the integral value is likely too high. Decrease the integral gain until the controller becomes stable.

If all else fails, you can re-set the PID values, and set-up the PID controller from the beginning as described above.

Hope this article has helped, check out the video below for a interactive walk through!

Check out this video on How to Tune a PID Controller.
Updated video for 2024!
PID Simulator
To practice PID control loops, download the PID Simulator App from the Microsoft Store!

About the author

A licensed industrial electrician, licensed auto mechanic, and PLC programmer. Passionate about what I do, and love helping people learn!