Pages: [1]   Go Down
Author Topic: Long delay  (Read 4879 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 1
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 33
Posts: 1228
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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.
Logged

0
Offline Offline
Newbie
*
Karma: 1
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: January 20, 2011, 01:23:06 pm by Savers » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26631
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You may want to add the 'UL' suffix to constants.
Logged

"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.

0
Offline Offline
Newbie
*
Karma: 1
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Singapore
Offline Offline
Newbie
*
Karma: 4
Posts: 25
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

Pages: [1]   Go Up
Jump to: