Using Timers to Measure Time

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.216-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 0FFFFH, 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.38-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 FDH and TL0 holds the value FEH. 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

TH0

TL0

Cycle

Value

Value

 

 

 

1

FDH

FEH

2

FDH

FFH

3

FDH

FDH

4

FDH

FEH

5

FDH

FFH

6

FDH

FDH

7

FDH

FEH

Timers8-7

Page 81
Image 81
Texas Instruments MSC1210 manual 3. Example of 8-Bit Auto-Reload, Instruction, Cycle