Skip to content

Is there an Overflow in PID_RelayOutput.ino? #130

@rtek1000

Description

@rtek1000

Hello,

I noticed that the sum of the value in the windowStartTime variable occurs, but it seems to me that it is not restarted, so in a moment it seems to overflow.

PID_RelayOutput.ino:

  if (millis() - windowStartTime > WindowSize)
  { //time to shift the Relay Window
    windowStartTime += WindowSize;
  }

Based on the Blink code, the variable can be set using the value of millis(), this way it must always have a value within the operating range:

  if (millis() - windowStartTime > WindowSize)
  { //time to shift the Relay Window
    windowStartTime = millis();
  }

Ref.:

  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
   [...]
  }

https://docs.arduino.cc/built-in-examples/digital/BlinkWithoutDelay

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions