Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4829

MicroPython • Re: Logging temp to SD card, missing data

$
0
0
Thanks, I'll try ticks as well. I didn't like that the documentation said that it could rollover, though.
Hey, nothing like a timely response … but I thought I had a nice simple explainer for ticks_*() and ticks_diff(). Things got very weird when I tried other platforms, though, and I may have to launch some Issues at the MicroPython team once I get everything straight in my head.

Briefly:
  • time.ticks_us() and time.ticks_ms() both roll over at 2³⁰ (= 1,073,741,824). That's 00:17:53.74 for ticks_us() and 12 days, 10:15:41.82 for ticks_ms(). Both seem to (but aren't guaranteed to) start at zero on power-on.
  • time.ticks_diff() provides a reliable delta between two ticks values, even allowing for rollover. With one caveat: the delta must be less than 2²⁸ (= 268,435,456). That's 00:04:28.44 for µs and 3 days, 02:33:55.46 for ms
  • time.time() is typically an integer second value, usually starting at zero on power-on. If the RTC is set, an epoch is applied: 1970-01-01 for the Raspberry Pi Pico (but 1990-01-01 for some other boards, including those from Espressif).
Because MicroPython uses a garbage collector to clean up memory, it can sometimes introduce small delays into program operation. Consequently, I wouldn't go too close to the 2²⁸ limit for ticks_diff() for reliable operation.

If you need to schedule longer periods, there's a MicroPython Schedule module, both in asyncio (cooperative multitasking framework) and standalone versions. Don't change the RTC while running schedules or asyncio: it will do some very unexpected things.

Statistics: Posted by scruss — Tue Dec 03, 2024 12:41 pm



Viewing all articles
Browse latest Browse all 4829

Trending Articles