12Level 4
Two pumps with alternation and backup
Two pumps fill a tank. Each filling cycle uses a different one to share the wear, and if one fails the other takes over and an alarm lights up.
The simulator is designed for computers (screens 1024 px or wider).
Virtual plant
Level: 15 %
Shown at rest. In the simulator the plant moves according to your program's outputs.
Inputs and outputs
| Address | Name | Description |
|---|---|---|
| I0.0 | SYSTEM | System switch |
| I0.2 | LEVEL_LOW | Low level switch: 1 when covered (plant) |
| I0.3 | LEVEL_HIGH | High level switch: 1 when covered (plant) |
| I0.4 | PUMP1_OK | Pump 1 NC fault contact: 0 = fault (plant) |
| I0.5 | PUMP2_OK | Pump 2 NC fault contact: 0 = fault (plant) |
| Q0.0 | PUMP_1 | Pump 1 contactor |
| Q0.1 | PUMP_2 | Pump 2 contactor |
| Q0.2 | ALARM | Fault alarm light |
| M0.0 | DEMAND | The tank needs water (between the two switches) |
| M0.1 | TURN_P2 | Pump 2's turn in this cycle |
| M0.2 | SWITCH_TO_P2 | Pulse: turn goes to pump 2 |
| M0.3 | SWITCH_TO_P1 | Pulse: turn goes to pump 1 |
Program
Ladder diagram (LD)
Rung 1 — Water demand with hysteresis between the low and high switches.
Rung 2 — New cycle and it was pump 1's turn: it goes to pump 2.
Rung 3 — New cycle and it was pump 2's turn: it goes to pump 1.
Rung 4 — Turn switches to pump 2.
Rung 5 — Turn switches to pump 1.
Rung 6 — Pump 1: in its turn, or as backup if pump 2 fails.
Rung 7 — Pump 2: in its turn, or as backup if pump 1 fails.
Rung 8 — Alarm on any fault.
Function block diagram (FBD)
Network 1 — Water demand with hysteresis between the low and high switches.
Network 2 — New cycle and it was pump 1's turn: it goes to pump 2.
Network 3 — New cycle and it was pump 2's turn: it goes to pump 1.
Network 4 — Turn switches to pump 2.
Network 5 — Turn switches to pump 1.
Network 6 — Pump 1: in its turn, or as backup if pump 2 fails.
Network 7 — Pump 2: in its turn, or as backup if pump 1 fails.
Network 8 — Alarm on any fault.
Structured text (ST)
(* Two pumps with alternation and backup — converted from Ladder *)
VAR
R_TRIG_1 : R_TRIG;
R_TRIG_2 : R_TRIG;
END_VAR
(* Rung 1: Water demand with hysteresis between the low and high switches. *)
DEMAND := (SYSTEM AND NOT LEVEL_LOW OR SYSTEM AND DEMAND) AND NOT LEVEL_HIGH;
(* Rung 2: New cycle and it was pump 1's turn: it goes to pump 2. *)
R_TRIG_1(CLK := DEMAND);
SWITCH_TO_P2 := R_TRIG_1.Q AND NOT TURN_P2;
(* Rung 3: New cycle and it was pump 2's turn: it goes to pump 1. *)
R_TRIG_2(CLK := DEMAND);
SWITCH_TO_P1 := R_TRIG_2.Q AND TURN_P2;
(* Rung 4: Turn switches to pump 2. *)
IF SWITCH_TO_P2 THEN TURN_P2 := TRUE; END_IF;
(* Rung 5: Turn switches to pump 1. *)
IF SWITCH_TO_P1 THEN TURN_P2 := FALSE; END_IF;
(* Rung 6: Pump 1: in its turn, or as backup if pump 2 fails. *)
PUMP_1 := DEMAND AND PUMP1_OK AND NOT TURN_P2 OR DEMAND AND PUMP1_OK AND NOT PUMP2_OK;
(* Rung 7: Pump 2: in its turn, or as backup if pump 1 fails. *)
PUMP_2 := DEMAND AND PUMP2_OK AND TURN_P2 OR DEMAND AND PUMP2_OK AND NOT PUMP1_OK;
(* Rung 8: Alarm on any fault. *)
ALARM := NOT PUMP1_OK OR NOT PUMP2_OK;Instruction list (IL)
(* Two pumps with alternation and backup — converted from Ladder *)
VAR
R_TRIG_1 : R_TRIG;
R_TRIG_2 : R_TRIG;
END_VAR
(* Rung 1: Water demand with hysteresis between the low and high switches. *)
LD SYSTEM
ANDN LEVEL_LOW
OR( SYSTEM
AND DEMAND
)
ANDN LEVEL_HIGH
ST DEMAND
(* Rung 2: New cycle and it was pump 1's turn: it goes to pump 2. *)
CAL R_TRIG_1(CLK := DEMAND)
LD R_TRIG_1.Q
ANDN TURN_P2
ST SWITCH_TO_P2
(* Rung 3: New cycle and it was pump 2's turn: it goes to pump 1. *)
CAL R_TRIG_2(CLK := DEMAND)
LD R_TRIG_2.Q
AND TURN_P2
ST SWITCH_TO_P1
(* Rung 4: Turn switches to pump 2. *)
LD SWITCH_TO_P2
S TURN_P2
(* Rung 5: Turn switches to pump 1. *)
LD SWITCH_TO_P1
R TURN_P2
(* Rung 6: Pump 1: in its turn, or as backup if pump 2 fails. *)
LD DEMAND
AND PUMP1_OK
ANDN TURN_P2
OR( DEMAND
AND PUMP1_OK
ANDN PUMP2_OK
)
ST PUMP_1
(* Rung 7: Pump 2: in its turn, or as backup if pump 1 fails. *)
LD DEMAND
AND PUMP2_OK
AND TURN_P2
OR( DEMAND
AND PUMP2_OK
ANDN PUMP1_OK
)
ST PUMP_2
(* Rung 8: Alarm on any fault. *)
LDN PUMP1_OK
ORN PUMP2_OK
ST ALARM
Step by step
- 1Press ▶ Run (F5) and turn on SYSTEM. DEMAND turns on at low level and stays on until high level, as in the tank example.
- 2Rungs 2 to 5: on each rising edge of DEMAND, TURN_P2 changes value. That way each filling is done by a different pump; see each pump's running time in the plant.
- 3Rungs 6 and 7: each pump runs in its turn, or in the other's turn if the other one has a fault. In the plant, press “Fault” on a pump and watch the other one back it up.
- 4Rung 8: any fault turns on the ALARM. Faults are read with the equipment's NC contacts: a broken wire also shows up as a fault.