Skip to content

time.sleep() truncates to 0 #429

@caternuson

Description

@caternuson

This shows the behavior which occurs near max resolution:

Adafruit CircuitPython 2.1.0 on 2017-10-17; Adafruit Trinket M0 with samd21e18
>>> import time
>>> t1 = time.monotonic(); time.sleep(0.1); t2 = time.monotonic(); t2-t1
0.0991211
>>> t1 = time.monotonic(); time.sleep(0.01); t2 = time.monotonic(); t2-t1
0.00878906
>>> t1 = time.monotonic(); time.sleep(0.001); t2 = time.monotonic(); t2-t1
0.0
>>> 

And some key bits of code are here:
https://github.com/adafruit/circuitpython/blob/master/shared-bindings/time/__init__.c#L76
which calls here:
https://github.com/adafruit/circuitpython/blob/master/ports/atmel-samd/common-hal/time/__init__.c#L37
with an implicit cast from float to uint32_t occurring in the process which results in the truncation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions