top of page

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.

If the counter is programmed for external input, then the counter register may either increase or decrease by 1, by changing the logic (voltage) at the programmed pin of micro controller.  You can access the value in the register and may show on a displaying device.  This type of programming is useful for event counter project etc.  In case, the counter is read for every one second and reset to zero after reading the current value, then the programming may be used as frequency counter project.

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.

bottom of page