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

MicroPython • time.sleep() oddities

$
0
0
Is it just me or are 'time.sleep(0.00nnnn)' millisecond / microsecond delays unreliable ...

Code:

import timefor delay in [0.002000,  # 2              0.001750,  # 1.75              0.001500,  # 1.5              0.001250,  # 1.25              0.001000,  # 1              0.000750,  # 0.75              0.000500,  # 0.5              0.000250,  # 0.25              0.000000]: # 0  start = time.ticks_us()  time.sleep(delay)  end = time.ticks_us()  print("{:8.6f} {:>4} us {} {}".format(delay, end - start, start, end))

Code:

           .-------------------.           |  RP2040 | RP2350B |.----------|---------|---------|| 0.002000 | 2073 us | 1528 us || 0.001750 | 1063 us |  516 us || 0.001500 | 1091 us |  619 us || 0.001250 |  949 us |  588 us || 0.001000 |  897 us |  642 us || 0.000750 |  108 us |   44 us || 0.000500 |   71 us |   62 us || 0.000250 |  106 us |   42 us || 0.000000 |   66 us |   65 us |`----------^---------^---------'
It all seems a bit random - I got "0.001500 96 us" on one run.

Statistics: Posted by hippy — Thu Nov 06, 2025 9:53 pm — Replies 3 — Views 83



Viewing all articles
Browse latest Browse all 7503

Trending Articles