Learn PLCs free
Programming Guides16 min read3 062 words

PLC PID Tuning Complete Guide: Kp, Ki, Kd for Real Industrial Loops

PID tuning for PLCs from first principles. Ziegler-Nichols, Cohen-Coon, and the practical trial-and-error method that actually ships. With worked examples and common anti-patterns.

IAE
Senior PLC Programmer
15+ years hands-on experience • 50+ automation projects completed
PLC
Programming Excellence

Every industrial automation engineer learns PID the same way: read two paragraphs of theory, stare at a Bode plot for five minutes, then get handed a misbehaving loop at 2 AM during commissioning and told to make the overshoot go away. This guide is for that engineer.

We'll cover what each term actually does in a PLC context, the three tuning methods worth knowing, how to implement anti-windup, and the eight anti-patterns that turn a simple loop into a process-shutdown nightmare. All examples work in TIA Portal's PID_Compact, Studio 5000's PIDE, and pure IEC 61131-3 — and each is runnable in a browser simulator if you want to practise tuning without risking a $500k batch.

Table of Contents

  1. What PID Actually Does
  2. The Three Terms in Plain English
  3. PID in PLC Function Blocks
  4. Method 1: Trial and Error (the honest one)
  5. Method 2: Ziegler-Nichols
  6. Method 3: Cohen-Coon
  7. Anti-Windup: the Thing Everyone Forgets
  8. Common Tuning Anti-Patterns
  9. Process-Specific Guidelines
  10. From Simulation to Real Hardware

What PID Actually Does

