On-delay timer (TON) behavior in PLC Programming - Time & Space Complexity
We want to understand how the time a PLC program takes changes when using an on-delay timer (TON).
Specifically, how the timer's behavior affects the program's execution time as inputs change.
Analyze the time complexity of the following on-delay timer code snippet.
// On-delay timer (TON) example
TON Timer1;
Timer1.IN = StartSignal;
Timer1.PT = T#5s;
Timer1();
if (Timer1.Q) {
Output = TRUE;
} else {
Output = FALSE;
}
This code starts a timer when StartSignal is TRUE and sets Output TRUE after 5 seconds delay.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: The timer function Timer1() is called every scan cycle.
- How many times: It runs once each scan, repeatedly until the timer reaches the preset time.
The timer function runs every scan, so the total operations grow with the number of scans while the timer is active.
| Input Size (n scans) | Approx. Operations |
|---|---|
| 10 | 10 calls to Timer1() |
| 100 | 100 calls to Timer1() |
| 1000 | 1000 calls to Timer1() |
Pattern observation: The number of operations grows linearly with the number of scans during which the timer is running.
Time Complexity: O(n)
This means the time spent grows directly in proportion to how long the timer runs.
[X] Wrong: "The timer only runs once, so it takes constant time regardless of delay."
[OK] Correct: The timer function is called every scan until the delay finishes, so time grows with the delay length.
Understanding how timers affect program execution helps you design efficient control logic and shows you grasp real-world PLC behavior.
"What if the timer was reset frequently before reaching the preset time? How would that affect the time complexity?"
Practice
On-delay timer (TON) do in a PLC program?Solution
Step 1: Understand the function of an On-delay timer
An On-delay timer waits for a set time after the input signal turns ON before activating the output.Step 2: Compare options with this behavior
Only It delays turning on the output after the input is activated. correctly describes this delay before output activation.Final Answer:
It delays turning on the output after the input is activated. -> Option CQuick Check:
On-delay timer delays output ON = C [OK]
- Confusing on-delay with off-delay timer
- Thinking output turns on immediately
- Mixing delay before turning off output
Timer1 with a preset time of 5 seconds in a typical PLC ladder logic?Solution
Step 1: Identify standard TON timer syntax
In IEC 61131-3 style, TON timers use PT (preset time) with time format like T#5s.Step 2: Match options to this syntax
TON Timer1 PT:=T#5s;usesPT:=T#5swhich is correct syntax for preset time 5 seconds.Final Answer:
TON Timer1 PT:=T#5s; -> Option AQuick Check:
Preset time uses PT:=T#5s format [OK]
- Using incorrect time format like '5s' without T#
- Missing PT:= keyword for preset time
- Confusing TON declaration syntax
TON Timer1 with a preset time of 3 seconds:Timer1(IN:=InputSignal, PT:=T#3s); // Assume InputSignal turns ON at time 0s // What is the value of Timer1.Q at 2 seconds?
Solution
Step 1: Understand TON behavior with preset 3 seconds
The output Q turns TRUE only after input is ON continuously for 3 seconds.Step 2: Check time at 2 seconds
At 2 seconds, input has been ON less than 3 seconds, so Q remains FALSE.Final Answer:
FALSE -> Option BQuick Check:
Q turns TRUE after 3s delay, at 2s Q = FALSE [OK]
- Assuming Q is TRUE immediately when input turns ON
- Confusing preset time with elapsed time
- Thinking Q toggles before preset time
TON Timer1; Timer1(IN:=StartButton, PT:=T#4s); // Output Q is not turning ON even after 5 seconds of StartButton pressed. // What is the likely error?
Solution
Step 1: Analyze why Q never turns ON after 5 seconds
If input StartButton never becomes TRUE, timer never starts counting.Step 2: Check other options
Preset time 4s is enough; missing reset won't stop Q turning ON; output usage unrelated to timer counting.Final Answer:
StartButton input is not wired or always FALSE. -> Option DQuick Check:
Input must be TRUE to start timer [OK]
- Assuming timer counts without input TRUE
- Thinking reset is mandatory to start timer
- Ignoring input signal state
Solution
Step 1: Identify correct input and delay for safety light
The light should turn ON only after door is open for 10 seconds, so input must be DoorOpen sensor TRUE and PT = 10s.Step 2: Evaluate options
Use a TON timer with input = DoorOpen sensor, PT = 10s, output controls light. matches this exactly. Use a TON timer with input = NOT DoorOpen, PT = 10s, output controls light. uses NOT DoorOpen which is wrong. Use a TOF (off-delay) timer with input = DoorOpen, PT = 10s, output controls light. uses off-delay timer which delays turning OFF, not ON. Use a TON timer with input = DoorOpen sensor, PT = 5s, output controls light. uses 5s delay which is too short.Final Answer:
Use a TON timer with input = DoorOpen sensor, PT = 10s, output controls light. -> Option AQuick Check:
Delay ON after door open 10s = Use a TON timer with input = DoorOpen sensor, PT = 10s, output controls light. [OK]
- Using off-delay timer instead of on-delay
- Using inverted input signal
- Setting delay time too short
Ready to prove it?
Pass the test and this pattern moves unknown
