Texas Instruments MSC1210 User Manual

Page 237

Advertising
background image

Timers

17-9

Keil Simulator

Every time the idle loop is interrupted, the MSC1210 vectors to the ISR of the
interrupting signal. If the interrupt source is the Timer 0 overflow, the processor
vectors to the interrupt_timer 0 ( ) ISR, where the timer_0_overflow_count vari-
able is updated, and the TH0:TL0 register pair is replenished with a value of
0x0200. If the external Interrupt 0 signal is the interrupt source, the inter-
rupt_external 0 ( ) is vectored to. This ISR keeps track of even and odd ISR
calls. For odd number of ISR calls, Timer 0’s TR0 bit is set, preparing the timer
to start running as soon as the INT0 line is raised. For even number of calls,
the ISR resets the TR0 bit for Timer 0. This will stop Timer 0 from timing, wheth-
er the INT0 line is asserted or not. In addition, the value of end_test is changed
to 1, so that upon re-entering the idle loop, the value of end_test is no longer
0, which forces the processor out of the loop.

Upon terminating the idle loop, the MSC1210 starts to compute the time lapse
within the period when the INT0 line was asserted and the Timer 0 TR0 bit was
high, or the time between the period when TR0 and INT0 were high, and TR0
went low. This is purely arithmetic. It is important to state that TH0 and TL0 nev-
er start at zero, hence the 0x0200 correction.

time_lapse

+

ǒ

timer_0_overflow

)

current_count

*

0x0200

(0x10000

*

0x0200)

Ǔ

@

12

@

(0x10000

*

0x0200)

24

@

10

6

The result of the pulse width computation is displayed on the Serial #1 display
window.

Subsequently, the MSC1210 enters an infinite loop.

void main ( )

{

float

time_lapse, time_lapse_residual, current_count;

SP = 0x50;

//Initialize Stack Pointer

setport ( );

//Set up UART Comm. b/w Simulator and Serial #1Window

//Issue operation instructions

printf (”\nMSC1210 Ver:”);

printf (”\nTimer 0 & 1 Test\n”);

printf (”\nActivate the Timers 0 & 1 peripherals.”);

printf (”\nClear the Check Box for INT0. This is a Gated timer.”);

printf (”\nTo arm the Timer 0, Clear the Check on INT1.”);

printf (”\nTiming begins when a Check is placed on INT0.”);

printf (”\nTiming ends either by clearing INT0 or Interrupting on INT1.”);

//Make INT1 edge triggered

TCON |= 0x04;

//this global variable track the number of times the Timer 0 timed out

timer_0_overflow_count = 0;

//track even or odd number of calls to ISR interrupt_external0

Advertising