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

Overflow of "now" variable after 50 days? #71

Open
SeanDS opened this issue Nov 10, 2018 · 0 comments
Open

Overflow of "now" variable after 50 days? #71

SeanDS opened this issue Nov 10, 2018 · 0 comments
Labels

Comments

@SeanDS
Copy link

SeanDS commented Nov 10, 2018

In src.ino, the variable now is set to the result of millis(). The Arduino documentation for this function states:

This number will overflow (go back to zero), after approximately 50 days.

I think this has an effect on the RF reset timeout and sample checks:

if ((now - last_rf_rest) > RF_RESET_PERIOD)
if ((now - last_sample) > TIME_BETWEEN_READINGS)

I think that after now overflows, the checks above will always result in false until now again reaches the time of the last last_rf_rest and last_sample times before the overflow, i.e. around once every 50 days. That means that from power-on, the board will reset the RF module and make samples every RF_RESET_PERIOD and TIME_BETWEEN_READINGS milliseconds, until ~50 days have past, then only make samples and reset the RF module every 50 days.

Maybe I've misunderstood how this works in the C/AVR/Arduino world, but I thought I'd point it out in case this is a bug.

A potential fix could simply be to put this before the two checks above:

  // Check if now has overflowed.
  if (now < last_sample || now < last_rf_rest) {
    // Assume now has overflowed, so reset variables that are checked against now.
    last_rf_rest = 0;
    last_sample = 0;
  }
@TrystanLea TrystanLea added the bug label Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants