PLC Programming SAPLC ProgrammingSOUTH AFRICA
Menu

exercises · South Africa

PLC Gate Control Program: Limits, Timers and Restart

Study a PLC gate control program with position limits, auto-close timing, reversal states and restart tests, plus practical South African course questions.

Conceptual PLC gate control program study desk with an enclosed miniature sliding gate and a laptop
Conceptual learning illustration; not a validated circuit, program screenshot or physical test result.

This PLC gate control program is a virtual sliding-gate sequencing exercise. It uses supplied position indicators, a trigger event, a continuous-clear waiting interval and separate timing for each movement attempt. You will test startup, interrupted closing, conflicting position signals and a trigger that restarts the auto-close wait.

The two outputs are OpenCommand and CloseCommand in a disconnected model. They are not instructions for connecting a motor, reversing contactors or installing a gate operator. The example cannot establish that a beam detects every obstruction, that a gate stops within a required distance or that a physical installation is safe.

For South African learners, the familiar gate scenario makes a useful PLC course question: can you explain what the programme knows about position after startup, and what it merely assumes? The lesson develops state reasoning and diagnostic evidence without turning a timing exercise into an installation guide.

Use input meanings that are explicit

AtOpen true means the exercise supplies an open-end position indication. AtClosed true means it supplies a closed-end indication. These names describe model values, not the electrical polarity of a particular switch or input module.

Both true is inconsistent under this exercise’s position contract. Both false means neither endpoint is indicated. That can be an ordinary observation during a commanded movement, but at startup it does not tell the programme which direction it should choose.

BeamClear is another supplied Boolean used by the exercise to permit its closing sequence. False cancels the open waiting interval or requests a closing interruption. It does not prove the presence of a person, vehicle or particular physical fault. True does not establish that all hazards have been detected.

TriggerButton is a virtual momentary request. Enabled permits the exercise to run, StopRequest cancels active sequencing, and ResetRequest is a separate event for clearing a latched model fault when its reset conditions are met.

Model valueMeaning
AtOpenSupplied open-end indication
AtClosedSupplied closed-end indication
BeamClearSupplied closing-sequence permission
TriggerButtonRequest to begin opening, restart a wait or interrupt closing
OpenCommandVirtual opening request
CloseCommandVirtual closing request

A normally closed contact does not, by its name alone, prove that every wiring failure is detected or that the indicated position is correct. Keep electrical interpretation separate from programme meaning. The ladder logic basics guide provides a starting point for that distinction.

Define six states and three separate clocks

Use Parked, Opening, OpenWait, Closing, ReversePause and Fault. Parked is a nonmoving state that requires a fresh accepted trigger. OpenWait permits automatic closing only after the defined waiting conditions. Fault is latched until an accepted reset.

Opening and Closing use a movement-entry timestamp. Each movement attempt receives a new origin and a fictional 45000 ms maximum interval. ReversePause has its own timestamp and a fictional 1000 ms duration. OpenWait has a separate ClearStartedAt timestamp for 30000 ms of continuously eligible observations.

StateOpenCommandCloseCommandMain purpose
ParkedFalseFalseWait for an accepted trigger and known endpoint
OpeningTrue unless AtOpenFalseRequest opening until arrival or timeout
OpenWaitFalseFalseObserve the full eligible auto-close interval
ClosingFalseTrue unless AtClosedRequest closing until arrival or interruption
ReversePauseFalseFalseSeparate virtual direction commands in time
FaultFalseFalseRetain the reported model fault

All command equations also require Enabled true, StopRequest false and no conflicting endpoint indications. The pause and timeout numbers are learning parameters. They do not size a drive, validate reversing delay, establish stopping performance or recommend settings for a real gate operator.

The conveyor sequence exercise introduces related command and restart concepts. The star-delta timing exercise offers another study of distinct states between virtual command combinations.

Conceptual sensor, controller and conveyor illustration for distinguishing signals from program values
Conceptual learning illustration; not a validated circuit, program screenshot or physical test result.

