(* ============================================================ ACC PLC Simulator - Traffic Light Drum Sequencer in Structured Text Scene: Traffic Light Intersection (acc-traffic-scene.html) Blog: https://accautomation.ca/plc-drum-sequencer-traffic-light/ Structured Text has no DRUM instruction. This is the same six-step sequence as acc-example-traffic-drum.json, written the usual way: a step number, a CASE for the step time, and one TON. X3 Run enable switch (X tab, maintained, ON = run) X4 Reset pushbutton (X tab) Y1 NS green Y2 NS yellow Y3 NS red Y4 EW green Y5 EW yellow Y6 EW red D1 Step (1-6), the same register the ladder drum uses D2 Completed cycles Step Lights Time 1 NS green, EW red 5 s 2 NS yellow, EW red 2 s 3 all red 1 s 4 EW green, NS red 5 s 5 EW yellow, NS red 2 s 6 all red 1 s (16 s per cycle) One difference from the drum: a TON cannot pause. With X3 OFF the step and the lights hold, but the step time starts again from zero when X3 comes back ON. The ladder DRUM keeps its time in step. ============================================================ *) VAR StepTimer : TON; // times the current step StepTime : TIME; // preset for the current step Advance : BOOL; // step time reached on the last call END_VAR // Reset: back to step 1 and clear the cycle count IF X4 THEN D[1] := 1; D[2] := 0; END_IF; // A step number outside 1-6 (0 in a new program) means step 1 IF (D[1] < 1) OR (D[1] > 6) THEN D[1] := 1; END_IF; // Step time - one case per step, like the drum's step table CASE D[1] OF 1, 4: StepTime := T#5s; // greens 2, 5: StepTime := T#2s; // yellows ELSE StepTime := T#1s; // all red clearance (steps 3 and 6) END_CASE; // The timer runs while Run is ON and Reset is OFF. // NOT Advance drops IN for one scan after each step, which restarts it. StepTimer(IN := X3 AND NOT X4 AND NOT Advance, PT := StepTime); Advance := StepTimer.Q; IF Advance THEN D[1] := D[1] + 1; // next step IF D[1] > 6 THEN D[1] := 1; // back to the start D[2] := D[2] + 1; // one more completed cycle END_IF; END_IF; // Lights - written straight from the step number Y1 := D[1] = 1; // NS green Y2 := D[1] = 2; // NS yellow Y3 := D[1] >= 3; // NS red: steps 3 to 6 Y4 := D[1] = 4; // EW green Y5 := D[1] = 5; // EW yellow Y6 := (D[1] <= 3) OR (D[1] = 6); // EW red: steps 1 to 3 and 6