Timers

There are two timers in 8051 microcontroller. Timers are used for the following purposes

  1. For events counting.
  2. To calculate event duration time.
  3. For delay time calculation.

How Timers of 8051 Count?

Each timer has it’s own two 8 bit registers for counting that make 16 bits for count as a whole. These registers are TH0, TL0 for timer 0 and TH1, TL1 for timer 1. Each timer counts one on each machine cycle. We know that 1 machine cycle is of 12 oscillator cycles. It means clock given to timer is

Timer Clock = Oscillator clock / 12

If oscillator

Modes of Operation of 8051 Timers

In 8051 each timer has following modes of operation

  1. 16 Bit Mode
  2. 13 Bit Mode
  3. 8 Bit Auto Reload Mode
  4. Split Timer Mode

1. 16 Bit Mode

In this mode timer uses all 16 bits for counting and maximum counting figure is 65535 (0xffff in hex). When timer try to count next to 65535 (0xffff) it is reset to 0 and timer overflow flag is set and if corresponding timer interrupt is enabled then interrupt service routine for that timer is called and executed. We can adjust timer start value other than default 0 value between 0 to 65535 in the interrupt service routine or when we recognize that overflow has occurred. But in this way there may be some error in calculation as instructions to load interrupt service routine will also take some timer counts during their calling and loading.