Pages: [1]   Go Down
Author Topic: Millis goes back to zero after 50 days, what happens to delay()??  (Read 346 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am going to use Arduino to make a pump protection, such that the pump does not burn itself up if the water is frozen, the pump clocked etc.

This will be done by measuring the current, issuing short delays, measuring again, another delay. From these measurements I will compute the current power supplied to the pump, and if it exceeds safe levels cut the supply voltage.

Now, the documentation tells me that the millis function goes back to zero about every 50 days. What happens to a delay that is issued before the function millis goes to zero again, but which would have expired after the reset. It seems such a delay would never terminate.

Very much interested in light on this issue! (Rather than having to analyze why pumps blew up every now and then).

Is it possible to reset the millis timer through code (say once a month)?

Thanks, peter
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3382
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nothing. Delay() works fine even between rollover.
Logged

UK
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nothing. Delay() works fine even between rollover.
Unless you try to delay for 52 days smiley-wink
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Croatia
Offline Offline
God Member
*****
Karma: 13
Posts: 508
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can check if current millis is smaller than on the previous occasion you checked.
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3382
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nothing. Delay() works fine even between rollover.
Unless you try to delay for 52 days smiley-wink
It will delay for 2 days, so It would still work, just not as intended.  smiley-razz
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 114
Posts: 4258
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nothing. Delay() works fine even between rollover.
Unless you try to delay for 52 days smiley-wink
In which case it would be better to turn off the Arduino and use a calendar instead  smiley
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

UK
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nothing. Delay() works fine even between rollover.
Unless you try to delay for 52 days smiley-wink
In which case it would be better to turn off the Arduino and use a calendar instead  smiley
But the 9V PP3 battery in my calendar runs out before then...
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

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

No one sees to have asked why the OP is using "delay()".
So, here goes: Why?
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.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18800
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Now, the documentation tells me that the millis function goes back to zero about every 50 days. What happens to a delay that is issued before the function millis goes to zero again, but which would have expired after the reset. It seems such a delay would never terminate.

The correct technique is to note the current time (in an unsigned long) eg. when you turn the motor on.

eg.

Code:
unsigned long motorOnTime;

...

motorOnTime = millis ();

Then you check, using subtraction, if that time is up. That works, even after millis rolls over. Don't attempt to reset millis.

eg.

Code:
 if ( (millis () - motorOnTime) >= timeToRun)
    {
    // turn motor off
    }

In this case you set up timeToRun to be the time you want it on (in milliseconds). If you do this in the main loop you are not "blocking" (with delay) and can thus do other things, like check other motors, switch presses, etc.
Logged


Pages: [1]   Go Up
Jump to: