09Level 3
Car park with space counter
An up/down counter keeps track of the cars inside. With all 10 spaces taken the FULL sign lights up and the entry barrier no longer opens.
Open in the simulator
The simulator is designed for computers (screens 1024 px or wider).
Virtual plant
Parked: 0 of 10. Waiting: 0
Shown at rest. In the simulator the plant moves according to your program's outputs.
Inputs and outputs
| Address | Name | Description |
|---|---|---|
| I0.0 | ENTRY_SENSOR | Detects a car going in (plant) |
| I0.1 | EXIT_SENSOR | Detects a car going out (plant) |
| I0.2 | CAR_AT_BARRIER | A car is waiting at the entry barrier (plant) |
| Q0.0 | FULL_SIGN | “FULL” sign |
| Q0.1 | BARRIER | Entry barrier |
| C0 | CARS | Cars inside the car park (maximum 10) |
Program
Ladder diagram (LD)
Rung 1 — Counts the cars going in and out. With 10 inside, FULL lights up.
Rung 2 — The barrier opens for the waiting car if there is space.
Function block diagram (FBD)
Network 1 — Counts the cars going in and out. With 10 inside, FULL lights up.
Network 2 — The barrier opens for the waiting car if there is space.
Structured text (ST)
(* Car park with space counter — converted from Ladder *)
VAR
CARS : CTUD;
END_VAR
(* Rung 1: Counts the cars going in and out. With 10 inside, FULL lights up. *)
CARS(CU := ENTRY_SENSOR, CD := EXIT_SENSOR, PV := 10);
FULL_SIGN := CARS.Q;
(* Rung 2: The barrier opens for the waiting car if there is space. *)
BARRIER := CAR_AT_BARRIER AND NOT FULL_SIGN;Instruction list (IL)
(* Car park with space counter — converted from Ladder *) VAR CARS : CTUD; END_VAR (* Rung 1: Counts the cars going in and out. With 10 inside, FULL lights up. *) CAL CARS(CU := ENTRY_SENSOR, CD := EXIT_SENSOR, PV := 10) LD CARS.Q ST FULL_SIGN (* Rung 2: The barrier opens for the waiting car if there is space. *) LD CAR_AT_BARRIER ANDN FULL_SIGN ST BARRIER
Step by step
- 1Press ▶ Run (F5) and, in the plant, press “A car arrives” several times: the barrier opens for each one and the CARS counter adds when it passes the entry sensor.
- 2The CTUD counter counts up with the entry (CU) and down with the exit (CD). Its QU output turns on when the count reaches 10 (PV).
- 3With 10 cars inside, FULL lights up and the NC contact of FULL_SIGN keeps the barrier closed: new cars wait in line.
- 4Press “A car leaves”: the count drops to 9, FULL turns off and the next car in line goes in.