Code Debug
Medium

Find the Bug — Conveyor Deadlock

A conveyor indexing sequence written in Structured Text causes the line to deadlock after 3-4 cycles. The operator has to power-cycle to recover. Find all bugs.

130 XP
📋 Scenario You've been handed this code by a contractor who has left the project. The conveyor runs fine for 3-4 cycles, then freezes — motor stays on, indexing timer never resets. There are 2 bugs. Find both.
🐛 Click the line(s) containing the bug(s). Multiple bugs may exist.
Structured Text — Find the Bug
1 (* Conveyor index sequence *)
2 CASE state OF
3
4 0: (* IDLE *)
5 IF cycle_start THEN
6 state := 1;
7 END_IF;
8
9 1: (* WAIT FOR PART *)
10 IF Part_Sensor OR timeout_flag THEN
11 state := 2;
12 END_IF;
13 timeout_timer(IN := TRUE, PT := T#5s);
14 timeout_flag := timeout_timer.Q;
15
16 2: (* RUN CONVEYOR *)
17 Motor_FWD := TRUE;
18 index_timer(IN := Motor_FWD, PT := T#2s);
19 IF index_timer.Q THEN
20 Motor_FWD := FALSE;
21 state := 3;
22 END_IF;
23
24 3: (* CONFIRM POSITION *)
25 IF Pos_Sensor AND NOT fault OR e_stop THEN
26 state := 0;
27 END_IF;
28
29 END_CASE;
0

Challenge Complete

Next Challenge →