microcontroller - COUNTERS & TIMERS
Almost all micro controllers have one or more inbuilt counters. They are either 8 bit or 16 bit counters. The input for the counters may be from either external pins or internal system clock through pre-scalars. The current counter value is always saved to a register in the micro-controller and may directly access the value at any time.
Delay is one of the commonly used timer function, which is single use timer and not so accurate when compared to the internal programmed timers. Delay works on counting the ticks of micro-controller system clock frequency.
For programming as internal counter, the counter should receive signal from system clock frequency through pre-scalar circuit. The pre-scalar divides the system clock frequency by the value set in the pre-scalar register.
In case, the counter register is full (i.e., exceeds its capacity), then it resets and starts counting again. An Interrupt may be activated when the particular counter register is full and resets, which calls COUNTER OVERFLOW SERVICE ROUTINE. Every time the counter is full or overflown, the Interrupt service routine is called, where you may program do specific tasks. This Interrupt is very useful to get exact and fixed time period, to do some specific operations in loop at a particular time period. These are called Timers in micro-controllers.
These timers are used for data aquisition system, frequency generation, wave form generation etc.