Application Scenario: A single-lane work-zone section is controlled by two photoelectric beam locations, A (entry) and B (exit), spaced apart to form a detection zone. Traffic is one car at a time. When a vehicle travels in the forward direction (passes A first, then B), the LED Board turns ON the moment the car passes A, stays ON while the car is in the zone, and remains ON for an additional 10 seconds after the car passes B, then turns OFF. A vehicle travelling in the reverse direction (passes B first, then A) does NOT activate the LED Board.
Table of Contents
- System Overview
- System Requirements Specification (SRS)
- System Design Diagrams
- Hardware Layout and Sensor Design
- I/O List
- Direction Detection Principle (A-then-B vs B-then-A)
- State Machine Design
- Ladder Diagram (LD, IEC 61131-3)
- Structured Text (ST, IEC 61131-3)
- Sequential Function Chart (SFC, IEC 61131-3)
- Timing Diagrams
- Safety Design and Failure Modes
- Test Cases
1. System Overview
1.1 Physical Scene
════════════════════════════════════════════════════════════════════════
──▶ LANE TWO (traffic flow →) ◆ LED Board
─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─(LED 板)─ ─ ─ ─
◀── LANE TWO (traffic flow ←) ◀──
════════════════════════════════════════════════════════════════════════
◆A ◆B
┌────────╫──────────────────────────────────────────────╫────────┐
│ ║ ──▶ traffic direction (one car at a time) ║ │
│ U-turn ║ ◀── ║ │
│ zone? ║ Detection Zone (LANE ONE) ║ │
└────────╫──────────────────────────────────────────────╫────────┘
◆A ◆B
(TX / RX) (TX / RX)
Entry beam Exit beam
Forward (A → B): LED Board ON when passing A; hold 10 s after passing B.
Reverse (B → A): LED Board stays OFF.
⚠ Concern: sensor group A may be affected by U-turning vehicles
near the entry side → see §7.5 mitigation.
1.2 Control Objective
| Condition | LED Board | Description |
|---|---|---|
| Vehicle passes A first (forward entry) | ON | Turns on immediately at A |
| Vehicle inside the zone (between A and B, forward) | ON | Zone occupied |
| Vehicle has just passed B (forward exit) | ON for 10 more seconds | Hold timer — safety buffer |
| 10 s hold expired after passing B | OFF | Zone clear |
| Vehicle passes B first, then A (reverse) | No action (stays OFF) | Reverse traffic does not activate the board |
| System fault / communication loss | ON (fail-safe) | Default deny — avoid hazard |
1.3 Key Design Rules (per supervisor's plan)
- Two beam locations only:
A(TX/RX pair, entry) andB(TX/RX pair, exit). The "4 photoelectric sensors" are the 2 emitters + 2 receivers of these two beams. - One car at a time — the lane geometry limits traffic to single-file passage, so a single direction-aware state machine suffices (no multi-vehicle counter).
- Direction is decided by which beam is broken first: - A before B → forward (rightward) → activate LED. - B before A → reverse (leftward) → do NOT activate LED.
- Requirement 1: car passes A → LED ON; after car passes B → LED stays ON for 10 s (configurable
T_HOLD), then OFF. - Requirement 2: car passes B then A → LED does not display.
- U-turn consideration: sensor group A may be tripped by a U-turning vehicle that never reaches B. A transit timeout (
T_TRANSIT_MAX) prevents the LED from being stuck ON in this case (see §7.5). - Fail-Safe: on sensor wire break or PLC fault, the default is LED = ON.
2. System Requirements Specification (SRS)
2.1 Functional Requirements (FR)
- FR-1 The system shall turn the LED Board ON the instant a vehicle breaks beam A as the first event of a passage (A broken while B is clear).
- FR-2 The LED Board shall remain ON while the vehicle is in the zone (from breaking A until it has fully passed B).
- FR-3 After the vehicle has fully passed B, the LED Board shall remain ON for an additional 10 seconds (configurable
T_HOLD, default 10 s) and then turn OFF. - FR-4 A vehicle that breaks beam B as the first event (i.e. travelling reverse, B then A) shall not activate the LED Board.
- FR-5 The system shall determine direction from the order of beam events:
- A-first-then-B → forward passage.
- B-first-then-A → reverse passage (ignored for LED activation).
- FR-6 If a forward passage starts (A broken) but B is not reached within
T_TRANSIT_MAX(default 60 s), the system shall assume the vehicle left or U-turned and shall clear the LED (return to idle) to prevent a stuck-ON condition. - FR-7 If a new forward vehicle breaks A during the 10 s hold, the hold shall be cancelled and the LED shall stay ON for the new passage.
- FR-8 If any photoelectric beam remains continuously broken for longer than
T_SENSOR_FAULT(default 5 min), the system shall enterS_FAULTand outputFAULT_LAMP = ON, LED = ON. - FR-9 A manual RESET pushbutton shall force the system back to idle (LED OFF) for maintenance.
2.2 Non-Functional Requirements (NFR)
- NFR-1 PLC scan cycle ≤ 20 ms.
- NFR-2 Photoelectric beam response time ≤ 2 ms (recommended: Omron E3Z-T or Keyence PR-G series).
- NFR-3 Fail-safe: on beam power loss (cable break) → LED = ON (PNP NO output + wire-break detection).
- NFR-4 LED Board service life ≥ 50,000 h (LED matrix type).
2.3 Nomenclature
| Abbreviation | Full name | Description |
|---|---|---|
A |
Beam A (entry, left) | Through-beam pair (TX + RX) at the entry boundary of the zone |
B |
Beam B (exit, right) | Through-beam pair (TX + RX) at the exit boundary of the zone |
LED_BOARD |
— | LED Board output facing LANE TWO traffic |
T_HOLD |
— | Hold time after the vehicle passes B (default 10 s) |
T_TRANSIT_MAX |
— | Max expected A→B transit time; U-turn / lost-vehicle timeout (default 60 s) |
3. System Design Diagrams
3.1 Overall System Architecture
┌──────────────────────────────────────────────────────────────────┐
│ SUPERVISORY LEVEL │
│ ┌──────────────────┐ ┌────────────────────┐ │
│ │ HMI / SCADA │ ◀───▶ │ Event Logger │ │
│ │ (display state, │ Modbus │ (traffic stats) │ │
│ │ direction) │ TCP │ │ │
│ └─────────┬────────┘ └────────────────────┘ │
│ │ │
└─────────────┼────────────────────────────────────────────────────┘
│
┌─────────────┼────────────────────────────────────────────────────┐
│ │ CONTROLLER LEVEL │
│ ┌─────────▼────────┐ │
│ │ PLC (Master) │ ── Siemens S7-1200 / Mitsubishi FX5U │
│ │ │ scan ≤ 20 ms │
│ │ DI ×2 (A, B) │ │
│ │ DI ×3 (buttons) │ │
│ │ DO ×3 (outputs) │ │
│ └─────────┬────────┘ │
└─────────────┼────────────────────────────────────────────────────┘
│
┌─────────────┼────────────────────────────────────────────────────┐
│ │ FIELD LEVEL │
│ ┌───────────┴───────────────┐ │
│ ▼ ▼ │
│ Beam A (entry) Beam B (exit) ┌──────────────────┐ │
│ ┌────┐ ┌────┐ │ LED Board (◆) │ │
│ │ TX │ ●─ ─ ─ ─ ─ ─ ● │ TX │ ●─ ─ ─ ─ ● │ at LANE TWO │ │
│ │ RX │ │ RX │ │ 220 VAC via SSR │ │
│ └────┘ └────┘ └──────────────────┘ │
│ 24VDC PNP NO 24VDC PNP NO │
└──────────────────────────────────────────────────────────────────┘
3.2 LANE ONE Plan View (Beam A and Beam B)
════════════════════════════════════════════════════════════════
──▶ LANE TWO → ◆ LED Board
─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
◀── LANE TWO ← ◀──
════════════════════════════════════════════════════════════════
Forward traffic ─────────────────────────────────────▶
╔═══════════════════════════════════════════════════════════╗
║ A (TX) ● B (TX) ● ║ ← North post
║ │ │ ║
║ │░░░░░░░░░░░ Detection Zone ░░░░░░░░░░░░░░│ ║
║ │░░░░░░░░░░░ (LANE ONE) ░░░░░░░░░░░░░░│ ║
║ │ one car at a time │ ║
║ A (RX) ● B (RX) ● ║ ← South post
╚═══════════════════════════════════════════════════════════╝
◀───────────── reverse traffic
Beam separation (A↔B) = detection zone length (site-dependent, 30–200 m)
Gate width: 3.0 ~ 3.5 m (full width of LANE ONE)
⚠ U-turn zone is near beam A (entry side) — see §7.5.
3.3 Control Block Diagram
┌──────────────┐ ┌──────────────────────────┐
│ Beam A ────▶│ │ Direction & Sequence │
│ (I0.0) │─────▶│ Detector (Main FSM) │
└──────────────┘ │ │
│ A-first → forward │ ┌────────────┐
┌──────────────┐ │ LED ON, then hold 10s │──────▶│ LED Board │
│ Beam B ────▶│─────▶│ B-first → reverse │ │ (Q0.0) │
│ (I0.1) │ │ LED stays OFF │ └────────────┘
└──────────────┘ │ │ ▲
│ transit timeout (U-turn) │ │
┌──────────────┐ │ → clear LED │ fail-safe ON
│ RESET (I0.2) │─────▶│ │ │
└──────────────┘ │ FAULT → LED ON │ ┌─────┴──────┐
┌──────────────┐ │ │ │ FAULT │
│ FAULT/EMG │─────▶│ │◀──────│ detection │
└──────────────┘ └──────────────────────────┘ └────────────┘
4. Hardware Layout and Sensor Design
4.1 Photoelectric Beam Selection
| Item | Specification |
|---|---|
| Type | Through-beam photoelectric (2 sets: A and B, each = TX + RX) |
| Recommended part | Omron E3Z-T81 / Keyence PR-G51N3 |
| Sensing distance | 0 – 15 m (lane is only 3 m, so plenty of margin) |
| Light source | Infrared LED, modulated, ambient-light immune |
| Response time | ≤ 1 ms |
| Output | PNP NO (normally open), 24 VDC, 100 mA |
| Protection | IP67 |
| Operating temperature | -25 °C to +55 °C |
| Wiring | 3-wire (V+, GND, OUT) + shield |
| Mounting | Stainless-steel posts, TX/RX paired, beam height ≈ 50 cm |
4.2 Posts and Beam Arrangement
Beam A (entry) Beam B (exit)
North post (TX) North post (TX)
┌─────────┐ ┌─────────┐
│ A-TX │ ●─ ─ ─ ─ ─ ─ ─ ─ ─ ─ │ B-TX │ ●─ ─ ─ ─ ─ ─ ─ ─
└─────────┘ beam A └─────────┘ beam B
South post (RX) South post (RX)
┌─────────┐ ┌─────────┐
│ A-RX │ ● │ B-RX │ ●
└─────────┘ └─────────┘
◀────────── A ↔ B separation = zone length ──────────▶
- Beam A sits at the entry boundary, beam B at the exit boundary. Their separation defines the detection zone.
- Direction is obtained from the temporal order of A and B being broken (see §6) — no second beam per location is required.
- Each beam should use a different modulation frequency to avoid cross-talk (use the sensor's Mutual Interference Prevention feature).
4.3 LED Board
| Item | Specification |
|---|---|
| Type | LED matrix board; graphics: red octagon + "STOP" / arrow text |
| Size | 800 × 800 mm (incl. housing) |
| Power | AC 220 V, 30 W |
| Control | Through SSR (Crydom D2425) switched by PLC DO |
| Protection | IP65 |
| Mounting | ≥ 2.5 m above ground, in LANE TWO facing the traffic to be warned |
| Accessory | Current transformer (CT) wired to PLC AI for bulb-fault detection |
4.4 Electrical Connection Overview
+24 VDC
──────────────────────┬─────────────────────────────
│
Beam A ●V+ │
●OUT ──── I0.0 (PLC DI)
●0V ──── 0V
Beam B ●V+
●OUT ──── I0.1
●0V ──── 0V
RESET button (NO) ──── I0.2
MAINTENANCE SW (NO) ── I0.3
PWR_OK ──── I0.4
│
0V
PLC DO ──┤├── SSR ──┤├── L (220 V) ── LED BOARD ── N
Q0.0 Crydom D2425
Note: With PNP wiring, the beam output = 24 V means "beam is broken" (NO logic), which is compatible with the active-high PLC DI input.
5. I/O List
5.1 Digital Inputs (DI)
| Address | Tag | Description | Contact | Note |
|---|---|---|---|---|
| I0.0 | A |
Beam A (entry) broken = 1 | PNP NO | Through-beam |
| I0.1 | B |
Beam B (exit) broken = 1 | PNP NO | Through-beam |
| I0.2 | PB_RESET |
Reset to idle pushbutton | NO | Pressed = 1 |
| I0.3 | SW_MAINT |
Maintenance-mode selector | NO | ON = maintenance |
| I0.4 | PWR_OK |
24 V power-OK feedback | NO | — |
5.2 Digital Outputs (DO)
| Address | Tag | Description |
|---|---|---|
| Q0.0 | LED_BOARD |
LED Board facing LANE TWO (lit = do not proceed) |
| Q0.1 | FAULT_LAMP |
Fault indicator lamp |
| Q0.2 | BUZZER |
Alarm buzzer (sounds on fault) |
5.3 Internal Variables (Memory)
| Address | Tag | Type | Description |
|---|---|---|---|
| M30.0 | A_Rise |
BOOL | Beam A rising edge (just broken) |
| M30.1 | A_Fall |
BOOL | Beam A falling edge (just cleared) |
| M30.2 | B_Rise |
BOOL | Beam B rising edge (just broken) |
| M30.3 | B_Fall |
BOOL | Beam B falling edge (just cleared) |
| MW40 | SysState |
INT | Main FSM state |
| M50.0 | FaultLatch |
BOOL | Fault latch |
| M50.1 | SensorStuck |
BOOL | Beam continuously broken |
| M50.2 | HoldActive |
BOOL | 10 s hold timer is running |
| MD60 | TotalFwdCnt |
DINT | Cumulative forward passages (statistics) |
| MD64 | TotalRevCnt |
DINT | Cumulative reverse passages |
5.4 Modbus Registers (to HMI / SCADA)
| Address | Tag | Type | R/W | Description |
|---|---|---|---|---|
| 10001 | STA_A |
BOOL | R | Current state of beam A |
| 10002 | STA_B |
BOOL | R | Current state of beam B |
| 10010 | STA_LED |
BOOL | R | LED Board state |
| 10011 | STA_FAULT |
BOOL | R | Fault flag |
| 10012 | STA_HOLD |
BOOL | R | Hold timer active |
| 30001 | SYS_STATE |
UINT16 | R | Current FSM state code |
| 30002 | TOTAL_FWD |
UINT32 | R | Cumulative forward passages |
| 30004 | TOTAL_REV |
UINT32 | R | Cumulative reverse passages |
| 30006 | HOLD_REMAIN_MS |
UINT16 | R | Hold timer remaining (ms) |
| 40001 | T_HOLD_CFG |
UINT16 | RW | Hold time (s), default 10 |
| 40002 | T_TRANSIT_CFG |
UINT16 | RW | Transit timeout (s), default 60 |
| 00001 | CMD_RESET |
BOOL | RW | Write 1 = reset to idle |
| 00002 | CMD_ACK_FAULT |
BOOL | RW | Write 1 = acknowledge fault |
6. Direction Detection Principle (A-then-B vs B-then-A)
6.1 Why Two Beam Locations?
A single beam can only tell you "something is there", not which way it is moving. By placing two beams (A and B) at the two ends of the zone, the order in which they are broken reveals the direction of travel:
- A broken first, then B → vehicle moving from entry to exit → forward.
- B broken first, then A → vehicle moving from exit to entry → reverse.
This is exactly what the supervisor's two requirements describe.
6.2 Forward Passage (A → B, LED ON)
Time ──────────────────────────────────────────────────────▶
A : ──██████──────────────────────────────────────────
B : ─────────────────────────────────████████─────────
Sequence: A breaks first → (car transits zone) → B breaks → B clears
Action: LED ON at A ───────────────────────────────────┐
after B clears: hold 10 s ─▶ OFF
6.3 Reverse Passage (B → A, LED OFF)
Time ──────────────────────────────────────────────────────▶
B : ──██████──────────────────────────────────────────
A : ─────────────────────────────────████████─────────
Sequence: B breaks first → (car transits zone) → A breaks → A clears
Action: LED stays OFF (reverse traffic is ignored)
6.4 Summary Table
| First beam broken | Second beam broken | Direction | LED Board action |
|---|---|---|---|
| A | B | Forward | ON at A; hold 10 s after B; then OFF |
| B | A | Reverse | Stays OFF (ignored) |
| A | (B never reached, A clears) | U-turn / lost | ON at A; cleared by T_TRANSIT_MAX timeout |
To reject momentary flickers, beam edges are debounced with a minimum-break filter (T_MIN_BLOCK, e.g. 100 ms) before being treated as a valid event.
7. State Machine Design
Because traffic is one car at a time, a single direction-aware main FSM is sufficient — no multi-vehicle counter is needed.
7.1 Main FSM Overview
[Power-On]
│
▼
┌─────────────┐ POST OK & ¬Fault ┌──────────────┐
│ S_INIT │ ─────────────────────▶│ S_IDLE │◀───────────────┐
│ (self-test)│ │ LED = OFF │ │
│ LED = ON │ └───┬───────┬──┘ │
└─────────────┘ A first (¬B) │ │ B first (¬A) │
▼ ▼ │
┌──────────────┐ ┌──────────────┐ │
│ S_FWD │ │ S_REV │ │
│ LED = ON │ │ LED = OFF │ │
│ (in zone) │ │ (reverse) │ │
└───┬──────┬───┘ └──────┬───────┘ │
B passed │ │ transit │ A cleared │
(B fall) │ │ timeout │ (A fall) │
▼ └────────────┼─────────────┤
┌──────────────┐ │ │
A first │ S_HOLD │ T_HOLD │ │
┌────────────│ LED = ON │─expires──┼─────────────┘
│ │ 10 s timer │ │
│ └──────────────┘ │
▼ │
(back to S_FWD) │
│
* Any state * ── SensorStuck / EMG ──▶ ┌────────────┐ │
│ S_FAULT │ │
│ LED = ON │────┘ (after ACK + restore)
└────────────┘
7.2 State Table
| State | Entry condition | Action | Exit condition |
|---|---|---|---|
S_INIT |
Power-up / reset | Self-test, LED = ON (safe default) | Self-test OK → S_IDLE |
S_IDLE |
No vehicle, hold expired | LED = OFF | A↑ while B clear → S_FWD; B↑ while A clear → S_REV |
S_FWD |
Forward car detected at A | LED = ON | B↓ (car passed B) → S_HOLD; transit timeout → S_IDLE |
S_HOLD |
Car just passed B | LED = ON, start 10 s timer | timer expires → S_IDLE; A↑ (new forward car) → S_FWD |
S_REV |
Reverse car detected at B | LED = OFF | A↓ (car cleared A, exited) → S_IDLE; transit timeout → S_IDLE |
S_FAULT |
Beam stuck / comm. error | LED = ON, FAULT_LAMP = ON, BUZZER = ON | Reset + fault cleared → S_IDLE |
7.3 Requirement 1 Trace (forward A→B with 10 s hold)
S_IDLE ──A↑──▶ S_FWD (LED ON) ──B↑──▶ still S_FWD ──B↓──▶ S_HOLD (LED ON, 10 s) ──timeout──▶ S_IDLE (LED OFF)
7.4 Requirement 2 Trace (reverse B→A, LED off)
S_IDLE ──B↑──▶ S_REV (LED OFF) ──A↑──▶ still S_REV (LED OFF) ──A↓──▶ S_IDLE (LED OFF)
The LED never turns on, because the passage entered through S_REV (B-first), not S_FWD (A-first).
7.5 U-Turn / Lost-Vehicle Mitigation (sensor A concern)
The supervisor noted that sensor group A may be tripped by U-turning vehicles near the entry side. Because the LED turns ON the instant A is broken (FR-1), a U-turning car that breaks A but never reaches B would otherwise leave the LED stuck ON.
Mitigation — a transit timeout in S_FWD:
- When entering
S_FWD, startTransitTimer (PT := T_TRANSIT_MAX, default 60 s). - If B is reached first (
B↓) → normal flow →S_HOLD. - If
TransitTimer.Qfires before B is reached → assume the vehicle U-turned / left → clear LED →S_IDLEand increment a diagnostic counter. - Optionally, also treat "A re-broken and cleared without B" as an immediate back-out (configurable).
This bounds the worst-case false-ON time to T_TRANSIT_MAX.
8. Ladder Diagram (LD, IEC 61131-3)
The LD shown below maps directly to TIA Portal / GX Works3 / Studio 5000. Timers use the IEC standard
TON.
8.1 Symbol Recap
│ │ ┌────┐
──┤├── ──┤/├── │TON │ ┌─┐
NO NC │ │ timer ( ) coil
└────┘ └─┘
──[ MOV in→out ]── ──[ CMP a = b ]──
8.2 LD-01: Edge Detection (A, B)
Rung 1: Beam A rising / falling edge
I0.0 M30.4 M30.0
──┤├──────┤/├──────────────────────────────────( )── A_Rise
A A_LAST
M30.4 I0.0 M30.1
──┤├──────┤/├──────────────────────────────────( )── A_Fall
A_LAST A
I0.0 M30.4
──┤├──────────────────────────────────────────( )── A_LAST
Rung 2: Beam B rising / falling edge
I0.1 M30.5 M30.2
──┤├──────┤/├──────────────────────────────────( )── B_Rise
B B_LAST
M30.5 I0.1 M30.3
──┤├──────┤/├──────────────────────────────────( )── B_Fall
B_LAST B
I0.1 M30.5
──┤├──────────────────────────────────────────( )── B_LAST
8.3 LD-02: Main FSM (state in MW40)
State codes: 0=INIT 1=IDLE 2=FWD 3=HOLD 4=REV 9=FAULT
Rung 10: IDLE → FWD (A first, B clear)
[MW40=1] M30.0 I0.1 MW40
──┤├───────┤├──────┤/├─────────────────[ MOV 2 → MW40 ]──
IS_IDLE A_Rise B
Rung 11: IDLE → REV (B first, A clear)
[MW40=1] M30.2 I0.0 MW40
──┤├───────┤├──────┤/├─────────────────[ MOV 4 → MW40 ]──
IS_IDLE B_Rise A
Rung 12: FWD → HOLD (vehicle passed B)
[MW40=2] M30.3 MW40
──┤├───────┤├──────────────────────────[ MOV 3 → MW40 ]──
IS_FWD B_Fall
Rung 13: FWD transit timeout (U-turn / lost) → IDLE
┌──────────────┐
[MW40=2] ──┤├────────────────────────│ IN Q├──┐
IS_FWD │ TON │ │
│ PT T#60s │ │
└──────────────┘ ▼
[ MOV 1 → MW40 ]──
Rung 14: HOLD timer
[MW40=3] ┌──────────────┐
──┤├─────────────────────────────────│ IN Q├── M50.6
IS_HOLD │ TON │ HoldDone
│ PT T#10s │
└──────────────┘
M50.2 (HoldActive) := IS_HOLD
Rung 15: HOLD → IDLE (timer expired)
M50.6 MW40
──┤├──────────────────────────────────[ MOV 1 → MW40 ]──
HoldDone
Rung 16: HOLD → FWD (new forward car breaks A)
[MW40=3] M30.0 MW40
──┤├───────┤├──────────────────────────[ MOV 2 → MW40 ]──
IS_HOLD A_Rise
Rung 17: REV → IDLE (reverse car cleared A)
[MW40=4] M30.1 MW40
──┤├───────┤├──────────────────────────[ MOV 1 → MW40 ]──
IS_REV A_Fall
8.4 LD-03: LED Board Output
Rung 20: LED_BOARD ON (FWD OR HOLD OR Fault)
[MW40=2] Q0.0
──┤├──────┬───────────────────────────────────( )──
IS_FWD │ LED_BOARD
[MW40=3] │
──┤├──────┤
IS_HOLD │
M50.0 │
──┤├──────┘
FaultLatch
(Note: in S_IDLE and S_REV the LED stays OFF.
On OB100 startup, default Q0.0 = 1 until self-test ends.)
Rung 21: FAULT_LAMP
M50.0 ───┤├──────────────────────────────────( )── Q0.1
Rung 22: BUZZER (1 Hz beep on fault)
M50.0 ───┤├─────┤ M0.5 (1 Hz) ├───────────────( )── Q0.2
8.5 LD-04: Fault Detection
Rung 30: Stuck beam (A or B broken continuously > 5 min)
┌──────────────┐
I0.0 ───┤├──────────────────────▶│ IN Q├──┐
A │ TON T#5m │ │
└──────────────┘ │
┌──────────────┐ ├─▶ M50.1
I0.1 ───┤├──────────────────────▶│ IN Q├──┘ SensorStuck
B │ TON T#5m │
└──────────────┘
Rung 31: Fault latch + enter FAULT state
M50.1 ───┬────────────────────────────────────[S]── M50.0 (FaultLatch)
I0.4=0 │ [ MOV 9 → MW40 ]
PWR_OK 0 │
CMD_ACK_FAULT (Modbus 00002 / RESET)
──┤├───────────────────────────────────[R]── M50.0
── if ¬stuck & PWR_OK: [ MOV 1 → MW40 ]
9. Structured Text (ST, IEC 61131-3)
Structured Text expresses this FSM most clearly. The code below compiles in TIA Portal, Codesys and Beckhoff TwinCAT.
9.1 Type Declarations
TYPE
E_SysState : (
SS_INIT := 0,
SS_IDLE := 1,
SS_FWD := 2, // forward car in zone (A first) — LED ON
SS_HOLD := 3, // car passed B — 10 s hold, LED ON
SS_REV := 4, // reverse car (B first) — LED OFF
SS_FAULT := 9
);
END_TYPE
9.2 Main Program
PROGRAM LaneOne_LedBoard
VAR_INPUT
A : BOOL; // I0.0 beam A (entry)
B : BOOL; // I0.1 beam B (exit)
PB_RESET : BOOL; // I0.2
SW_MAINT : BOOL; // I0.3
PWR_OK : BOOL; // I0.4
CMD_RESET : BOOL; // Modbus coil 00001
CMD_ACK_FAULT : BOOL; // Modbus coil 00002
END_VAR
VAR_OUTPUT
LED_BOARD : BOOL; // Q0.0
FAULT_LAMP : BOOL; // Q0.1
BUZZER : BOOL; // Q0.2
END_VAR
VAR
SysState : E_SysState := SS_INIT;
A_Prev, B_Prev : BOOL;
A_Rise, A_Fall : BOOL;
B_Rise, B_Fall : BOOL;
InitTimer : TON;
HoldTimer : TON;
TransitTimer : TON;
StuckA : TON;
StuckB : TON;
BuzzerClock : TON;
BuzzerPulse : BOOL;
FaultLatch : BOOL := FALSE;
SensorStuck : BOOL := FALSE;
TotalFwdCnt : DINT := 0;
TotalRevCnt : DINT := 0;
LostCnt : DINT := 0; // U-turn / lost-vehicle timeouts
// — Configurable parameters (Modbus holding) —
T_HOLD : TIME := T#10s;
T_TRANSIT_MAX : TIME := T#60s;
C_StuckTime : TIME := T#5m;
END_VAR
9.3 Edge Detection and Fault Aggregation
// === 1. Edge detection ===
A_Rise := A AND NOT A_Prev;
A_Fall := NOT A AND A_Prev;
B_Rise := B AND NOT B_Prev;
B_Fall := NOT B AND B_Prev;
A_Prev := A;
B_Prev := B;
// === 2. Stuck-beam detection ===
StuckA(IN := A, PT := C_StuckTime);
StuckB(IN := B, PT := C_StuckTime);
SensorStuck := StuckA.Q OR StuckB.Q;
IF SensorStuck OR (NOT PWR_OK) THEN
FaultLatch := TRUE;
END_IF;
IF CMD_ACK_FAULT AND NOT SensorStuck AND PWR_OK THEN
FaultLatch := FALSE;
END_IF;
// === 3. Manual reset ===
IF PB_RESET OR CMD_RESET THEN
SysState := SS_IDLE;
END_IF;
9.4 Main FSM
// === 4. Global fault override ===
IF FaultLatch THEN
SysState := SS_FAULT;
END_IF;
CASE SysState OF
SS_INIT:
LED_BOARD := TRUE; // fail-safe default ON
InitTimer(IN := TRUE, PT := T#2s);
IF InitTimer.Q AND NOT FaultLatch THEN
InitTimer(IN := FALSE);
SysState := SS_IDLE;
END_IF;
SS_IDLE:
LED_BOARD := FALSE;
HoldTimer(IN := FALSE);
TransitTimer(IN := FALSE);
// Direction decided by which beam breaks first
IF A_Rise AND NOT B THEN
SysState := SS_FWD; // forward: A first
ELSIF B_Rise AND NOT A THEN
SysState := SS_REV; // reverse: B first
END_IF;
SS_FWD:
LED_BOARD := TRUE; // Req-1: LED ON at A
TransitTimer(IN := TRUE, PT := T_TRANSIT_MAX);
IF B_Fall THEN // vehicle has passed B
TransitTimer(IN := FALSE);
SysState := SS_HOLD;
ELSIF TransitTimer.Q THEN // §7.5 U-turn / lost vehicle
TransitTimer(IN := FALSE);
LostCnt := LostCnt + 1;
SysState := SS_IDLE;
END_IF;
SS_HOLD:
LED_BOARD := TRUE; // Req-1: hold 10 s after B
HoldTimer(IN := TRUE, PT := T_HOLD);
IF A_Rise AND NOT B THEN // new forward car during hold
HoldTimer(IN := FALSE);
SysState := SS_FWD;
ELSIF HoldTimer.Q THEN
HoldTimer(IN := FALSE);
TotalFwdCnt := TotalFwdCnt + 1; // completed forward passage
SysState := SS_IDLE;
END_IF;
SS_REV:
LED_BOARD := FALSE; // Req-2: reverse → LED OFF
TransitTimer(IN := TRUE, PT := T_TRANSIT_MAX);
IF A_Fall THEN // reverse car cleared A → exited
TransitTimer(IN := FALSE);
TotalRevCnt := TotalRevCnt + 1;
SysState := SS_IDLE;
ELSIF TransitTimer.Q THEN
TransitTimer(IN := FALSE);
SysState := SS_IDLE;
END_IF;
SS_FAULT:
LED_BOARD := TRUE; // fail-safe ON
IF NOT FaultLatch THEN
SysState := SS_IDLE;
END_IF;
END_CASE;
// === 5. Annunciators ===
FAULT_LAMP := FaultLatch;
BuzzerClock(IN := NOT BuzzerClock.Q AND FaultLatch, PT := T#500ms);
IF BuzzerClock.Q THEN
BuzzerPulse := NOT BuzzerPulse;
END_IF;
BUZZER := FaultLatch AND BuzzerPulse;
9.5 Modbus Mapping for SCADA / HMI
FUNCTION_BLOCK FB_ModbusMap
VAR_INPUT
SysState : E_SysState;
Led, Fault : BOOL;
HoldActive : BOOL;
HoldRemainMs : UINT;
TotalFwd : DINT;
TotalRev : DINT;
A, B : BOOL;
END_VAR
VAR_OUTPUT
DiscreteIn : ARRAY[0..15] OF BOOL; // 1xxxx
InputReg : ARRAY[0..15] OF UINT; // 3xxxx
END_VAR
DiscreteIn[0] := A;
DiscreteIn[1] := B;
DiscreteIn[9] := Led;
DiscreteIn[10] := Fault;
DiscreteIn[11] := HoldActive;
InputReg[0] := UINT(SysState);
InputReg[1] := UINT(SHR(TotalFwd, 16)); // high word
InputReg[2] := UINT(TotalFwd AND 16#FFFF); // low word
InputReg[3] := UINT(SHR(TotalRev, 16));
InputReg[4] := UINT(TotalRev AND 16#FFFF);
InputReg[5] := HoldRemainMs;
10. Sequential Function Chart (SFC, IEC 61131-3)
SFC (also called a Sequential Function Diagram, IEC 61131-3 / Grafcet) expresses the control sequence as steps (boxes) linked by transitions (horizontal bars with a Boolean condition). Exactly one branch of a selection divergence is taken, based on which transition fires first. This SFC is the supervisor-supplied sequence reference; the executable logic in §7–§9 is the validated implementation of the same behaviour.
10.1 Polarity Convention Used in This SFC
In this SFC the beam variables follow the light-received convention:
| Symbol | Meaning in SFC |
|---|---|
A = 1 / B = 1 |
beam clear (light received, no vehicle) |
A = 0 / B = 0 |
beam blocked (vehicle interrupting the beam) |
This is the logical complement of the raw PNP-NO wiring used elsewhere in this document (where broken = 1). In code, simply map
A := NOT A_broken_DI(or select light-operate sensors), soA = 0here = "vehicle present at A".
10.2 SFC Diagram
┌──────────────────┐
│ 0 Initial │
└────────┬─────────┘
│
───┴─── T1 : A = 1 AND B = 1 (both beams clear)
│
┌────────┴─────────┐
│ 1 Idle │
└────────┬─────────┘
│
───┴─── T2 : A = 0 (vehicle breaks beam A)
│
┌────────┴─────────┐
│ 2 Armed │
└────────┬─────────┘
│
┌──────────┴───────────────────────────────────┐ ← selection divergence
───┴─── T3 : B = 0 ───┴─── T4 : A = 0 for > 600 s
│ (vehicle reaches beam B) │ (beam A stuck blocked)
┌────────┴─────────┐ ┌───────────┴────────┐
│ 3 Warning │ │ 4 Fault │
│ (LED Flash) │ │ (LED Flash Fast) │
└────────┬─────────┘ └───────────┬────────┘
│ │
───┴─── T5 : Output ON ───┴─── T6 : B = 0 for > 600 s
│ │
┌────────┴─────────┐ │
│ 5 Timer Started │ │
│ (t = 10) │──────────(new vehicle)───────────┐ │
└────────┬─────────┘ │ │
│ ▼ ▼
───┴─── T7 : t = 10 expires ┌────────────────────────┐
│ │ 6 New Vehicle detected │
┌────────┴─────────┐ └───────────┬────────────┘
│ 0 (Initial) │ │
└──────────────────┘ (re-arm → return to step 5)
loop back to top
10.3 Step Table
| Step | Name | Action / output |
|---|---|---|
| 0 | Initial | Power-up state; outputs reset, self-test |
| 1 | Idle | Both beams clear, LED OFF, waiting for a vehicle |
| 2 | Armed | Beam A broken — forward candidate detected, waiting for B |
| 3 | Warning (LED Flash) | Vehicle reached beam B — LED Board flashes (warning) |
| 4 | Fault (LED Flash Fast) | Beam A stuck blocked > 600 s — fault, LED flashes fast |
| 5 | Timer Started (t = 40) | Output ON; hold timer running (preset t = 40, see §10.5) |
| 6 | New Vehicle detected | A further vehicle arrived during hold/fault — re-arm sequence |
10.4 Transition Table
| Transition | Condition | From → To |
|---|---|---|
| T1 | A = 1 AND B = 1 (both clear) |
0 → 1 |
| T2 | A = 0 (vehicle breaks A) |
1 → 2 |
| T3 | B = 0 (vehicle reaches B) |
2 → 3 |
| T4 | A = 0 for > 600 s (A stuck) |
2 → 4 |
| T5 | Output ON (LED energised) |
3 → 5 |
| T6 | B = 0 for > 600 s (B stuck) |
4 → 6 |
| T7 | t = 40 expires (hold elapsed) |
5 → 0 |
| — | New vehicle detected (during hold) | 5 → 6 |
10.5 Mapping to the Validated Main FSM (§7)
| SFC step | §7 main FSM state | Notes |
|---|---|---|
| 0 Initial | S_INIT |
self-test, fail-safe LED ON |
| 1 Idle | S_IDLE |
LED OFF |
| 2 Armed | S_FWD (entry) |
A-first confirms forward direction |
| 3 Warning | S_FWD (in zone) |
LED ON/flashing while car transits to B |
| 5 Timer Started | S_HOLD |
hold after passing B |
| 4 Fault | S_FAULT |
stuck-beam fault (> 600 s) |
| 6 New Vehicle | S_FWD (re-entry) |
new car during hold cancels timer |
Timer preset note: the SFC labels the hold timer
t = 40. To realise the 10 s hold required by FR-3, set the timebase so that40 × 250 ms = 10 s(or set the preset directly toT#10sas in the ST code, whereT_HOLD := T#10s). The> 600 sstuck-beam thresholds map to theT_SENSOR_FAULT(5 min) / configurable fault timers — adjust to site preference.Reverse traffic: the SFC arms only on
A = 0first (T2). A reverse vehicle breaks B first, so T2 never fires and the sequence stays in Idle — i.e. the LED never turns on, satisfying Requirement 2.
11. Timing Diagrams
11.1 Requirement 1 — Forward (A → B) with 10 s Hold
Time → 0 2s 8s 40s 42s 52s
A ──██████──────────────────────────────────────────────────────────
B ─────────────────────────────────────────████████──────────────────
Events A_Rise▌ B_Fall▌
State IDLE FWD ────────────────────────────────────── HOLD ──────── IDLE
│◀── 10 s ──▶│
LED OFF ON ──────────────────────────────────────── ON ────────── OFF
11.2 Requirement 2 — Reverse (B → A), LED stays OFF
Time → 0 2s 8s 40s 42s
B ──██████──────────────────────────────────────────────────
A ─────────────────────────────────────────████████─────────
Events B_Rise▌ A_Fall▌
State IDLE REV ────────────────────────────────────── IDLE
LED OFF OFF ───────────────────────────────────────OFF ← never turns on
11.3 U-Turn at A (sensor A concern, §7.5)
Time → 0 2s 10s 62s
A ──██████───────────────── (car U-turns, B never reached)
B ─────────────────────────────────────────────────────────
Events A_Rise▌
State IDLE FWD ─────────────────────────────────── IDLE
TransitTimer (60 s) ───────────────▌ expires
LED OFF ON ─────────────────────────────────────OFF ← cleared by timeout
11.4 New Forward Car During the 10 s Hold
Time → 0 2s 8s 30s 32s 38s 42s
(car1 passes B) (car2 breaks A during hold)
Events A_Rise▌ B_Fall▌ A_Rise▌
State IDLE FWD ───────── HOLD ──────────── FWD ─────── ...
│◀ hold cancelled ▶│
LED OFF ON ────────── ON ───────────────ON ─────── ...
11.5 Stuck Sensor (fault transition)
Time → 0 5 min 5 min + 1
A ──████████████████████████████████── ← broken continuously ≥ 5 min
StuckA.Q ─────────────────────────────▌
FaultLatch ───────────────────────────████████
State ... ──────────────────────────FAULT
LED follows previous ──────────────ON
FAULT_LAMP ───────────────────────────████████
BUZZER ──────────────────────────────╳▌╳▌╳▌╳▌ ← 1 Hz beep
12. Safety Design and Failure Modes
12.1 FMEA (Failure Mode and Effects Analysis)
| Failure | Cause | Effect | Detection | Response |
|---|---|---|---|---|
| Dirty beam lens | Dust, rain | Weak / intermittent trigger | StuckTimer + scheduled cleaning | S_FAULT, LED = ON |
| Beam wire break | Mechanical damage, ageing | Signal stuck at 0 (never triggers) | Wire-break detection (NAMUR) or loop-back test | S_FAULT, LED = ON |
| 24 V power loss | UPS exhausted | Full system loss | PWR_OK signal |
UPS + LED held ON via hard-wired NC contact |
| PLC failure | CPU stop | No control | Watchdog timer | DO defaults OFF; LED uses "lit on failure" wiring (see below) |
| U-turn vehicle trips A | Vehicle reversing near entry | False LED ON | A broken but B never reached | T_TRANSIT_MAX timeout clears LED (§7.5) |
| Slow vehicle crossing | Truck, traffic jam | Transit timeout misfires | Tune T_TRANSIT_MAX to site |
Maintenance mode can extend timeout |
| Two vehicles at once | Violates "one car at a time" | Sequence ambiguity | Geometric single-file enforcement | Narrow lane / barriers; optional counter upgrade |
| Pedestrians / animals | Non-vehicle objects | False trigger | Minimum-break filter (T_MIN_BLOCK, 100 ms) |
Filter out short pulses |
12.2 Fail-Safe Design Principles
- LED Board uses "positive logic stop": lamp on = danger signal, therefore it must remain lit when power is lost. Solution: drive the LED Board via a dual power source or independent battery backup sharing the PLC UPS. If the PLC fails, the SSR drops out through the watchdog and a relay-based lockout takes over:
PLC alive ─┬── (Q0.0) ─── SSR control
│
└── Watchdog OK ──┐
│ NC contact: closes when PLC dies
LED lamp ──── L1 ─── SSR ────┼──── direct L1 through NC contact ──── N
│
Failsafe Relay
- PNP NO beams with wire-break detection: choose sensors with IO-Link or NAMUR signalling to detect cable disconnection.
- Watchdog: the PLC toggles a
WD_BITevery scan; if the external watchdog relay sees no toggle for 200 ms it forces the LED ON. - Battery backup: size the UPS for ≥ 30 min.
12.3 SIL Assessment (Recommended SIL 2)
- Target PFD (Average Probability of Failure on Demand) in the range 1e-3 to 1e-2.
- A second independent direction check (or redundant beams) can raise integrity toward SIL 2.
- For SIL 3, introduce a second independent PLC arranged in a 1oo2D voting architecture.
13. Test Cases
13.1 Unit Tests (simulated inputs)
| TC# | Event sequence | Expected LED | Expected State |
|---|---|---|---|
| TC-01 | Power-up → self-test OK | OFF | S_IDLE |
| TC-02 | Forward: A↑ → A↓ → B↑ (LED on at A) | ON | S_FWD |
| TC-03 | Continue: B↓ (car passed B) | ON (hold) | S_HOLD |
| TC-04 | Wait 10 s after TC-03 | OFF | S_IDLE |
| TC-05 | Reverse: B↑ → A↑ → A↓ (B first) | OFF throughout | S_REV → S_IDLE |
| TC-06 | U-turn: A↑ then A↓, B never reached, wait 60 s | ON then OFF (timeout) | S_FWD → S_IDLE |
| TC-07 | New car: in S_HOLD at t = 5 s, A↑ | ON (hold cancelled) | S_HOLD → S_FWD |
| TC-08 | Press PB_RESET while LED ON | OFF | S_IDLE |
| TC-09 | A broken continuously for 5 min | ON | S_FAULT |
| TC-10 | Press CMD_ACK_FAULT after beam recovers | OFF | S_IDLE |
| TC-11 | Momentary 50 ms flicker on A (< T_MIN_BLOCK) | OFF (filtered) | S_IDLE |
13.2 Integration Tests
| TC# | Scenario | Expected result |
|---|---|---|
| IT-01 | 100 forward vehicles within 1 hour at 20 km/h | TotalFwd = 100, LED correctly ON during each passage + 10 s hold |
| IT-02 | Brief raindrop streak across the lens (< 50 ms jitter) | No state change, with T_MIN_BLOCK = 100 ms filtering |
| IT-03 | Disconnect beam B cable | Transition to S_FAULT within 1 s, LED = ON |
| IT-04 | PLC restart | On power-up LED = ON for ≈ 2 s (INIT), then OFF if idle |
| IT-05 | UPS cutover (mains lost) | LED remains ON for ≥ 30 min |
| IT-06 | 10× reverse vehicles (B→A) | LED never turns on; TotalRev = 10 |
| IT-07 | 5× U-turn vehicles at A (no B) | LED clears within T_TRANSIT_MAX each time; LostCnt = 5 |
13.3 Acceptance Criteria
- Direction accuracy: 100 % correct forward/reverse classification over a 100-vehicle test.
- Response time: from vehicle breaking A to LED turning ON ≤ 200 ms.
- Hold timer accuracy: 10 s ± 0.5 s.
- Availability: MTBF ≥ 1000 h over 30 days of continuous 7×24 operation.
- EMC: compliant with CNS 13438 Class A.
Appendix A: Integration with the Existing 4-Phase Signal System (File 01)
This subsystem can be plugged into 01_PLC_Modbus_SCADA.md as a sub-program:
- Shares the same S7-1200 PLC (only 2 DI + 1 DO are required, well within the existing modules).
- Shares the same SCADA / HMI; LED state and direction counters are exposed via Modbus.
- Add a "LANE ONE Direction Monitor" panel to the SCADA screen showing the FSM state, beam A/B states, forward/reverse totals and hold-timer status.
PROGRAM OB1
BEGIN
TrafficLight_Main(...); // existing intersection controller
LaneOne_LedBoard(...); // new sub-program
END_PROGRAM
Appendix B: Incremental BOM
| Item | Specification | Qty | Note |
|---|---|---|---|
| Through-beam photoelectric beam | Omron E3Z-T81 (TX/RX pair) | 2 pairs | Beam A + Beam B (= 4 sensors: 2 TX + 2 RX) |
| Stainless-steel sensor post | H = 1 m, with base | 4 pcs | A: TX+RX posts, B: TX+RX posts |
| LED display board | 800 × 800 mm, 220 VAC, IP65 | 1 set | In LANE TWO facing traffic |
| SSR | Crydom D2425 (25 A) | 1 pc | For LED Board switching |
| Current transformer (CT) | 5 A : 5 mA | 1 pc | LED Board bulb-fault detection |
| 4–20 mA transmitter | — | 1 pc | CT → AI |
| MCB | 6 A, C-curve | 1 pc | LED Board circuit |
| Fail-safe relay | Omron MY2N 24 VDC | 1 pc | Fail-safe interlock |
| Cable (3C × 0.75 mm² shielded) | — | ≈ 150 m | Site-dependent |
| Waterproof junction box | IP66 | 4 pcs | One per post |
Document version: v3.0 Standards referenced: IEC 61131-3 (LD, ST, FBD), IEC 61508 SIL 2 (recommended), CNS 13438 (EMC)