Timer Libraries
Timer
Overview
The Tsentry timer libraries encompass basic timer functions that can be used inside any application task to set and test timers.
Timer Types
There are two types of timers covered by these libraries: wall clock timers and set interval timers.
Wall clock timer values refer to an absolute date and time according to the host system. These timers are useful for timestamping events for HMI display or long-term storage. However, because these timers are referenced to the wall clock, which can be adjusted forwards and backwards either abruptly by an administrator or slowly by time synchronization services, these timers are not well suited for reliably measuring intervals of time. In other words, when comparing two wall clock timer values measured at two different moments, the numerical difference between the timer values may not equal the true time elapsed between the two measurements because the wall clock may have been adjusted faster or slower (or even backwards!) in between the two samples.
On the other hand, set interval timer values are based on a clock that ticks at very precise intervals. As a result, the underlying timer values increment at a constant rate regardless of any adjustments made to the system time. However, the underlying clock tick interval is not exactly an integer number of nanoseconds – for instance, the actual elapsed time between ticks on a given system could be 100.001 ns, and there is no compensation for this extra 0.001 ns. So while these set interval timer values are reliable for measuring short durations, over long durations these 0.001 ns errors can add up. As a result, measuring time across a day or more using a set interval timer may indicate an elapsed time that differs from the same measured by a wall clock timer by +/-1 second or more.
Timer Values
Within C/C++ tasks, all timers are stored as TIMERVAL variable types. Internally the TIMERVAL is a 64-bit integer counting 100ns increments, but applications should consider TIMERVAL as an opaque type and only utilize the methods described below for interacting with TIMERVAL variables.
Timer Functions
Current Time
The following functions can be used to get the current value of a timer.
Timer Type Detection
The following functions can be used to determine the type of a timer.
Timer Reset
The following functions can be used to initialize or reset a timer.
Timer Type Conversion
The following functions can be used to convert between timer types.
Setting Timers
The following functions can be used to create a timer that will expire at some time in the future.
Testing Timer Status
The following functions can be used to test if a timer is active or expired.
Elapsed Time
The following functions can be used to calculate the time elapsed since a timer value.
Remaining Time
The following functions can be used to calculate the time remaining until a timer value.
Calculating Time Differences
The following functions can be used to calculate the difference between two timer values.
Â
Â
Â
Â
Â
Â
© 2022 TelePro, Inc.
3811 Illinois Avenue, Suite 100, St. Charles, IL 60174