Skip to content

Slow time on micro:bit V1 and V2 #225

Open
@kevinjwalters

Description

@kevinjwalters

I've observed that time is slow in micropython on the micro:bit V1 and V2 using v1.18 from https://python.microbit.org/v/3

This program using sleep runs for longer than 100 seconds.

from microbit import sleep

sleep(15 * 1000)
pause_ms = 100 * 1000

count = 1
while True:
    print("{:06d}".format(count))
    sleep(pause_ms)
    count += 1

It produces this output (borrowed the Arduino IDE as it has timestamping, running on Windows 11)

20:44:16.077 -> 000001
20:45:56.757 -> 000002
20:47:37.501 -> 000003
20:49:18.167 -> 000004
20:50:58.920 -> 000005
20:52:39.635 -> 000006
20:54:20.306 -> 000007

On v1.18

KeyboardInterrupt:
MicroPython v1.18 on 2023-10-30; micro:bit v2.1.2 with nRF52833
Type "help()" for more information.

The 100 second sleep (plus a tiny bit of processing for format/print/increment) is 100.680, 100.744, 100.666, 100.753, 100.715, 100.671. The clock appears to be running about 0.7% slow (at 23C). It's easy to dismiss this as poor time keeping on a microcontroller but the micro:bit V2 has a crystal (listed in BOM) and all is fine in CircuitPython on same board.

I first noticed this when checking the performance of the MCP7940N rtc on a ZIP Halo HD vs MicroPython utime.ticks_us(). Across 24 hours the RTC is running about 18 seconds fast (I think this has a trim feature which I may explore to get it spot on), MicroPython is 552 seconds slow (about 0.64%) and CircuitPython (time.monotonic_ns()) is just 2 seconds slow (extrapolated, I only had time to run the test for ~90 mins).

Image

@JackAtKitronik might be interested in this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions