1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-26 17:46:14 +01:00

fix power change timer micros overflow

This commit is contained in:
Harald Barth 2023-06-19 00:33:53 +02:00
parent f83be05220
commit 6dd175f63b
2 changed files with 5 additions and 4 deletions

View File

@ -1 +1 @@
#define GITHUB_SHA "devel-202306181725Z" #define GITHUB_SHA "devel-202306182233Z"

View File

@ -190,9 +190,10 @@ class MotorDriver {
// was really long ago (approx > 52min) advance counter approx 35 min so that // was really long ago (approx > 52min) advance counter approx 35 min so that
// we are at 18 minutes again. Times for 32 bit unsigned long. // we are at 18 minutes again. Times for 32 bit unsigned long.
inline unsigned long microsSinceLastPowerChange() { inline unsigned long microsSinceLastPowerChange() {
unsigned long diff = micros() - lastPowerChange; unsigned long now = micros();
if (diff > (1UL << (6 *sizeof(unsigned long)))) unsigned long diff = now - lastPowerChange;
lastPowerChange += 1UL << (4 * sizeof(unsigned long)); if (diff > (1UL << (7 *sizeof(unsigned long)))) // 2^(4*7)us = 268.4 seconds
lastPowerChange = now - 30000000UL; // 30 seconds ago
return diff; return diff;
}; };
#ifdef ANALOG_READ_INTERRUPT #ifdef ANALOG_READ_INTERRUPT