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
Level: 20 %. Valve: 0 %
Shown at rest. In the simulator the plant moves according to your program's outputs.
Inputs and outputs
| Address | Name | Description |
|---|---|---|
| I0.0 | CONTROL | Automatic control switch |
| IW0 | LEVEL_TRANSMITTER | Level transmitter: 0–27648 = 0–100 % (plant) |
| QW0 | VALVE | Inlet valve opening: 0–27648 = 0–100 % |
| MD0 | LEVEL | Level in % (REAL) |
| MD1 | ERROR | Setpoint (60 %) minus level |
| MD2 | OPENING | Calculated valve opening in % (REAL) |
Program
Ladder diagram (LD)
Rung 1 — Scales the transmitter to level percent.
Rung 2 — Error = setpoint (60 %) − level.
Rung 3 — Proportional action: opening = Kp × error, with Kp = 8.
Rung 4 — Upper limit: at most 100 %.
Rung 5 — Lower limit: at least 0 %.
Rung 6 — With control on, the opening goes to the valve (0–100 % → 0–27648).
Rung 7 — With control off, the valve closes.
Function block diagram (FBD)
Network 1 — Scales the transmitter to level percent.
Network 2 — Error = setpoint (60 %) − level.
Network 3 — Proportional action: opening = Kp × error, with Kp = 8.
Network 4 — Upper limit: at most 100 %.
Network 5 — Lower limit: at least 0 %.
Network 6 — With control on, the opening goes to the valve (0–100 % → 0–27648).
Network 7 — With control off, the valve closes.
Structured text (ST)
(* Analog level control (introduction to PID) — converted from Ladder *)
(* Rung 1: Scales the transmitter to level percent. *)
LEVEL := (TO_REAL(LEVEL_TRANSMITTER) - TO_REAL(0)) * (TO_REAL(100) - TO_REAL(0)) / (TO_REAL(27648) - TO_REAL(0)) + TO_REAL(0);
(* Rung 2: Error = setpoint (60 %) − level. *)
ERROR := 60.0 - LEVEL;
(* Rung 3: Proportional action: opening = Kp × error, with Kp = 8. *)
OPENING := ERROR * 8.0;
(* Rung 4: Upper limit: at most 100 %. *)
IF OPENING > 100.0 THEN OPENING := 100.0; END_IF;
(* Rung 5: Lower limit: at least 0 %. *)
IF OPENING < 0.0 THEN OPENING := 0.0; END_IF;
(* Rung 6: With control on, the opening goes to the valve (0–100 % → 0–27648). *)
IF CONTROL THEN VALVE := (TO_REAL(OPENING) - TO_REAL(0)) * (TO_REAL(27648) - TO_REAL(0)) / (TO_REAL(100) - TO_REAL(0)) + TO_REAL(0); END_IF;
(* Rung 7: With control off, the valve closes. *)
IF NOT CONTROL THEN VALVE := 0; END_IF;Instruction list (IL)
(* Analog level control (introduction to PID) — converted from Ladder *)
(* Rung 1: Scales the transmitter to level percent. *)
LD LEVEL_TRANSMITTER
TO_REAL
SUB( 0
TO_REAL
)
MUL( 100
TO_REAL
SUB( 0
TO_REAL
)
)
DIV( 27648
TO_REAL
SUB( 0
TO_REAL
)
)
ADD( 0
TO_REAL
)
ST LEVEL
(* Rung 2: Error = setpoint (60 %) − level. *)
LD 60.0
SUB LEVEL
ST ERROR
(* Rung 3: Proportional action: opening = Kp × error, with Kp = 8. *)
LD ERROR
MUL 8.0
ST OPENING
(* Rung 4: Upper limit: at most 100 %. *)
LD OPENING
GT 100.0
JMPCN SKIP_4
LD 100.0
ST OPENING
SKIP_4:
(* Rung 5: Lower limit: at least 0 %. *)
LD OPENING
LT 0.0
JMPCN SKIP_5
LD 0.0
ST OPENING
SKIP_5:
(* Rung 6: With control on, the opening goes to the valve (0–100 % → 0–27648). *)
LD CONTROL
JMPCN SKIP_6
LD OPENING
TO_REAL
SUB( 0
TO_REAL
)
MUL( 27648
TO_REAL
SUB( 0
TO_REAL
)
)
DIV( 100
TO_REAL
SUB( 0
TO_REAL
)
)
ADD( 0
TO_REAL
)
ST VALVE
SKIP_6:
(* Rung 7: With control off, the valve closes. *)
LDN CONTROL
JMPCN SKIP_7
LD 0
ST VALVE
SKIP_7:
Step by step
- 1Press ▶ Run (F5) and turn on CONTROL. Rung 1: the level is scaled to percent. Rung 2: ERROR = 60 % − LEVEL.
- 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.
- 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.
- 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.