TMOD (Timer Mode Register)
The TMOD (Timer Mode Register) is a special function register in the 8051 microcontroller. Timer 0 and Timer 1 are the modes of operation that it is utilized to set. Whether a timer or counter needs to be set, it is done so using this register. The structure in detail is displayed below.
Structure of TMOD Register
The eight bits of the TMOD register are split into two sections: Timer 0 is controlled by the lower four bits, and Timer 1 is controlled by the upper four bits. Similar bit fields in each component set the timers’ mode and behavior.
Here’s what each bit represents:
Bit |
Bit Name |
Description |
---|---|---|
7 or 3 |
Gate (0 or 1) |
Gate Control Bit |
6 or 2 |
C/Tx |
Counter/Timer Select Bit |
5 or 1 |
TxM1 |
Timer Select Bits for Mode1 |
4 or 0 |
TxM0 |
Timer Select Bits for Mode0 |
Let’s see each bit’s one by one,
- GATE (Gate Control Bit): When set to 1, the timer/counter is enabled only while the INT pin is high and TR control bit is set. When cleared to 0, the timer is enabled whenever the TR control bit is set.
- C/T (Counter/Timer Select Bit): When set to 1, the timer operates as a counter (counts external events). When cleared to 0, it operates as a timer (measuring time).
- M1 and M0 (Mode Select Bits):
M0 |
M1 |
Mode |
Description |
---|---|---|---|
0 |
0 |
Mode 0 |
13-bit Timer mode (8 Bit of THx and 5 Bit of TLx). |
0 |
1 |
Mode 1 |
16-bit Timer mode. |
1 |
0 |
Mode 2 |
8-bit Auto-reload mode (TLx reload with the THx value each time when TLx overflows). |
1 |
1 |
Mode 3 |
Split Timer mode – Split 16 bit timer into two 8 bit timers(THx and TLx). |
8051 Timers and Counters
8051 microcontrollers are mainly used to speed up our tasks because they are very easy to use and they are also fast to complete tasks easily. These microcontrollers have one main feature which is Timers and counters. This feature is widely used in microcontrollers to measure the time and as well as to count the events or tasks. By learning about these timers and counters ,we can make good embedded systems. In this article let us see how these counters and timers work in microcontrollers.
Table of Content
- 8051 Timers and Counters
- Types
- What is Timer 0 (T0) ?
- What is Timer 1 (T1) ?
- TCON and TMOD
- Timer Counter Modes
- What is Counter Mode ?