Intel Embedded Microcontroller, 8XC251SA, 8XC251SP, 8XC251SQ manual Pulse Width Measurements, Timer

Models: Embedded Microcontroller 8XC251SP 8XC251SA 8XC251SQ 8XC251SB

1 458
Download 458 pages 25.38 Kb
Page 144
Image 144

8XC251SA, SB, SP, SQ USER’S MANUAL

3.Enter an eight-bit reload value (nR) in register TH0. This can be the same as n0 or different, depending on the application.

4.Set the TR0 bit in the TCON register (Figure 8-6) to start the timer. Timer overflow occurs

after FFH + 1 - n0 peripheral cycles, setting the TF0 flag and loading nR into TL0 from TH0. When the interrupt is serviced, hardware clears TF0.

5.The timer continues to overflow and generate interrupt requests every FFH + 1 - nR peripheral cycles.

6.To halt the timer, clear the TR0 bit.

8.5.2Pulse Width Measurements

For timer 0 and timer 1, setting GATEx and TRx allows an external waveform at pin INTx# to turn the timer on and off. This setup can be used to measure the width of a positive-going pulse present at pin INTx#. Pulse width measurements using timer 0 in mode 1 can be made as follows:

1.Program the four low-order bits of the TMOD register (Figure 8-5) to specify: mode 1 for

timer 0, C/T0# = 0 to select FOSC/12 as the timer input, and GATE0 = 1 to select INT0 as timer run control.

2.Enter an initial value of all zeros in the 16-bit timer register TH0/TL0, or read and store the current contents of the register.

3.Set the TR0 bit in the TCON register (Figure 8-6) to enable INT0.

4.Apply the pulse to be measured to pin INT0. The timer runs when the waveform is high.

5.Clear the TR0 bit to disable INT0.

6.Read timer register TH0/TL0 to obtain the new value.

7.Calculate pulse width = 12 TOSC × (new value - initial value).

8.Example: FOSC = 16 MHz and 12TOSC = 750 ns. If the new value = 10,00010 and the initial value = 0, the pulse width = 750 ns × 10,000 = 7.5 ms.

8.6TIMER 2

Timer 2 is a 16-bit timer/counter. The count is maintained by two eight-bit timer registers, TH2 and TL2, connected in cascade. The timer/counter 2 mode control register (T2MOD, as shown in Figure 8-11 on page 8-16) and the timer/counter 2 control register (T2CON, as shown in Figure 8-12 on page 8-17) control the operation of timer 2.

8-10

Page 144
Image 144
Intel Embedded Microcontroller, 8XC251SA, 8XC251SP, 8XC251SQ, 8XC251SB manual Pulse Width Measurements, Timer