Make startup require an observed release

Initialise State to Parked, TriggerArmed false, all timestamps empty and FaultReason empty. Initialise PreviousTrigger and PreviousReset from the current supplied button values. A button already held at startup must not appear to be a new press.

During an eligible Parked evaluation with TriggerButton false, set TriggerArmed true. A later raw rising edge can be accepted only if TriggerArmed was true. Accepting it clears the armed flag. Update both previous-button values on every evaluation, including while stopped, disabled or faulted.

An accepted trigger in Parked examines the endpoint indications. If AtOpen alone is true, enter OpenWait. If AtClosed alone is true, enter Opening and start a movement timestamp. If neither is true, enter Fault with the reason PositionUnknownAtStart.

This version deliberately does not guess that opening from an unknown position is physically preferable. For a disconnected test, supply a consistent endpoint fixture and follow the reset procedure. A real position-recovery or homing procedure is outside the model and would need its own design.

If Enabled becomes false or StopRequest true, clear the clocks and TriggerArmed. A nonfaulted sequence becomes Parked. An existing Fault remains latched. Restore eligibility, observe the trigger released while Parked and then press again; a held button cannot resume the interrupted command.

State the priority rules before coding

At each evaluation, first handle disabled or stopped operation. Otherwise, conflicting AtOpen and AtClosed indications select Fault with a ConflictingEndpoints reason. These branches take priority over reset and ordinary transitions.

Next, accept a fresh ResetRequest edge if the endpoint indications are not conflicting. Reset selects Parked, clears FaultReason and all clocks, and clears TriggerArmed. Reset is not a movement request, and a trigger held during reset is not accepted as a subsequent fresh start.

With no accepted reset, Fault retains its reason and ignores movement requests. An unrecognised State value selects Fault with an InvalidState reason. A reset with neither endpoint indicated may clear the old fault, but a later start request still fails the known-endpoint requirement.

Only after those decisions should the ordinary state logic run. Use the state from the beginning of the evaluation to select at most one transition. Do not enter OpenWait and also process its auto-close branch in the same evaluation.

These priorities specify programme behaviour. In particular, a software reset does not prove that a physical cause has been removed. Keep the diagnostic wording tied to what the supplied inputs and timing actually establish.

Opening and the movement timeout

In Opening, AtOpen has priority over the movement timeout. If the open-end indication arrives at the exact evaluation where 45000 ms has elapsed, enter OpenWait rather than reporting timeout. Set ClearStartedAt empty on entry; the waiting interval starts on a subsequent eligible OpenWait evaluation.

If AtOpen is false and the movement interval has reached 45000 ms, enter Fault with OpeningTimeout. Otherwise remain Opening. Trigger presses during Opening are ignored in this version, and BeamClear does not change this virtual opening state.

That last rule is only a model choice about a supplied input. It must not be interpreted as advice to ignore physical protection while opening. The exercise has no sensing arrangement or assessment of hazards on either side of a real gate.

OpeningTimeout means the expected open indication was not observed within the configured model interval. It does not uniquely diagnose a slipped drive, a blocked gate, a failed limit switch or overheating. The fault-finding workflow guide helps frame observations without jumping to an unsupported root cause.

Illustrated learning desk with a notebook and laptop for planning Boolean logic test cases
Conceptual learning illustration; not a validated circuit, program screenshot or physical test result.

Require a full continuous-clear auto-close wait

In OpenWait, AtOpen must remain true. If it becomes false, select Fault with OpenIndicationLost. This makes unexpected position changes visible instead of silently continuing an automatic sequence from an unverified state.

If BeamClear is false, clear ClearStartedAt and remain OpenWait. If BeamClear is true and a fresh trigger edge occurs, set ClearStartedAt to the current time. That restarts the complete 30000 ms interval, even when the old interval was about to expire.

