Go Down

Topic: Long delay (Read 5274 times) previous topic - next topic

Savers

I've looked at the blink without delay method, but I'm not sure how good it is for a long delay.

I need to trigger something every 7 hours, which converts to 25 200 000 milliseconds. I also have 1 sec delays in my code which I assume will also affect the accuracy of the milliseconds.

Any recommendations for which way I should approach this?

Msquare

Code: [Select]
delay(25200000)  // :)It is ok, there is room for 4 294 967 296 milliseconds - it is a unsigned long parameter.

If you need to have both a one second and a 7 hour, then use the method outlined i the NoDelayBlink, where you loop and check if milli() has increased 25200000 since you last "fired" the 7 hour code. And this will be acurate, evn if your 7 hour code takes minutes of CPU time (the milli() stuff increments via a timer interrupt)

The acuracy is limited by the crystal. It will be in the same ballpark accuracy wise as any ordinary watch.

Savers

#2
Jan 20, 2011, 07:22 pm Last Edit: Jan 20, 2011, 07:23 pm by Savers Reason: 1
I have quite a few delay functions in my code, all switching relays and such, which are all going to put the milliseconds way out of line. I think it would be possible to tap these into the no delay code, but would be very time consuming!

I have seen the ibutton RTC used in quite a few applications, would this be worth looking into?

AWOL

You may want to add the 'UL' suffix to constants.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Savers

I just ran a short test and it turns out the delay functions don't really interfere much with the millisecond counts. For every 60 seconds, its out by around 0.5 second.

Which equates to 210 seconds every 7 hours. Which is a perfectly acceptable ratio for my uses.

Many thanks chaps, top banana.

dania25

Why don't you use the aiko events library? I find it to be very easy to use.  It also makes the code look neater (I think anyway).

Go Up