Texas Instruments MSC1210 User Manual

Page 81

Advertising
background image

Using Timers to Measure Time

8-7

Timers

When the timer is in 13-bit mode, TLx will count from 0 to 31. When TLx is in-
cremented from 31, it will roll over to 0 and overflow into THx, thus increment-
ing it. Therfore, only 13 bits of the two timer bytes are being used: bits 0 to 4
of TLx, and bits 0 to 7 of THx. This also means the timer can only contain 8192
values. If you set a 13-bit timer to 0, it overflows back to zero 8192 instruction
cycles later.

There is very little reason to use this mode and it is only mentioned so there
will be no surprise if ever analyzing archaic code that has been passed down
through the generations.

8.3.3.2

16-Bit Time Mode (mode 1)

Mode 1 operates in the same manner as mode 0, except Timer 0 or Timer 1
is configured as a 16-bit timer/counter. The timer/counter uses all 8 bits of both
the TLx register and THx register for the 16-bit register.

When the timer/counter rolls over on a transition from 0FFFF

H

, the timer/counter

interrupt flag is set (TCON.TFx).

Timer mode 1 is a 16-bit timer. This is a very commonly used mode. It functions
just like 13-bit mode, except that all 16 bits are used.

TLx is incremented from 0 to 255. When TLx is incremented from 255, it resets
to 0 and causes THx to be incremented by 1. The timer may contain up to
65 536 distinct values because this is a full 16-bit timer. If a 16-bit timer is set
to 0, it will overflow back to 0 after 65 536 machine cycles.

8.3.3.3

8-Bit Auto-Reload Time Mode (mode 2)

Timer mode 2 is an 8-bit auto-reload mode. When a timer is in mode 2, THx
holds the reload value and TLx is the timer itself.

TLx starts counting up. When TLx reaches 255 and is subsequently increm-
ented instead of resetting to 0 (as in the case of modes 0 and 1), it will be reset
to the value stored in THx.

For example, TH0 holds the value FD

H

and TL0 holds the value FE

H

.

Table 8−3 shows what would occur if the values of TH0 and TL0 are viewed
for a few machine cycles.

Table 8−3. Example of 8-Bit Auto-Reload

Instruction

Cycle

TH0

Value

TL0

Value

1

FD

H

FE

H

2

FD

H

FF

H

3

FD

H

FD

H

4

FD

H

FE

H

5

FD

H

FF

H

6

FD

H

FD

H

7

FD

H

FE

H

Advertising