Q10Microprocessor
Question
Q.10. Differentiate between Timers and Counters. Draw the diagram of TCON in 8051.
Answer
A timer counts internal clock (machine cycle) pulses to measure elapsed time, while a counter counts external pulses applied to the T0/T1 pins to count external events; both functions are configured and controlled via the TCON register, which contains the run-control bits (TR0, TR1) and overflow flags (TF0, TF1) for both timers.
A timer, in the 8051's Timer 0/Timer 1 hardware, is configured (via the C/T bit in the TMOD register) to increment automatically once per machine cycle, driven by the internal oscillator clock — since the machine cycle duration is fixed and known (12 oscillator periods), counting a known number of machine cycles directly corresponds to measuring a known, precise elapsed time interval, making this configuration suited to generating accurate time delays or measuring the duration of events. A counter, by contrast, is configured (via the same C/T bit, set to the opposite state) to increment once for each high-to-low transition detected on the corresponding external T0 or T1 input pin, rather than on the internal clock — this configuration is suited to counting the number of occurrences of some external event (pulses from a sensor, rotations of a shaft, etc.) rather than measuring elapsed time.
The Timer/Counter Control register (TCON) contains, among other bits, TR0 and TR1 (Timer Run control bits, which the software sets to 1 to start the respective timer/counter and clears to 0 to stop it) and TF0 and TF1 (Timer Overflow flags, automatically set by hardware when the respective 16-bit timer/counter register overflows from FFFFH back to 0000H, which can trigger a Timer interrupt if enabled, or be polled directly in software).
TCON bit layout (bit 7 to bit 0): TF1 (Timer 1 overflow flag), TR1 (Timer 1 run control), TF0 (Timer 0 overflow flag), TR0 (Timer 0 run control), IE1 (External Interrupt 1 edge flag), IT1 (External Interrupt 1 type select — level or edge triggered), IE0 (External Interrupt 0 edge flag), IT0 (External Interrupt 0 type select).