Skip to content
PROCESIAby Aterra Ingeniería

LEARN · PROCESS CONTROL

PID level control

What each part of a PID does, how a loop is tuned and why a badly tuned one oscillates. Move the simulator while you read.

The problem: holding a level

The TK-101 tank receives water from the P-101 pump, which has a variable frequency drive. The plant draws water through the FCV-102 valve, and that demand changes: sometimes the valve is 30 % open, sometimes 65 %. The LT-101 transmitter measures the level from 0 to 3 m.

We want the level to stay at 1.8 m (the setpoint, SP) no matter what happens with demand. To do that, the LIC-101 level controller compares the setpoint with the measurement (PV) and adjusts the pump speed. Since the pump changes the level and the level goes back to the controller, it is called a closed loop.

u = Kc·e + (Kc/Ti)·∫e dt + Kc·Td·de/dt  ·  e = SP − PV
The closed loop
Setpoint SP 1.80 m Σ + − error e +0.00 m PID controller P0.0 % I0.0 % D0.0 % sum, limited to 0–100 % output u 0 % Pump + drive P-101 TK-101 Measurement PV · LT-101 1.80 m
TK-101 tank
P-101 0 % SP 0 m1 m 3 m FCV-102 30 % LT 1.80 m
Trend · last 4 minutes
Max. deviation in this stage: 0.0 cm · stable
Setpoint SP (m)Level PV, LT-101 (m)Output to P-101 (%, right scale)
PProportional

Looks at the error right now. More gain, stronger reaction. With P alone a permanent error remains.

Kc · e
0.0 %
250
IIntegral

Adds up the error over time and drives it to zero. Short Ti = aggressive integral.

(Kc / Ti) · ∫ e dt
0.0 %
30 s
DDerivative

Looks at how fast the level is changing and brakes early. With noise in the measurement it becomes jumpy.

Kc · Td · de/dt
0.0 %
0 s
Example tunings
FCV-102 demand and setpoint
1.80 m
Simulation
Simulated time: 0:00 · 100 ms sampling

Simplified loop simulator: 1 m² tank, 60 m³/h pump with a 10 %/s ramp and 2.5 s of pipe transport delay, measurement with a 1.5 s filter. PID sampling: 100 ms, as in a PLC cyclic interrupt.

The equation

The error is the difference between what we want and what we measure: e = SP − PV. The PID calculates the output u (the pump speed, from 0 to 100 %) by adding three terms:

u = Kc·e + (Kc/Ti)·∫e dt + Kc·Td·de/dt

Each term looks at the error in a different way. In the simulator you can see how much each one contributes in the colored bars.

P · Proportional: the error right now

It corrects in proportion to the error. If the level is 10 cm below and the gain Kc is 250, the P part asks for 0.10 × 250 = 25 % more pump. More gain, stronger reaction.

The problem: with P alone there is always a permanent error. For the pump to deliver the flow that the demand takes away, some error has to remain to keep it running.

Try it: choose “P only”. The level settles below the setpoint and never reaches it. When the demand goes up, it settles even lower.

I · Integral: the accumulated error

It keeps adding up the error over time. As long as there is error, the I part keeps growing and pushes the output until the error reaches zero. That removes the permanent error of the P part.

The integral time Ti says how fast it acts: a short Ti is an aggressive integral; a long Ti, a slow integral.

Try it: starting from “P only”, tick the integral checkbox. The level rises to the setpoint and stays there.

D · Derivative: the speed of change

It looks at how fast the measurement is changing and brakes before overshooting. It helps in slow processes with a lot of inertia, such as temperature.

On level it is hardly used: the water surface moves and the measurement is noisy. The derivative of a noisy signal jumps all over the place, and the pump becomes jumpy.

Try it: tick the derivative checkbox and turn on “noise on LT-101”. Watch how the output to the pump trembles in the trend. If you turn the noise off, it calms down again.

Tuning: choosing Kc, Ti and Td

Tuning is finding values that correct quickly without overshooting. For a level loop like this one, a PI controller (Td = 0) is usually used. A practical way to adjust it by hand:

  1. Start with a slow integral (long Ti) and a low gain.
  2. Raise Kc until the level responds firmly to a demand change without oscillating.
  3. Lower Ti until the error disappears in a reasonable time. If it starts to oscillate, go back one step.
  4. Try several demand changes, not just one.
What you seeProbable causeWhat to adjust
The level goes up and down non-stop; the pump goes from 0 to 100 %Gain too high or integral too fastLower Kc or raise Ti
The level takes a long time to return to the setpointGain too low or integral too slowRaise Kc or lower Ti
The level stays fixed, but far from the setpointThere is no integral partEnable I
The output trembles even though the level is fineDerivative with a noisy measurementRemove D or filter the measurement

Why does a badly tuned PID oscillate?

The tank does not respond instantly. Between the PLC asking the pump for more speed and the level rising there are delays: the drive's ramp, the time the water takes to travel through the pipe and the measurement filter.

With a very high gain, the PID reacts strongly to a small error. With a very short Ti, the integral charges quickly and keeps pushing when the level has already passed the setpoint. Because of the delays it always arrives late: it overshoots upward, over-corrects downward, and starts again. Since the pump cannot go beyond 0 and 100 %, the oscillation settles into a repeating cycle called a limit cycle.

Try it: choose “Badly tuned” and watch the output to the pump: it swings from one extreme to the other. Then go back to “Well tuned”.

In a real plant, that oscillation means a pump that speeds up and slows down all the time, equipment wear, pipe knocks and alarms that trip on their own.

In a real PLC

  • The PID goes in a cyclic interrupt (for example, every 100 ms), not in the main cycle: it needs a fixed sampling time.
  • Four things are connected: the setpoint, the measurement scaled to engineering units (meters), a reset to hold it still when the plant is out of service, and the output in % to the drive.
  • The ranges are configured: measurement from 0 to 3 m and output from 0 to 100 %.

The complete program for this example for a simulated S7-1500 is in Tutorials, with the variable table and a test guide.

A challenge

Choose “Too slow” (Kc 20, Ti 300 s) and let the demand profile run. How far does the level move from the setpoint at each change? Which Kc and Ti values give you the smallest deviation without the pump oscillating?

Practice it with your own PLC

In Procesia the TK-101 tank has the same loop, connected to your real or simulated PLC. Use the full version free for 7 days, no card.