The Tick module provides accurate time-keeping capabilities based on the hardware clock. By default, it uses Timer 0 on 8-bit parts and Timer 1 on 16- and 32-bit families. The module is interrupt driven, which makes the timing stable and accurate. As such, it is also suitable for a real-time clock.
The Tick module exists to assist with the implementation of non-blocking delays and timeouts. Rather than using a loop to count to a specific number, use the Tick module and compare a previous time with the current time. In this fashion applications can return its unused cycles to the stack during long delays, which increases the overall efficiency of the system.
Tick works best in conjunction with a state machine. In general, call TickGet and store the result. Return to the main stack application, and on future calls compare the current Tick value to the stored one. The constants TICK_SECOND, TICK_MINUTE, and TICK_HOUR can be used to compare against logical time increments.
The following example implements a delay of 0.5 seconds using the Tick module:
TICK startTime; // ...state machine and other states case SM_SET_DELAY: startTime = TickGet(); sm = SM_DELAY_WAIT; return; case SM_DELAY_WAIT: if((LONG)(TickGet() - startTime) < TICK_SECOND/2) return; case SM_DELAY_DONE: // This state is entered only after 0.5 second elapses.
Ticks are stored internally as 48-bit integers. Using the various TickGet, TickGetDiv256, and TickGetDiv64K functions the Tick is suitable for measuring time increments from a few microseconds to a few years.
If absolute timestamps are required, the SNTP Client module may be more appropriate.
Name |
Description |
Functions and variables accessible by the stack application | |
Functions and variables intended to be accessed only by the stack | |
Functions and variables internal to the Tick module | |
The following table lists functions in this documentation. |
|
Name |
Description |
|
6-byte value to store Ticks. Allows for use over longer periods of time. |