Skip to content

Commit e174de8

Browse files
authored
Merge pull request #5443 from dhalbert/time.monotonic-doc
Add precision info to time.monotonic() documentation
2 parents f6681ef + f0e2945 commit e174de8

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

locale/circuitpython.pot

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1900,10 +1900,13 @@ msgid ""
19001900
msgstr ""
19011901

19021902
#: ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c
1903-
#: ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c
19041903
msgid "Pins must be sequential"
19051904
msgstr ""
19061905

1906+
#: ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c
1907+
msgid "Pins must be sequential GPIO pins"
1908+
msgstr ""
1909+
19071910
#: ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c
19081911
msgid "Pins must share PWM slice"
19091912
msgstr ""
@@ -3943,6 +3946,7 @@ msgstr ""
39433946
#: ports/espressif/boards/adafruit_funhouse/mpconfigboard.h
39443947
#: ports/espressif/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h
39453948
#: ports/espressif/boards/adafruit_metro_esp32s2/mpconfigboard.h
3949+
#: ports/espressif/boards/ai_thinker_esp32-c3s/mpconfigboard.h
39463950
#: ports/espressif/boards/ai_thinker_esp_12k_nodemcu/mpconfigboard.h
39473951
#: ports/espressif/boards/artisense_rd00/mpconfigboard.h
39483952
#: ports/espressif/boards/atmegazero_esp32s2/mpconfigboard.h
@@ -3961,6 +3965,7 @@ msgstr ""
39613965
#: ports/espressif/boards/gravitech_cucumber_rs/mpconfigboard.h
39623966
#: ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/mpconfigboard.h
39633967
#: ports/espressif/boards/lolin_s2_mini/mpconfigboard.h
3968+
#: ports/espressif/boards/microdev_micro_c3/mpconfigboard.h
39643969
#: ports/espressif/boards/microdev_micro_s2/mpconfigboard.h
39653970
#: ports/espressif/boards/morpheans_morphesp-240/mpconfigboard.h
39663971
#: ports/espressif/boards/muselab_nanoesp32_s2_wroom/mpconfigboard.h

ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode
6868
pins[1] = MP_OBJ_FROM_PTR(pin_a);
6969
self->swapped = false;
7070
if (!common_hal_rp2pio_pins_are_sequential(2, pins)) {
71-
mp_raise_RuntimeError(translate("Pins must be sequential"));
71+
mp_raise_RuntimeError(translate("Pins must be sequential GPIO pins"));
7272
}
7373
}
7474

shared-bindings/time/__init__.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,26 @@
3939
//| """time and timing related functions
4040
//|
4141
//| The `time` module is a strict subset of the CPython `cpython:time` module. So, code
42-
//| written in MicroPython will work in CPython but not necessarily the other
42+
//| using `time` written in CircuitPython will work in CPython but not necessarily the other
4343
//| way around."""
4444
//|
4545
//| def monotonic() -> float:
4646
//| """Returns an always increasing value of time with an unknown reference
47-
//| point. Only use it to compare against other values from `monotonic`.
47+
//| point. Only use it to compare against other values from `time.monotonic()`.
48+
//|
49+
//| On most boards, `time.monotonic()` converts a 64-bit millisecond tick counter
50+
//| to a float. Floats on most boards are encoded in 30 bits internally, with
51+
//| effectively 22 bits of precision. The float returned by `time.monotonic()` will
52+
//| accurately represent time to millisecond precision only up to 2**22 milliseconds
53+
//| (about 1.165 hours).
54+
//| At that point it will start losing precision, and its value will change only
55+
//| every second millisecond. At 2**23 milliseconds it will change every fourth
56+
//| millisecond, and so forth.
57+
//|
58+
//| If you need more consistent precision, use `time.monotonic_ns()`, or `supervisor.ticks_ms()`.
59+
//| `time.monotonic_ns()` is not available on boards without long integer support.
60+
//| `supervisor.ticks_ms()` uses intervals of a millisecond, but wraps around, and is not
61+
//| CPython-compatible.
4862
//|
4963
//| :return: the current monotonic time
5064
//| :rtype: float"""
@@ -216,7 +230,8 @@ STATIC mp_obj_t time_time(void) {
216230
MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time);
217231

218232
//| def monotonic_ns() -> int:
219-
//| """Return the time of the monotonic clock, cannot go backward, in nanoseconds.
233+
//| """Return the time of the monotonic clock, which cannot go backward, in nanoseconds.
234+
//| Not available on boards without long integer support.
220235
//|
221236
//| :return: the current time
222237
//| :rtype: int"""

0 commit comments

Comments
 (0)