With BeamClear true and no trigger edge, initialise an empty ClearStartedAt to the current time. Otherwise, when current time minus ClearStartedAt reaches 30000 ms, enter Closing and start a new movement timestamp. A still-held trigger does not repeatedly restart the interval because it produces no new edge.

The distinction between clearing a permission flag and restarting a timer matters. A programme that only removes a startup inhibit can immediately use an already-completed timer. It has not necessarily given the newly requested full waiting interval.

A false BeamClear observation interrupts continuity. When it returns true, the next eligible OpenWait evaluation establishes a new origin. Time accumulated before the interruption is discarded. Compare this with a retentive timing requirement, which would be a different exercise.

Schneider Electric’s TON documentation describes on-delay behaviour and elapsed time. If you translate this timestamp model into a native timer, verify its actual reset and invocation behaviour. Do not assume the clock in a browser animation and the timer in a controller are interchangeable.

Interrupt closing without inheriting its old timer

In Closing, first check AtClosed. If true, enter Parked and clear TriggerArmed and all clocks. Otherwise check the 45000 ms movement timeout; if expired, select ClosingTimeout. This timeout has priority over a simultaneous trigger or BeamClear interruption in the model.

If neither arrival nor timeout applies, a fresh trigger edge or BeamClear false enters ReversePause. Both commands are false in that state. Record the pause-entry time and discard the previous movement timestamp.

In ReversePause, an AtOpen indication enters OpenWait. Otherwise, at 1000 ms or later from pause entry, enter Opening and create a new movement timestamp. Ignore further trigger edges during the pause; they neither shorten it nor queue another action.

A shared timer driven by “Opening or Closing” may remain continuously enabled when direction changes. Without an explicit reset policy, the second direction can inherit time accumulated in the first. The separate movement-entry timestamp here makes each attempt’s timing visible.

The virtual pause only defines separation between programme commands. It is not evidence that physical motion has stopped, that a contactor released or that reversal is appropriate. No motor circuit or commissioning procedure is supplied.

Two illustrated learners reviewing a controller example beside a guarded training conveyor
Conceptual learning illustration; not a validated circuit, program screenshot or physical test result.

Follow the normal wait, reversal and restarted wait

Use nondecreasing supplied timestamps. Enabled remains true and StopRequest and ResetRequest false throughout this trace. The initial endpoint is closed, and the trigger starts released.

Time msTriggerAtOpenAtClosedBeamClearState after evaluation
00011Parked, trigger armed
101011Opening
1000001Opening
50000101OpenWait, wait not started
50100101OpenWait, origin 5010
350090101OpenWait
350100101Closing
360000000ReversePause
369990000ReversePause
370000000Opening, new movement origin
420000101OpenWait
420100101OpenWait, origin 42010
500001101OpenWait, origin reset to 50000
500100101OpenWait
799990101OpenWait
800000101Closing
850000011Parked, trigger not yet armed

The trigger at 50000 restarts the full wait. It does not merely allow the interval that began at 42010 to finish. Closing therefore starts at 80000 in this supplied trace, not at 72010.

The reverse Opening attempt begins at 37000 and owns a new 45000 ms interval. Its nominal timeout threshold would be 82000 if AtOpen never arrived. It does not inherit the Closing origin at 35010 or the earlier Opening origin at 10.

Test the boundaries and contradictory observations

Supply both endpoint indications true during every state. With eligibility true and no higher-priority stop, the result must be Fault and both commands false. A reset edge while both remain true must not bypass that result.

Test startup with the trigger held, startup at the open endpoint and startup with neither endpoint. The first cannot create a new edge. The open-end case stays Parked until a release and fresh trigger are accepted; it must not begin auto-close merely because an open indication exists. The unknown case faults when starting is requested.

Test a BeamClear interruption just before the 30000 ms wait expires and exactly at its threshold. Both reset the wait. Test a fresh trigger edge at the threshold; it also restarts the full interval instead of closing.