A PID controller takes the error — the difference between the setpoint (what you want) and the process variable (what you're measuring) — and uses it to compute the manipulated variable (what the PLC tells the valve, the drive, or the heater to do).

PID controller block diagram Setpoint subtracts process variable to produce error, which feeds three parallel terms — proportional, integral, derivative — that sum to the controller output. Output drives the process, whose measured value feeds back as the process variable. SP setpoint error Kp · error Proportional Ki · ∫error·dt Integral Kd · d(error)/dt Derivative Σ output Process PV (process variable)
The PID block: setpoint minus process variable equals error. Three terms run in parallel; their sum is the controller output. Output drives the process; the process variable feeds back to close the loop.

In plain arithmetic:

output = Kp * error + Ki * ∫error·dt + Kd * d(error)/dt

That's it. Three terms summed together. Kp scales the current error, Ki integrates the history of the error, Kd looks at how quickly the error is changing. Everything else — tuning methods, anti-windup, cascade loops — is elaborations on those three terms.

The Three Terms in Plain English

Proportional (Kp) answers "how big is the error right now?" If the temperature is 10 °C below setpoint and Kp is 2, the proportional contribution is 20 units of heater output. Double Kp, double the response. Kp alone will get you close to setpoint quickly but leaves a persistent offset (steady-state error).

Integral (Ki) answers "how long have we been off?" If you're 1 °C below setpoint for 60 seconds, the integral accumulates 60 °C-seconds of error and ramps the output up until the offset vanishes. Integral is what eliminates steady-state error; too much integral causes overshoot and oscillation.

Derivative (Kd) answers "how fast is the error changing?" It brakes aggressive moves. If the temperature is climbing fast toward setpoint, derivative subtracts from the output before the process overshoots. Derivative is useful on slow, well-behaved processes (temperature, level) and dangerous on noisy ones (flow, pressure) — it amplifies measurement noise and will make your actuator chatter.

The ugly truth: most industrial loops run PI only, with Kd set to zero. PI handles 80 % of real loops. Add D only when you know the process is slow and the measurement is clean.

PID in PLC Function Blocks

Every major PLC platform ships a tuned PID function block. The semantics differ slightly — know your platform.

Siemens TIA Portal — PID_Compact (S7-1200/1500):

  • Gain (Gain) is what most of the world calls Kp.
  • Integral time (Ti) is expressed in seconds — period, not gain. Larger Ti → less integral action. Ki equivalent = Gain / Ti.
  • Derivative time (Td) also in seconds. Kd equivalent = Gain × Td.
  • Built-in auto-tuning via the State parameter. Commissioning-mode tuning is good for most loops; fine-tune manually after.

Rockwell Studio 5000 — PIDE (ControlLogix):

  • Proportional gain (PGain), integral gain (IGain), derivative gain (DGain). Gains, not times — so units align with the math above.
  • Autotune built in via AutotuneFB. Runs a step test and computes initial gains.
  • Set ManualMode to 1 when commissioning; bump ControlVariable manually while watching the response, then tune.

Pure IEC 61131-3 (Codesys, Beckhoff TwinCAT, OpenPLC):

  • Function block naming varies by library — PID, FB_CTRL_PID, PID_FB. Check your library.
  • All expose some combination of Kp, Ki/Ti, Kd/Td plus output limits and anti-windup.

Regardless of block, the work is the same: set reasonable limits, disable Kd initially, tune Kp until overshoot is acceptable, add Ki slowly until steady-state error closes.

Method 1: Trial and Error (the honest one)

This is how 80 % of loops are actually tuned in the field.

PID step-response curves: under-damped, critically-damped, over-damped, oscillating Four time-domain step responses of a temperature loop. Under-damped overshoots and rings; critically-damped reaches setpoint fastest without overshoot; over-damped reaches setpoint slowly; oscillating fails to settle. 100% 0% t=0 time → PV SP Under-damped (Kp too high) Critically damped Over-damped (Kp too low) Oscillating (Ki too high)
Four step-response shapes you'll see while tuning. Critically-damped (green) is the goal: fastest rise without overshoot. Under-damped (red) and oscillating (purple) are signs to back off Kp or Ki.
It is also the method that most consistently ships working code.
  1. Set Kp to a small value, Ki and Kd to zero. Start conservative. For a temperature loop, Kp = 1 is a fine starting point.
  2. Bump the setpoint by 10 % of operating range. Watch the process variable.
  3. If the response is too slow, double Kp. Bump again.
  4. Keep doubling Kp until you see oscillation — the process variable starts overshooting and swinging around setpoint.
  5. Back Kp off to about half that value. This is your working proportional gain.
  6. Add Ki = Kp / (process time constant) as a starting point. For a temperature process with a 60-second time constant, start with Ki = Kp / 60.
  7. Observe. Steady-state error should close within about three time constants. If it closes too slowly, increase Ki. If the response develops a new oscillation around setpoint, decrease Ki.
  8. Add Kd only if overshoot remains excessive and the measurement is clean. Start Kd = Kp / 10 × time constant. Increase cautiously. If the output chatters, Kd is too high or the measurement is too noisy — back off.

The total exercise takes 30 minutes on a well-behaved loop, longer on a slow process like a 5,000-litre reactor that takes 20 minutes to respond to any input. Budget accordingly.

Method 2: Ziegler-Nichols

The textbook method. Reasonable starting point for processes you don't know well.

Ultimate gain method:

  1. Set Ki and Kd to zero.
  2. Increase Kp until the process oscillates with sustained, non-decaying oscillations at the setpoint. Call this gain Ku (ultimate gain).
  3. Measure the period of oscillation. Call it Pu.
  4. Apply the Ziegler-Nichols gains:
Controller Kp Ki Kd
P only 0.5 × Ku
PI 0.45 × Ku 1.2 × Kp / Pu
PID 0.6 × Ku 2 × Kp / Pu Kp × Pu / 8

Ziegler-Nichols was derived for fast-responding processes in the 1940s. It typically produces aggressive tuning with significant overshoot — often 25 % overshoot on a step response. That's fine for a lab demo, problematic in production where overshoot on a temperature loop might trip a high-temperature alarm or scorch a product batch.

Treat Z-N as a starting point. After applying the numbers, back Kp off by 20–30 % and reduce Ki similarly for anything where overshoot matters.

Method 3: Cohen-Coon

Better than Ziegler-Nichols for processes with significant dead time — think long pipes, large tanks, slow heat transfer.

  1. Put the loop in manual mode.
  2. Step the output by ~10 % and record the response.
  3. From the response curve, measure:
    • Dead time (L) — time between step and first process variable movement.
    • Time constant (T) — time from first movement to 63 % of the final value.
    • Process gain (K) — (final PV change) / (output step).
  4. Apply Cohen-Coon gains:
Controller Kp Ki Kd
PI (T / (K·L)) × (0.9 + L/(12T)) Kp × (L × (30 + 3L/T)) / (9 + 20L/T)
PID (T / (K·L)) × (4/3 + L/(4T)) Kp × (L × (32 + 6L/T)) / (13 + 8L/T) Kp × (4L / (11 + 2L/T))

Cohen-Coon works better than Z-N on processes where dead time is more than 10 % of the total response time. On fast, responsive loops (flow, pressure) it offers no advantage and is harder to apply than trial and error.

Anti-Windup: the Thing Everyone Forgets

Integral windup is the single most common PID failure mode in industrial code. Here's how it happens:

  1. The process is stuck — maybe a valve is fully open but the flow won't reach setpoint because upstream pressure is low.
  2. The integral term keeps accumulating error because the error won't go away.
  3. The internal integrator grows to enormous values — far beyond what the actuator can physically deliver.
  4. Conditions change, the process starts moving, the output should come down — but the accumulated integral is so large the PID output stays saturated for minutes.
  5. Operators watch the process overshoot catastrophically while the loop "unwinds" its integrator.

Fixes:

1. Clamp the integrator directly. When the output hits its upper or lower limit, freeze the integrator. Siemens PID_Compact and Studio 5000 PIDE both do this automatically — but only if you set the output limits correctly in the function block.

2. Back-calculation anti-windup. More sophisticated — the integrator is driven back by the difference between the commanded output and the saturated output. Better for fast processes; overkill for most plants.

3. Conditional integration. Integrator runs only when the output is not saturated. Simple and effective; almost all commercial PID blocks support it as an option.

Always set your output limits (OutMax, OutMin) to physically achievable values. Don't leave them at ±100 % if the actuator range is 0–100. Anti-windup cannot protect you if the limits are wrong.

Common Tuning Anti-Patterns

Seen too many times to count:

  1. Copying tuning gains between loops. "This loop tunes at Kp=2.5, let me try that on the next one." Gains are dimensional — they depend on engineering-unit scaling, actuator range, and process dynamics. Never copy; always re-tune.
  2. Turning off integral to "stabilise" a loop. A persistent oscillation is not fixed by removing integral. It means Kp is too high or the process has changed. Removing integral just gives you steady-state error plus the oscillation.
  3. Using derivative on flow. Flow measurements are inherently noisy. Derivative amplifies noise and makes valves chatter, wearing out actuators in months. Kd = 0 on flow, always.
  4. Manual mode forever. A loop in manual mode for six months is not a loop. Commission properly or accept that the operator is the control system.
  5. Tuning at the wrong operating point. A valve with a linear characteristic at 50 % open has a non-linear characteristic at 90 % open. Tune at your normal operating range, not on a bench.
  6. Cascade loops that aren't synchronised. Outer loop update rate should be slower than inner loop settling time — typically outer is 3–5× slower. Otherwise the outer loop confuses the inner loop and both oscillate.
  7. Letting the PID drive outside physical limits. A PID output of 110 % means nothing to a valve that opens to 100. Clamp at the function block; don't rely on downstream logic.
  8. Forgetting to disable PID during startup. Many processes need a specific startup sequence (pre-heat, pre-fill, flush) before PID control takes over. Starting PID from zero setpoint on a cold process often produces a wild first response. Use bumpless transfer from manual to auto.

Process-Specific Guidelines

Rough starting points when you're staring at an unfamiliar loop:

Process type Typical Kp Typical Ti (sec) Typical Td Notes
Flow 0.1–1 0.5–5 0 Noisy; PI only; fast response
Pressure (gas) 0.5–3 5–30 0 PI usually enough
Pressure (liquid) 1–5 10–60 0 Often PI with slow Ki
Temperature (fast) 1–5 30–300 0–30 PID often justified
Temperature (slow, large vessel) 2–10 300–1800 60–300 PID with long times
Level (linear tank) 1–3 60–600 0 PI; avoid Kd
Level (conical tank) 0.5–2 300–1800 0 Non-linear — consider gain scheduling
pH 0.1–1 60–600 0 Non-linear near setpoint; requires care

These are order-of-magnitude starting points, not recipes. Every real process deviates. Budget tuning time accordingly.

From Simulation to Real Hardware

Tuning in a simulator is safe, fast, and (critically) consequence-free. Real hardware is none of those. Three things change when you move from sim to plant:

  1. Process noise. Real signals have noise. Your simulator's clean temperature reading becomes a 0.2 °C jitter on a real thermocouple, and your clean Kd = 1 becomes actuator chatter on real hardware.
  2. Actuator dynamics. A simulated valve that moves instantly from 0 % to 100 % is a real valve with 5 seconds of stroke time and 2 seconds of backlash. Tuning that worked in sim often looks sluggish on real hardware.
  3. Coupled loops. Plants have cross-coupling. Changing the flow setpoint moves pressure, which moves the level in the downstream tank, which moves the next flow. Tune loops in the order they cascade: innermost first, each time putting the outer loop in manual while you work.

Use a simulator to develop the intuition — what does higher Kp feel like, what does too-fast Ki look like. Use real commissioning time to close the gap between sim and plant.

Key Takeaways

  • PI covers 80 % of real loops. Default Kd to zero until you're sure the process is slow and the measurement is clean.
  • Trial and error is a legitimate, widely-used tuning method. Don't be embarrassed to use it.
  • Ziegler-Nichols is aggressive; back its suggested gains off by 20–30 % for production work.
  • Anti-windup is non-negotiable. Every PID function block needs correct output limits and windup protection enabled.
  • Know your function block: PID_Compact (Siemens), PIDE (Rockwell), or the IEC equivalent in Codesys/TwinCAT.
  • Tune at the real operating point with real process dynamics, not on a bench or at startup.

Once theory lands, tune a loop yourself in the browser — the feedback from changing Kp and watching the curve respond is worth more than ten blog posts.

#PIDTuning#PLCProgramming#PIDControl#ClosedLoop Control#ProcessControl#KpKi Kd
Share this article:

Related Articles