Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/20/04 11:35
Read: times


 
#81568 - Timer Event Detection
Responding to: ???'s previous message
I'm not too sure of what your problem is, but anyhow....

You haven't shown us the values used to initialise the timer (TMOD,TCON).

The timer does continue to run after overflow - the TF1 flag tells us that is has overflowed.

//In the last i want to check that Timer1 has counted 50
//millisecond interval
if(TF1 == 0)
{
//do some processing here at every 50 milliseconds


Don't you want to wait until the timer has overflowed?

while (TF1 == 0) {}; //wait here until 50mS has elapsed
// execute code
// reload the timer


Normally if I want to add timer functions into my code (almost certainly), I use a timer to generate a periodic interrupt. This interrupt is normally around 10mS. In the interrupt routine you can decrement a value (or many values) down to 0.

timer1_isr:
{
TR1 = 0;
//reload timer with 10mS (or whatever)
TR1 = 1;

if (timer1_val)
{
timer1_val--;
}
if (timer2_val)
{
timer2_val--;
}
}

In your mainline code:

timer1_val = 5; //5 * 10 = 50mS
..
..
..
..
if (timer1_val == 0)
{
//execute routine every 50mS
timer1_val = 5; //5 * 10 = 50mS
}

I hope this explains the technique.






}










List of 2 messages in thread
TopicAuthorDate
Timer event detection            01/01/70 00:00      
   Timer Event Detection            01/01/70 00:00      

Back to Subject List