8.2 Introduction: 89C51 microcontroller has built-in two 16-bit timers which can
ID: 3777778 • Letter: 8
Question
8.2 Introduction:
89C51 microcontroller has built-in two 16-bit timers which can be used for different applications like creating delays, baud rate generators, etc. These timers can also be used as event counters.
When activated, these Timers/Counters increment once for each event. An event can be related to the system clock (Timer) or from an external logic signal transition (Counter).
The “Timer” or “Counter” function is selected by control bits C/T in the Special Function Register (SFR) TMOD (Timer MODe). These Timers/Counters have four operating modes, which are selected by bit-pairs (M1, M0) in TMOD.
During the transition from its maximum possible count of FFFFH (65535) to 0000H (rolls over from all 1s to all 0s), it sets the overflow flag TFx, where x is 0 or 1 for Timer 0 or Timer 1, respectively.
TMOD register is not bit-addressable. It is loaded, generally, by the software at the beginning of a program to initialize the timer mode.
GATE C/T M1 M0 GATE C/T M1 M0
Timer 1 Timer 0
Figure 8.1: TMOD Register
C/T: Set for counter operation, reset for timer operation.
GATE: Permits INTx pin to enable/disable the counter. For normal operation, this should be 0.
M1, M0: To Select the Mode
0 0 : Mode 0 - 13-bit timer mode (Emulates 8048).
0 1 : Mode 1 - 16-bit timer mode.
1 0 : Mode 2 - 8-bit auto-reload mode.
1 1 : Mode 3 - Split timer mode (only Timer 0 is used as two 8-bit timers while Timer 1 can be used for other purposes like Baud rate generation).
As all the registers of 89C51 microcontroller are 8-bit. The 16-bit Timers/Counters are built by cascading two 8-bit registers. This cascading is done automatically by hardware; user has to just select the mode. These registers are called as TLx and THx where L stands for low and H stands for high byte of 16-bit register.
These Timers/Counters can count up only and can be preset to any value so that any time or count limit can be set up. For example, to time or count 100 events, the registers THx and TLx should be loaded with the number 65535 – 100 + 1 = 65436 (FF9CH). So after 100 events, it will roll over from all 1s to all 0s and sets the overflag TFx.
Mode 2 (8-bit auto-reload mode) is the best mode for counting less than 256 events. Only in this mode you don’t have to load the timer register with the initial (preset) values every time when it starts a new loop. In other modes, the timer registers must be initialized with values every time when it starts a new loop.
What is the best mode for a timer to be used for counting 400 events?
GATE C/T M1 M0 GATE C/T M1 M0
Explanation / Answer
A timer could be a straightforward counter! The input clock of microcontroller and operation of the timer is freelance of the program execution.All the Atmel microcontrollers have Timers as associate constitutional peripheral. during this tu our focus is on ATmega8 microcontroller. ATmega8 comes with 2 8-bit and one 16-bit timer. this suggests that there ar three sets of timers, every with the flexibility to count at totally different rates.
The two 8-bit counters will count to 255 while the 16- bit counter will count to sixty five,536. we have a tendency to learned that the only timer in Atmeag8 is TIMER0 with associate 8-bit resolution (0-255). Timers will run asynchronous to the most AVR core thence timers ar entirely freelance of central processing unit. A timer is sometimes such as by the most price to that it will count, on the far side that it overflows and resets to zero.
Speed of the enumeration is controlled by variable the speed of clock input to that. As we know, all the componets of a microcontroller unit (MCU) ar in some manner connected to the central process unit (CPU) and a few registers, to share info beween them. Next, i'm discussing concerning few of the Registers in TIMER0 of ATmega8 intimately. this is often infact a sequel of the previous part!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.