Test arrival exactly at each movement timeout and timeout with no arrival. Under the declared priority, arrival wins the tie. In Closing with no arrival, an expired timeout wins over a simultaneous reversal request. Record these choices rather than relying on accidental rung order.

Test disabling and StopRequest in Opening, Closing, ReversePause and OpenWait. Commands clear, timing is discarded and a nonfaulted sequence returns to Parked. Restore eligibility with the trigger held: there must be no restart until the required release and new edge occur.

Illustrated learner comparing program observations with a guarded conveyor training model
Conceptual learning illustration; not a validated circuit, program screenshot or physical test result.

Build ladder logic from the transition contract

Keep raw trigger and reset edges separate from whether they are accepted. Keep each timestamp associated with the state that owns it. An intermediate NextState and explicit transition actions can help prevent multiple rungs from overwriting one another’s decisions.

Commit the state once, then decode OpenCommand and CloseCommand from that same result. Both should be false outside their respective movement states. Include the global eligibility and endpoint-conflict conditions in the final command equations.

Do not use a previous output value as a substitute for a complete state and timing specification. A cross-reference to the other command can introduce an evaluation-order delay, and it does not establish physical interlocking. The scan-cycle lesson can help explain why previous and newly assigned values differ.

The CODESYS simulation documentation distinguishes simulation from a physical controller, including differences in timing and I/O handling. Use simulation to inspect this logic contract, while keeping any claim about real equipment outside the evidence it supplies.

South African PLC training questions and portfolio evidence

When comparing PLC training in Pretoria, Johannesburg, Durban, Cape Town or online, ask whether the lesson is an ordinary logic simulation or an actual gate-operator training course. Those descriptions do not establish the same scope, equipment or competence.

Ask the provider to demonstrate a trigger at the auto-close threshold and a reversal near the travel timeout. Those two cases reveal whether the programme has explicit timestamp ownership and event priorities. A successful uninterrupted animation will not reveal either defect.

For a portfolio, include the input contract, transition rules, the seventeen-row trace and at least one intentionally failed test that you corrected. Describe the work as a virtual sliding-gate state model. Do not present a generated tabletop illustration as a customer installation or claim measured reduction in accidents, damage or downtime.

The online PLC training guide helps with delivery questions. The electrician learning guide can help separate programme interpretation from broader practical training requirements. A completed exercise is not a registered qualification or permission to commission physical equipment.

Questions learners ask about gate-control logic

Why does the model refuse to open from an unknown startup position?

Neither endpoint indicates a known starting position. The exercise chooses to report that uncertainty rather than invent a homing policy. During an already-commanded movement, neither endpoint can be an expected observation; the state and history change its meaning.

Does BeamClear false prove an obstruction?

No. It is a supplied permission value here. A physical system would need evidence about the sensor, wiring, diagnostics and installation to interpret the observation. The programme reports the value and follows the model’s interruption rule without assigning a unique cause.

Why use a separate reversal pause?

It makes a period with both virtual commands false explicit and independently testable. The fictional one-second value does not prove adequate physical stopping or switching time. The model also resets movement timing when the new opening attempt begins.

Can I use elapsed travel time as gate position?

Elapsed time alone does not measure position. Speed changes, stopped movement and different starting points would affect any such estimate. This exercise uses supplied endpoint indications and makes no claim to know a percentage-open position.

Conceptual PLC learning portfolio with a process sketch, test notes and a laptop showing logic
Conceptual learning illustration; not a validated circuit, program screenshot or physical test result.

Continue with command and execution-order practice

Explore motor-control practice in PLC Simulation Software for a related learning entry point, and inspect its scan-cycle highlighting feature when comparing conditions with resulting commands. These links do not claim that this exact gate model is a supplied or graded project on any particular plan.

Return to the PLC programming examples collection to compare other state and timing exercises. The useful result is a programme you can explain at startup, at an interruption and at an exact threshold, with a clear boundary between a command and physical evidence.

By PLC Programming SA · Last updated 2026-09-11