diff --git a/adafruit_ticks.py b/adafruit_ticks.py index 5585d2b..3efb0ad 100644 --- a/adafruit_ticks.py +++ b/adafruit_ticks.py @@ -122,7 +122,9 @@ def ticks_ms() -> int: def ticks_add(ticks: int, delta: int) -> int: "Add a delta to a base number of ticks, performing wraparound at 2**29ms." - return (ticks + delta) % _TICKS_PERIOD + if -_TICKS_HALFPERIOD < delta < _TICKS_HALFPERIOD: + return (ticks + delta) % _TICKS_PERIOD + raise OverflowError("ticks interval overflow") def ticks_diff(ticks1: int, ticks2: int) -> int: