Application Timer Expiration Behavior
Application timer periods should be configured to either match the Subsystem's HAL timer period or be a multiple of it. The HAL timer period is configured in the RTX64 Control Panel. It begins when the Subsystem is started and provides a HAL timer tick based on the configured value. For example, when the HAL timer period is set to its default value of 100 μs, a tick would occur at each 100 μs interval.
When a user-created timer period does not match the criteria noted above, the user timer’s period will be rounded down by the Subsystem. For example, if the HAL timer period was set to 100 μs, and the user timer period was set to 450 μs, the user timer period would be rounded down to 400 μs and would expire 50 μs earlier than expected.
A user timer period will often begin before or after a HAL timer tick. The delta between the user timer start time and the HAL tick can cause the user timer to expire earlier than expected, possibly up to one HAL timer period early.
The below diagrams demonstrate examples of this behavior.
NOTE: In the examples below, the HAL timer period is set to its default configuration of 100 μs.
Example 1: The User Timer Period is Rounded Down
In this example, the user timer, which starts on a HAL timer tick, is configured to expire after 250 μs. Because the timer’s expiration occurs between HAL timer ticks, the timer is rounded down, causing the actual timer to expire after 200 μs, 50 μs earlier than expected.
Example 2: The User Timer Period Starts before the HAL Timer Tick
In this example, the user timer start time occurs 50 μs before a HAL timer tick (indicated by the gold band in the diagram). As a result, the user timer, configured for 200 μs, expires between HAL timer ticks, causing the timer to be rounded down. The actual timer expires after 150 μs, 50 μs earlier than expected.
Example 3: The User Timer Period is Rounded Down Twice
The relationship between the timer duration, HAL timer period, and the timer’s start time can cause the timer to expire two ticks prior to the configured expiration time, as shown in the below example. Here, the user timer start time occurs 1 μs before a HAL timer tick (indicated by the gold band in the diagram). The user timer is configured to expire after 199 μs. Given the rule that application timers expire on the HAL timer tick immediately prior to the rounded down expiration time, the actual timer expires two HAL ticks prior to its configured expiration time, after only 1 μs — 198 μs earlier than expected.
To guarantee that a user-configured application timer expires only 1 HAL timer tick before the configured expiration time, and not more HAL timer ticks before, you must configure the timer’s expiration period to be a multiple of the HAL timer period.