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

delay might fail after ~50days runtime #42

Open
VeryPrivat opened this issue Oct 7, 2018 · 2 comments
Open

delay might fail after ~50days runtime #42

VeryPrivat opened this issue Oct 7, 2018 · 2 comments

Comments

@VeryPrivat
Copy link

Analyzing your code shows following problem in line 195 of TimeAlarms.cpp:

  • millis() will overrun after 49,7 days since it is an unsigned long (4.294.967.295 / 86.400.000 [ms/day] = 49,710 days)
  • If start + ms is bigger than 4.294.967.295 calculation of millis() - start will never reach the value of ms => While loop will never end
@tonilopezmr
Copy link

@VeryPrivat @b4dnewz @crisap94 is this already fixed?

@b4dnewz
Copy link

b4dnewz commented Nov 30, 2019

@tonilopezmr I don't know, I don't even know if is a real issue

When using subtraction on unsigned integers. the subtraction will automatically handle it.
millis() - startTime >= interval Lets try it using byte to make the math easier
10 - 245 >= 20 Millis() has just rolled over startTime was before rollover
if you start at 10 count back to 0 then 255 on down you will see that the answer is exactly 20.
subtraction will always give the right answer when using unsigned integers hence no problems with rollover.

source; https://forum.arduino.cc/index.php?topic=543895.0

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

3 participants