Review Mode ST Simulator
Medium

Bottle Capper — Sequence Control

Program a Structured Text sequence to control an automated bottle capping station. The capper must detect a bottle, descend, torque the cap, retract, and signal done — all within a 3-second cycle.

180 XP
📋 Scenario A rotary filling line feeds uncapped bottles to your station at 20 bottles/min. A proximity sensor detects the bottle. A pneumatic cylinder descends the capper head. A torque sensor confirms cap tightness. Your job: write the ST program that sequences all outputs correctly. The line will fault if the capper head is still down when the conveyor indexes to the next position.

✓ Solution & Explanation

Root cause: state_machine

Reference Code

IF NOT In_EStop THEN
    Out_Fault := TRUE; Out_CylExtend := FALSE;
    Out_CylRetract := TRUE; Out_CapMotor := FALSE;
    state := 0; RETURN;
END_IF;
Out_CycleComplete := FALSE;
CASE state OF
    0: Out_CylExtend:=FALSE; Out_CylRetract:=TRUE; Out_CapMotor:=FALSE;
       IF In_BottlePresent AND In_CylUp THEN state:=1; END_IF;
    1: Out_CylExtend:=TRUE; Out_CylRetract:=FALSE;
       IF In_CylDown THEN state:=2; END_IF;
    2: Out_CapMotor:=TRUE;
       IF In_TorqueOK THEN state:=3; END_IF;
    3: Out_CapMotor:=FALSE; Out_CylExtend:=FALSE; Out_CylRetract:=TRUE;
       IF In_CylUp THEN state:=4; END_IF;
    4: Out_CycleComplete:=TRUE; state:=0;
END_CASE;

Steps

  1. State 0 (IDLE): De-assert all outputs. Transition when In_BottlePresent AND In_CylUp.
  2. State 1 (DESCEND): Assert Out_CylExtend, clear Out_CylRetract. Wait for In_CylDown.
  3. State 2 (CAP): Assert Out_CapMotor. Wait for In_TorqueOK.
  4. State 3 (RETRACT): De-assert motor + extend, assert retract. Wait for In_CylUp.
  5. State 4 (COMPLETE): Set Out_CycleComplete := TRUE, state := 0 on the same scan.
  6. E-Stop guard: Latch Out_Fault, kill motion, RETURN — fires before state machine every scan.

(1) CycleComplete is a 1-scan pulse: cleared at top of every scan, then state 4 sets it and transitions to 0, so next scan state 0 runs with it already FALSE. (2) Interlock is structural — no state ever writes both Extend and Retract TRUE. (3) Fault latch stays set because Out_Fault := TRUE is unconditional in the E-Stop guard.

0

Challenge Complete

Next Challenge →