Dlloydev / QuickPID

A fast PID controller with multiple options. Various Integral anti-windup, Proportional, Derivative and timer control modes.
MIT License
195 stars 50 forks source link

millis() overflow problem. #52

Closed qnxsgwy closed 1 year ago

qnxsgwy commented 2 years ago

"if (msNow > nextSwitchTime) { nextSwitchTime = msNow + debounce;" is used in the PID_RelayOutput example, When nextSwitchTime overflows, the comparison results for the next cycle will be wrong.

//should use if(millis() - lastMillis >= interval){ //and NOT like if(millis() >= lastMillis + interval){

Dlloydev commented 2 years ago

Thank you for pointing this out. Even though the effect is very minimal on the output, I'll take a look at updating the function to prevent the overflow issue.

Dlloydev commented 1 year ago

Converting this to discussion. Will do some additional testing and possible update for a future release.