Pages: 1 [2]   Go Down
Author Topic: Alternative to millis()  (Read 1004 times)
0 Members and 1 Guest are viewing this topic.
Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 50
Posts: 1766
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

An alternative to using millis, etc. is to use a real time clock.  You can get real time clock boards at various places that sit on the i2c bus.  Most have optional coin battery holders, so the clock can keep time, even if the Arduino is not powered.  In addition, most of these RTC devices can be programmed to raise a pin high at a particular time, so you would attach that to an input pin.  If your device mostly waits for the next event, you can hook the rtc input to one of the pins that you can attach an interrupt to, and have the Arduino go to sleep to save battery power, until the RTC raises the signal, and wakes up the Arduino.  If you need accuracy, you can get RTC's that adjust for the temperature (based on the DS3231 chipset).  One that I've seen on ebay (but have not bought) is http://www.ebay.com/itm/DS3231-AT24C32-IIC-High-Precision-RTC-Module-Clock-EEPROM-Memory-Module-Arduino-/161078687764?pt=LH_DefaultDomain_0&hash=item258109b814.

If you are using a device with GPS chips, note that you will get extremely accurate time from the GPS, when you have the GPS enabled, but I'm not sure whether GPS receivers have an alarm function like the RTC chips.  So you would have to employ the method used by kids on long car trips (repeatily asking are we there yet?)
« Last Edit: September 17, 2013, 08:05:34 am by MichaelMeissner » Logged

UK
Offline Offline
Shannon Member
****
Karma: 183
Posts: 11154
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

By my reckoning, nine hours is about how long it would take to overflow a signed int that was being incremented once a second. If that's the technique you're using for counting the passage of time, you're doing it wrong.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think I've found the bug.
There was a fragment in the code:

Code:
long percent = 100*(millis() - switchtime[z]);

Where switchtime is a massive of unsigned long, which stores millis() values. So in ~12 hours, the value of 100*millis() becomes too large to store as long. (don't tell me about millis() being an unsigned long, I already know that smiley-grin )

Thank you guys.
« Last Edit: September 18, 2013, 04:18:38 am by Q109 » Logged

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

Thanks for getting back with that.

Now, hopefully you can see why we ask you to post code.
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.

Pages: 1 [2]   Go Up
Jump to: