On 3/14/06, Timothy Smith <address@hidden> wrote:
can anyone explain in simple terms how i can calculate the time it will
take for the timer overflow interrupt to trigger using the prescaler? i
have had success in writing my own little programs to make various
led's blink etc but doing this in terms of seconds or minutes still
escapes my grasp of the concept.
The timer runs at Xtal/Prescaler ticks/sec
If you have a 4 mhz oscillator, and use /64 prescaler, then each tick is
(1/4000000)*64 sec or 16uS
What I do in most apps, is set up T0 for a 1mS overflow int, and do all my timekeeping from that. If a task wants a 100mS delay, then it loads 100 into an sram byte, which is decremented to 0 by the T0OV ISR. The ISR picks up each timer byte, and if it's non-zero, decrements it, and stores back to SRAM.
You can implement delays as large as you like with this scheme, since the ISR can also have variables that it uses to generate 100mS intervals, 1S, 1 minute, 1 hour...