How to Tune PID in PLC: Step-by-Step Guide
To tune a
PID controller in a PLC, start by setting the proportional (P), integral (I), and derivative (D) gains to zero, then gradually increase P until the output oscillates, adjust I to eliminate steady-state error, and finally add D to reduce overshoot. Use the PLC's PID instruction syntax to input these values and test the response.Syntax
The basic PID instruction in a PLC typically requires these parameters:
PV(Process Variable): The current measured value.SP(Set Point): The target value you want to reach.P(Proportional Gain): Controls reaction to current error.I(Integral Gain): Controls reaction based on accumulated error.D(Derivative Gain): Controls reaction based on rate of error change.MV(Manipulated Variable): The output controlling the process.
Example syntax in many PLCs:
plc
PID(PV, SP, P, I, D, MV)
Example
This example shows tuning a PID loop in a PLC program where the set point is 100, and the process variable is read from an input. We start with P=2.0, I=0.5, D=0.1.
plc
VAR PV : REAL; // Process Variable SP : REAL := 100.0; // Set Point P : REAL := 2.0; // Proportional gain I : REAL := 0.5; // Integral gain D : REAL := 0.1; // Derivative gain MV : REAL; // Manipulated Variable (output) END_VAR // Call PID function block MV := PID(PV, SP, P, I, D, MV);
Output
MV value changes to control the process towards SP = 100
Common Pitfalls
- Setting gains too high: Causes oscillations or instability.
- Ignoring integral windup: Integral term accumulates too much error causing overshoot.
- Not tuning derivative: Can lead to slow response or overshoot.
- Skipping stepwise tuning: Adjust
Pfirst, thenI, thenDfor best results.
Example of wrong tuning:
plc
// Wrong: High P gain causes oscillation P := 10.0; I := 0.0; D := 0.0; // Right: Start low and increase gradually P := 2.0; I := 0.5; D := 0.1;
Quick Reference
| Step | Action | Purpose |
|---|---|---|
| 1 | Set P, I, D to zero | Start with no control action |
| 2 | Increase P until output oscillates | Find proportional gain limit |
| 3 | Add I to remove steady error | Eliminate offset from set point |
| 4 | Add D to reduce overshoot | Smooth response and reduce oscillations |
| 5 | Test and fine-tune | Ensure stable and accurate control |
Key Takeaways
Tune PID gains step-by-step: P first, then I, then D for best control.
Start with low gains to avoid oscillations and instability.
Integral gain removes steady-state error but watch for windup.
Derivative gain helps reduce overshoot and smooth response.
Always test changes in a controlled environment before applying.