Introduction
A retentive timer (RTO) helps keep track of time even if the timer is stopped or paused. It remembers how much time has passed so you don't lose progress.
RTO TimerName, PresetTime, AccumulatedTime, Enable
RTO Timer1, T#5000ms, AccTime1, StartSignalRTO MotorRunTimer, T#10000ms, MotorRunAccum, MotorRunning(* Example of RTO timer behavior in structured text *) VAR StartSignal : BOOL := FALSE; TimerDone : BOOL := FALSE; AccTime : TIME := T#0ms; END_VAR (* Simulate timer with RTO behavior *) IF StartSignal THEN AccTime := AccTime + T#100ms; (* Add 100ms each cycle while enabled *) IF AccTime >= T#500ms THEN TimerDone := TRUE; END_IF ELSE (* Timer paused, AccTime keeps value *) END_IF (* Reset logic for demonstration *) IF TimerDone THEN AccTime := T#0ms; TimerDone := FALSE; END_IF (* Simulation steps *) (* Step 1: StartSignal = TRUE, timer counts up *) (* StartSignal := TRUE; *) (* After 5 cycles, AccTime = 500ms, TimerDone = TRUE *) (* Step 2: StartSignal = FALSE, timer pauses, AccTime keeps value *) (* StartSignal := FALSE; *) (* AccTime stays at 500ms *)
IF Start THEN RTO.EN := TRUE; ELSE RTO.EN := FALSE; END_IF; // After 5 seconds running, Start goes FALSE for 3 seconds, then TRUE again // What will be the accumulated time (RTO.ACC) after 10 seconds total?
IF Start THEN RTO.EN := TRUE; ELSE RTO.EN := FALSE; RTO.ACC := 0; END_IF;
Pass the test and this pattern moves unknown