Timers in PLC Programming

Timers are key in PLC programming, helping control everything from when a motor starts to how long a signal lasts. They might seem tricky at first, but they’re straightforward once you get the hang of them. Let’s explore how these timers work and how you can use them effectively.


On Delay Timer (TON)

Off Delay Timer (TOF)

Pulse Timer (TP)

Timer Accuracy

Different PLC platforms offer various timer functions, and many are unique to a specific platform. For instance, Siemens PLC has its own set of timer functions exclusively for their systems. It’s important to know this as the timer functions you can use might vary with the platform you choose.

Timers can be used not only in ladder logic but also as functions blocks in function block diagram or functions in structured text. They can even be used to check how long an actuator has been running and then for alarms in a SCADA system.

PLC Timers from the standard

Because this can be very confusing with all these different timer function, I will give you an introduction to the 3 standard timer functions.

The reason for this is that they work the same way no matter which platform you are using.

You will find them defined in the official standard for PLC programming languages – IEC61131-3 by PLCOpen. Since this is the standard for PLC programming languages most platforms have these three types of timer functions available

In this tutorial, I will not only show you how those standard timer functions work but also stimulate them in the open-source CodeSys environment. That way, you can see how you can use the PLC timer functions in your own PLC programs.

On Delay Timer (TON)

First one of the standard timers is the on delay timer also known as just TON. This is by far the most used timer in PLC programming. You will find this in any platform and it is in fact so useful that you can build the other timer functions with the on delay timer.

The functionality of the on delay timer (TON) can be described like this:

Output is turned ON after a delay

For that reason the timer also has its name.

Below here you can see the timing diagram of the on delay timer. You can see that the output is turned on after a delay.

On Delay Timer Diagram
On Delay Timer Diagram

This delay is called the preset time (PT). The delay said in another way, is how long you want the timer to be turned on. When you turn on the input (IN) the timer will start timing (turning on the timer). Elapsed time (ET) is the current time of the timer. Here you can always see how long the timer has been turned on.

As soon as you activate the timer by turning on the input the timer will start counting. After a certain delay the output will be turned on.

Off Delay Timer (TOF)

The second standard PLC timer is the off delay timer or just TOF. My best way to remember how it works is again by its name.

It is called an off delay timer because it works like this:

Output is turned OFF after a delay

One of the biggest differences between this and the on delay timer is how you activate it.

As soon as you turn on the input of this timer, the output is also turned on. This is because in order for the output to be turned OFF (after a delay) it needs to be turned on in the beginning.

Check the timer diagram below to see that.

Off Delay Timer Diagram
Off Delay Timer Diagram

The timer will not be activated before you turn the input off again. When you do that the timer will start counting and after the delay, the output will be turned off.

Pulse Timer (TP)

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

Although this timer is not so commonly used it is still a very useful timer function.

This timer is a little different than the two others, since this one is used to generate pulses. Yes, that is also how we can describe its functionality:

Generates a pulse of a specific length

You can activate the timer by turning on the input. When that happens the timer will start counting time. As a parameter for the pulse timer the time for the pulse is defined.

After the output has been on for that amount of time it will be turned off again.

Pulse Timer Diagram
Pulse Timer Diagram

Again, you can see above in the timing diagram how it works

The difference from the two other timers here is that this pulse will happen no matter what the state of the input will be in the mean time. You will always get a pulse of that certain length after the timer has been activated.

If you look closer at the timing diagram you can also see that Q always has the same length

I find the pulse timer to be very useful exactly because is doesn’t depend on the input. All it needs is a short or long or just any signal at the input to give you that pulse.

Timer Accuracy and Timer Errors

Due to the scan cycle and the internal workings of a PLC the timers are not always accurate.

This is important to know about if you are a professional PLC programmer, because in the end it can affect how your programs will work. If you are timing with seconds, minutes or more this has no effect and you should not be worried.

But if you are dealing with milliseconds in your timers, the accuracy of the timers can suddenly have a huge impact and your timing can be wrong.

When the timer does not count the time we expected it is called a timer error. And basically there are two types of timer errors – software and hardware errors.

Both of these can generate errors and inaccuracy both on the input side and on the output side

Software Errors

You might wonder how the software in a PLC can generate timer errors. But here I’m not talking about the software you are programming with ladder logic or structured text. I’m talking about the internal software also called firmware.

The firmware is what makes the PLC work. It is this piece of software that does the whole scan cycle of the PLC – puts the state of the inputs into memory registers, runs your program and sets the outputs via the output memory registers.

Because of exactly that scan cycle the software can lead to some timer inaccuracy and errors.

Input Errors

Input errors occur when the PLC detects inputs later than expected. The PLC’s scan cycle, typically around 20 ms, first checks the inputs. If an input changes right after this check, the PLC might only recognize it in the next cycle. This delay can impact precise timing in your programs.

This might not seem like a lot, but if you’re dealing with large PLC programs or you have to time very short amounts of time (milliseconds) this is a significant error.

Output Errors

Output errors can also stem from the scan cycle’s timing. If the PLC is set to change an output right after it has updated the output register, there might be a full scan cycle’s delay before the change takes effect. It’s crucial to consider this to ensure your PLC responds accurately.

Total Software Error

When you sum up the input and output errors you will get what is called the total software error. This error can be up to two scan cycles long which is quite a lot of time if you’re working in ms.

Hardware Errors

The accuracy of a PLC timer can also depend on the PLC hardware. You will often see even experienced PLC programmers overlook this source of errors.

It is so important for PLC programmers not only to know about PLC programming, but also to know about electronics and hardware. Because of how the hardware works it can generate errors both at the inputs and at the outputs of a PLC.

Input Errors

Most modern PLC’s has a build-in filter on the input side to avoid noise and bouncing. This filter is actually a small delay, that makes sure the short spikes will not get detected at real inputs.

When you press a button and turn on e.g. 24VDC at a PLC input what will happen is a lot of bouncing, just as the button or sensor closes and electrical connection is made.

The signal will jump up and down and without the filter the PLC might detect that as not just one press but multiple presses on the button. If you connect an oscilloscope at the input you can see that bouncing.

Filtering out the bouncing and noise will also give a delay from the timer input is turned on to when the PLC actually detects that it is turned on.

Output Errors

On the output side you can also have errors. They happen because of the output electronics. If you have a relay output it can actually take up to 10 milliseconds for the relay to close.

Transistors (such as NPN transistors) are a little better but could still take up to 1 ms to fully close.

All these hardware and software errors might not seem significant, but if you sum them up you can easy get a total error or inaccuracy of 100 milliseconds.

100 ms!

That is a tenth of a second.

This is why it is so important to know about these timer errors and the timer accuracy. If you are working with small amounts of time that requires precision you should take your measures.

You can for example do it with periodic task execution that doesn’t depend on the scan cycle and use transistor outputs.

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