chumicro-timing¶
Cross-runtime millisecond tick helpers and periodic timing for CircuitPython, MicroPython, and CPython.
Capture ticks_ms() once per pass through your loop and hand it to a Rate (a drift-free periodic cadence) or a Deadline (a single armed timeout). Both are built on wrap-safe tick arithmetic, so the counter rollover on a board that has been up for weeks changes nothing. All timing is non-blocking: nothing on the device path calls time.sleep() (the host-test sleep_ms shim in chumicro_timing.testing is the one exception, and it never deploys).
Quick example¶
from chumicro_timing import Rate, ticks_ms
rate = Rate(1000, ticks_ms())
while True:
now = ticks_ms()
if rate.due(now):
print("one second elapsed")
# ... do other work ...
Documentation¶
- User Guide: periodic cadence with
Rate, sharing one timestamp across a loop, deadlines, choosing a wait, using the tick helpers directly, wraparound details, pairing withchumicro-runner - API Reference: the wrap-safe
ticks_ms/ticks_diff/ticks_addhelpers, theDeadlineandRatevalue objects, and theSignal/wait_forwait vocabulary - Testing Helpers: using
FakeTicksin your tests