Timers in PLC Programming

PLC timers control when events happen, from starting a motor to setting a signal’s duration. They can seem tricky when you’re learning, but become straightforward with practice. Understanding how they work lets you choose and use them in your programs. The examples below connect each timer’s name to its behavior, so you can understand what happens when it runs.

Content:

On Delay Timer (TON)

Off Delay Timer (TOF)

Pulse Timer (TP)

Timer Accuracy

The timer functions available depend on the PLC platform. Many belong to a particular platform; Siemens PLC, for example, has timer functions exclusive to its systems. When choosing a platform, remember that its timer options can differ from those on another system.

You can use timers in ladder logic, as function blocks in function block diagram or as functions in structured text. Timers can also measure how long an actuator has run and use that timing for alarms in a SCADA system.

PLC Timers from the standard

With so many timer functions available, it helps to start with the 3 standard ones.

I use these as a starting point because their behavior stays the same across platforms.

The official PLC programming language standard, IEC61131-3 by PLCOpen, defines them. Most PLC platforms therefore include these three timer functions.

I’ll show how the standard timers work and simulate them in the open-source CodeSys environment. Watching them run will help you see how to use these functions in your own PLC programs.

On Delay Timer (TON)

The first standard timer is the on delay timer, usually called TON. By far the most common timer in PLC programming, TON is available on any platform. You can even use an on delay timer to build the other timer functions.

An on delay timer (TON) works as follows:

Output is turned ON after a delay

The name describes that delay before the output turns on.

The timing diagram below shows the delay between activating the timer and turning on its output.

On Delay Timer Diagram
On Delay Timer Diagram

The delay is called preset time (PT): the time you want the timer to stay on. Turning on input (IN) starts the timing. Elapsed time (ET) shows the timer’s current time, so you can check how long it has been on. In other words, ET lets you follow the count as the timer runs, while PT is the delay you have chosen.

Turning on the input activates the timer and starts the count. Its output turns on once the set delay has passed.


Off Delay Timer (TOF)

Next is the off delay timer, or TOF. I find its name the easiest way to remember what it does.

The off delay timer gets its name from this behavior:

Output is turned OFF after a delay

How you activate the timing is a main difference between this timer and the on delay timer.

Turning on this timer’s input immediately turns on its output. The output needs to be on first so it can later turn OFF after the delay. At this stage, the input and output are both on; the delayed switch-off comes later.

You can follow that sequence in the timing diagram below.

Off Delay Timer Diagram
Off Delay Timer Diagram

Timing begins only when you turn the input off again. The timer then counts until the delay ends, at which point it turns the output off.


Pulse Timer (TP)

The final one of the 3 standard timers is called the Pulse Timer or PT.

This timer is less common, but I still find it useful.

Unlike the other two, this timer generates pulses. Its function can be described as follows:

Generates a pulse of a specific length

Turning on the input activates the timer and starts its count. A parameter defines how long the pulse will last.

Once the output has stayed on for that time, the timer turns it off again.

Pulse Timer Diagram
Pulse Timer Diagram

The timing diagram above shows the sequence.

With this timer, changes to the input during the pulse do not affect it. Once activated, it produces a pulse of the specified length, which differs from the behavior of the other two timers. The output completes that timed pulse even if the input signal changes while it is running.

In the timing diagram, notice that Q stays on for the same length each time.

I find the pulse timer useful because the pulse doesn’t depend on how long the input stays on. A brief or long input signal will produce the same pulse.

Timer Accuracy and Timer Errors

A PLC’s scan cycle and internal operation can make its timers inaccurate.

Timer accuracy can affect how your PLC programs work, so professional programmers need to understand it. If you time events in seconds, minutes or longer, these errors have no effect and are not a concern. The time intervals you use in the program determine whether this source of error affects the timing you need.

When you time events in milliseconds, however, an inaccurate timer can make a large difference to the result.

A timer that counts a different time from what we expect has a timer error. These errors fall into two types: software errors and hardware errors.

Either type can cause inaccurate timing at the PLC’s inputs or outputs.

Software Errors

Software-related timer errors can come from the PLC’s firmware, its internal software. Here I mean that software, rather than the ladder logic or structured text program you write. The distinction matters because the error comes from the software running the PLC internally, rather than from your choice of programming language.

Firmware runs the PLC, including the full scan cycle of the PLC. It saves the input states in memory registers, executes your program and sets the outputs through the output memory registers.

That scan sequence is how the internal software can introduce timer errors and inaccuracy.

Input Errors

If the PLC detects an input later than expected, it causes an input error. A typical scan cycle is around 20 ms and checks inputs first. An input that changes just after that check might wait until the next cycle to be recognized, delaying precise timing in your program. Until that next check, the PLC has not yet seen the changed input state.

That delay can be large enough to affect a big PLC program or a program timing very short periods in milliseconds.

Output Errors

The scan cycle can also delay outputs. If an output is due to change just after its register has been updated, the change might wait a full scan cycle. Account for that delay when you need the PLC to respond accurately.

Total Software Error

Adding the input and output errors gives the total software error. It can last up to two scan cycles, a long delay when you are timing in ms. Both sides contribute to that delay, so considering just the input or just the output leaves part of the software error out.

Hardware Errors

The PLC hardware can also affect timer accuracy. Even experienced PLC programmers often overlook this source of error.

Electronics and hardware knowledge matters alongside PLC programming because the hardware can introduce errors at both the inputs and the outputs.

Input Errors

Most modern PLCs filter their inputs to reject noise and bouncing. The filter adds a small delay so brief spikes are not detected as real input signals.

Pressing a button to apply, for example, 24VDC to a PLC input causes bouncing as the button or sensor closes and makes the electrical connection.

As the signal jumps up and down, the PLC might register several button presses unless the filter rejects the bouncing. You can connect an oscilloscope at the input you can see that bouncing. The trace shows the signal moving up and down as the connection is made.

The filter’s rejection of bouncing and noise also delays the PLC’s detection after the timer input turns on.

Output Errors

Output electronics introduce their own errors. A relay output, for example, can take up to 10 milliseconds to close.

A transistor output, including NPN transistors, is a little faster but could still take up to 1 ms to close fully.

Small hardware and software errors can add up. Together, they can easily produce a total timing error of 100 milliseconds. Each source contributes some delay, and their combined effect determines how far the actual timing differs from what you expect.

100 ms!

That is a tenth of a second.

For short intervals that need precise timing, you must account for these errors. Understanding timer accuracy helps you decide what measures to take.

For example, you can use periodic task execution independent of the scan cycle, together with transistor outputs.

1 Comments
Leave a response
  • vikram patil
    April 27, 2019 at 2:26 pm

    sir preset time should be less than elapsed time how should you taking preset time 7 sec. and elaspsed time also 7 sec. in video.

Leave a Response