Content-Length: 279368 | pFad | http://github.com/micropython/micropython/issues/17594

C7 RP2: time.sleep and time.sleep_ms waking early (but not time.sleep_us) · Issue #17594 · micropython/micropython · GitHub
Skip to content

RP2: time.sleep and time.sleep_ms waking early (but not time.sleep_us) #17594

@washley

Description

@washley

Port, board and/or hardware

RP2 (Pico 2W)

MicroPython version

MicroPython v1.25.0 on 2025-04-15; Raspberry Pi Pico 2 W with RP2350

Reproduction

sleep:

>>> for _ in range(0, 10): a = time.ticks_us() ; time.sleep(0.002) ; b = time.ticks_us() ; print(b - a) ;
... 
1900
1767
1883
1868
1882
1894
1918
1885
1902
1901

sleep_ms:

>>> for _ in range(0, 10): a = time.ticks_us() ; time.sleep_ms(2) ; b = time.ticks_us() ; print(b - a) ;
... 
1957
1782
1917
1881
1895
1883
1903
1902
1905
1899

sleep_us:

>>> for _ in range(0, 10): a = time.ticks_us() ; time.sleep_us(2000) ; b = time.ticks_us() ; print(b - a) ;
... 
2035
2033
2022
2022
2020
2021
2022
2021
2022
2027

Expected behaviour

Expecting sleep times to be at least the requested duration (except, of course, in the case of an exception being thrown).

Observed behaviour

thread.sleep and thread.sleep_ms wake early for this particular (2ms) duration, but thread.sleep_us does not.

Additional Information

I discovered this because an I2C sensor driver was intermittently failing due to not sleeping long enough when resetting a device (its code follows the sensor specification of waiting 2ms, or at least it tries to).

#15626 may or may not be related, I don't know nearly enough about micropython at this point to say.

Code of Conduct

Yes, I agree

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: http://github.com/micropython/micropython/issues/17594

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy