Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

millis() wrap #4

Open
irekzielinski opened this issue Nov 30, 2016 · 1 comment
Open

millis() wrap #4

irekzielinski opened this issue Nov 30, 2016 · 1 comment

Comments

@irekzielinski
Copy link

irekzielinski commented Nov 30, 2016

After 49 days of running, millis() wraps and SimpleTimer logic will be broken (will fire at wrong time).
Check for this condition is needed.

for example:

        if (current_millis - prev_millis[i] >= delays[i]) {

if:
prev_millis[0] == 4,294,967,290 (just 5 mills from wrap over)
current_millis == 1 (just after wrap over)

"if" statement above will be satisfied for almost any delays[0] value.
this will lead to timer being fired pre-maturely

@yunjova
Copy link

yunjova commented Mar 27, 2017

The solution is to use "unsigned long" for all variables in the equation that checks the elapsed time against the wanted expiry time (if (current_millis - prev_millis[i] >= delays[i]) {).
So delays must also be unsigned long. See also: http://playground.arduino.cc/Code/TimingRollover.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants