
Introduction
INTRODUCTION

In industrial automation programming, timers are one of the most commonly used components in control logic. While standard timers like TON and TOF can meet most scenarios, are there more flexible implementations for situations that require special timing accuracy or want to break free from “relying on the system’s default timer”?
A user from the Siemens Industrial Technology Forum【1Shadow1】 made an interesting attempt in the TIA V16 environment using PLCSIM — customizing a timer by reading the program cycle time and configuring cycle interrupts. During the process, they encountered cumulative error pitfalls and made several optimizations, ultimately discovering a feasible approach. Today, I will share the complete process of this attempt, which may provide some new insights for your programming ideas.

Testing Environment: TIA V16 + PLCSIM
1. The first approach is to read the program’s cycle time each time, then divide by the PT time to get the number of runs needed;


2. The first method has cumulative errors, so it is only suitable for short durations, such as within 1 minute. Therefore, some improvements were made to address this flaw:
The first improvement is to accumulate all past cycle times, controlling the error to the last comparison, and then comparing it with the target value; the results showed significant improvement;
The second improvement is to use a consistent interrupt interval to replace the less stable cycle time for timing. Theoretically, these two improvements should control the error within 5ms, but in practice, it did not achieve that.


3. The third approach is more direct, using cycle interrupts to calculate based on the number of interrupts. It is important to note that a smaller set time does not necessarily mean higher accuracy, as the processing time of the interrupt program must be considered, while also reducing the use of floating-point calculations:



Summarizing these experimental approaches, we can see that the ET time comparisons are relatively accurate, but not perfect. I think there are two reasons for this:
-
Using a simulated PLC;
-
Not using an absolutely accurate time reference (yes, I have some doubts about the accuracy of the system’s timer).
Additionally, I made an extra discovery: using my phone timer as a reference, I found that the PLCSIM TON timer is approximately 15 seconds slow per 5 minutes, which means it is about 1 minute slow every 20 minutes;
For long-term timing, the error can be kept within an acceptable range by reading the system time and synchronizing with an NTP server.
The above is just to expand thinking and not be constrained by existing conditions. Interested colleagues can try it on actual PLCs.
This attempt to use cycle interrupts and cycle time as a timer, although encountering issues such as errors and simulation deviations, has broken the fixed mindset that “timing can only use TON” — as long as the core logic of timing is understood, flexible solutions can be designed based on the scenario.
Have you had similar “breaking the norm” attempts in programming? For example, custom pulse generators, special logic counters? Or have you encountered accuracy issues when using timers? Feel free to share your experiences and solutions in the comments section!


More Information
With such rich and practical functions, how can you quickly understand more detailed information and master the usage points? Later, we will launch more detailed introduction videos, usage tips, and precautions about SITOP power supplies on the Siemens 1847 Industrial Learning Platform.
Want to learn more? Then come to the popular courses on the 1847 Industrial Learning Platform that many people are studying!






Swipe left and right to see more course directories
The minimum 9.9 yuan (original price 139yuan), welcome to scan the code to add customer service for course details:

More Benefits
Popular courses, official certification
![]() |
|
![]() |
![]() |
![]() |
![]() |





