4.1.2 As a Source of Periodic Tick

In an application that needs to keep track of time, or has operations to perform periodically, a timer can be used to provide periodic ticks.

In this mode, a timer is set up to count continuously. The counting frequency is often a factor of the main clock frequency. For count up timers, software usually sets up an overflow value. For count down timers, software can usually set up a restart value. Sometimes, the overflow or restart value cannot be specified in software, and hardcoded to some powers of 2.

For a count up timer, when the counter value becomes greater than or equal to the overflow value, the timer resets the counter to zero and causes a hardware interrupt. We'll talk about interrupts later. For now, let's just say that ``the timer calls a particular subroutine in software''.

For a count down timer, when the counter value gets to zero, the timer reloads the counter with the reload value, and it causes a hardware interrupt.

As you can see, whether a timer counts up or down is not important. The important point is that it ``calls a particular subroutine in software'' periodically. We'll discuss interrupt service routines (ISRs) later.

Copyright © 2006-02-15 by Tak Auyeung