Skip to content
PLCampus
All examples

14Level 5

Analog level control (introduction to PID)

A proportional valve opens more or less depending on how far the level is from 60 %. It is the P part of a PID, and shows its limitation: the steady-state error.

The simulator is designed for computers (screens 1024 px or wider).

Virtual plant

QW0 · Valve0 %Setpoint 60 %20 %IW0

Level: 20 %. Valve: 0 %

Shown at rest. In the simulator the plant moves according to your program's outputs.

Inputs and outputs

AddressNameDescription
I0.0CONTROLAutomatic control switch
IW0LEVEL_TRANSMITTERLevel transmitter: 0–27648 = 0–100 % (plant)
QW0VALVEInlet valve opening: 0–27648 = 0–100 %
MD0LEVELLevel in % (REAL)
MD1ERRORSetpoint (60 %) minus level
MD2OPENINGCalculated valve opening in % (REAL)

Program

Ladder diagram (LD)

  1. Rung 1 — Scales the transmitter to level percent.

    SCALE→ LEVELLEVEL_TRANSMI…
  2. Rung 2 — Error = setpoint (60 %) − level.

    SUB→ ERROR60.0 − LEVEL
  3. Rung 3 — Proportional action: opening = Kp × error, with Kp = 8.

    MUL→ OPENINGERROR × 8.0
  4. Rung 4 — Upper limit: at most 100 %.

    >OPENING100.0MOVE→ OPENING100.0
  5. Rung 5 — Lower limit: at least 0 %.

    <OPENING0.0MOVE→ OPENING0.0
  6. Rung 6 — With control on, the opening goes to the valve (0–100 % → 0–27648).

    CONTROLI0.0SCALE→ VALVEOPENING
  7. Rung 7 — With control off, the valve closes.

    CONTROLI0.0MOVE→ VALVE0

Step by step

  1. 1Press ▶ Run (F5) and turn on CONTROL. Rung 1: the level is scaled to percent. Rung 2: ERROR = 60 % − LEVEL.
  2. 2Rung 3: the opening is proportional to the error (gain Kp = 8). Rungs 4 and 5: it is limited between 0 and 100 %. Rung 6: it is scaled to the analog output QW0.
  3. 3Watch the level: it settles near 55 %, not at 60 %. With proportional-only control some error is needed to keep the valve open: that is the steady-state error. The I (integral) part of a PID exists to remove it.
  4. 4Try changing the gain to 20.0: the steady-state error drops, but the valve reacts more strongly. Turn off the consumer in the plant and see how the balance point changes.