On Mar 18, 2006, at 8:52 PM, OWEN-A wrote:
> I need to generate delays of up to 24 hours on a Mega16 has anyone
> any suggestions, I could use an RTC but there may be another option
> as strict timekeeping is not necessary for this application.
As others have said, implement a timer overflow counter. RTC hardware
is a PITA and totally unnecessary. Pick any timer that you don't
reset. Size your counter according to how long of an interval you
wish to measure.
Then I suggest rather than counting overflows, you subtract the
overflows from your "software timer" variable. So when you wish to
know when 24 hours has elapsed you preload 24 hours worth of
overflows in the variable. When it reaches zero, time is up!
Make sure you catch it reaching zero by only decrementing non-zero
values:
Put this in your hardware timer overflow IRQ service routine:
if( my_24_hour_timer )
my_24_hour_timer--;
If my_24_hour_timer is larger than 8 bits (most likely) wrap it in cli
()/sei() when testing outside of an IRQ service routine so that the
value doesn't change in the middle of your compare. Is also best to
declare "volatile" to ensure the compiler doesn't optimize out the
reloading of my_24_hour_timer every time thru your loop.
cli();
if( my_24_hour_timer == 0 ) {
sei();
do_the_24_hour_thing();
}
sei(); // doesn't hurt to have an extra sei()
--
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.Message
Re: [AVR-Chat] Long delays
2006-03-19 by David Kelly
Attachments
- No local attachments were found for this message.