Timers are a staple of any PLC program, it’s extremely unlikely that any sizable project does not have a use case for a timer of any sort. This post takes us through some examples of how Timers work, use cases and also some insights into other less known areas.
There are 3 types of timer that all have the same base type ( IEC Timer ), but behave slightly differently as to how they control their output.
All 3 types of Timer all share the same interface, consisting of the following:
The most common type of Timer is the TON, as shown in #R1.0.
This timers output value adheres to the following logic rules:
IF IN is True AND ET is Less Than Or Equal To PT THEN Q is True
Else Q is False
📝Note
If IN is False , ET = PT
If IN is True , ET is incremented towards the PT value
This is demonstrated in the following image, lifted from Siemens TIA Portal’s help system
A TOF timer works the opposite way round to the TON timer, meaning the output is kept True whilst the timer is idle and not timing, but only after IN is set to True . It is on the transition to False that the timer starts.
Once started, it is not until the ET = PT that the Q value is set to False .
The output of a TOF timer adheres to the following rules:
IF IN is False AND ET is Less Than Or Equal To PT THEN Q is False
Else Q is True
Whilst the above statement is correct, it’s important to understand that the IN must have been True at some point in order for the Q to be True . The Q output will not be true on PLC start if the IN is not True
The below diagram, lifted from Siemens TIA Portal’s help system demonstrates this:
A TP timer will always complete its PT duration on the rising edge of IN . Even if IN falls to False , the timer will continue to time. During the execution of the PT duration, whilst PT
The output of the TP timer adheres to the following rules
IF IN transitions from False to True THEN Q is True UNTIL ET >= PT
Even if IN becomes False whilst ET < PT , the Q output is remains True
Even if IN remains True whilst ET >= PT , the Q output returns to False
The following diagram, lifted from Siemens TIA Portal’s Help System demonstrates the above logic:
Each timer has a PT input, which sets the duration of the Timer. In order to set the PT value, the Time data type is used.
A 20 second period, represented as Time would look like T#20s when hard-coded on the interface of the Timer (See #R1.4 for example)
The PT input will also accept millisecond representations of time, for example 2000 would be T#2s . This is because the Time data type is represented in milliseconds as the base value, but visually shown as a “nice” T#2s value to keep things simple.
📝 Note
The value 7882000 as milliseconds is difficult for us to quickly work out as a time based value, so the Time data type serves as an easy way to visually read that. In this case it would be T#2H_11M_22s , which doesn’t need any further explanation
Siemens handle IEC Timers a little differently to most other PLC vendors, opting for the rule that PT values can only be changed when Timers are NOT running. The example below demonstrates that despite the Timer’s PT value being changed from T# 30s to T#15s , the Timer rolls through the 15s period, and all the way to 30s before the variable Complete is set to True
Each Timer type has its own instance data type, as shown above. This means that TON uses TON_Time , TOF uses TOF_Time and TP uses TP_Time .
However, a not-so-well-known secret of TIA Portal is that all of these timer instance data types are actually an alias for the data type IEC_Timer . You can actually mix and match all of the Timer types with any of the data types, and the project will compile and operate without issue.
The above image shows that a TON timer has an instance declaration as a TP_Time data type, yet is operating as a TON still. If it were to behave as a TP, we’d expect to see the Complete variable as True .
Because of this, we can exploit the fact that all timer types can use the TON_Time data type to create a 1 Timer Fits All super Timer.
This timer will be capable of the following functionality:
This section of the post contains a walk-through of a Function Block that is set up to manage multiple different modes of Timer. It demonstrates how a Timer can be all 3 types, with the functionality set out above. This section only available to Do & Grow members as part of Do & Grow membership enables additional insight into popular topics.