A small, affordable computer with free resources to help people learn, make things, and have fun
https://forums.raspberrypi.com/
Code: Select all
import time
for 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: Select all
.-------------------.
| 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 |
`----------^---------^---------'
Code: Select all
time.sleep_ms()Perhaps so, but that's a ridiculous implementation if you ask me. And I am not sure exactly what it's doing with such random and unpredictable results.katak255 wrote: ↑Fri Nov 07, 2025 12:41 amProblem is probably due to this ... https://github.com/micropython/micropyt ... /modtime.c ... and we have millisecond granularity. I guess they don't expect folks to use time.sleep() for under 1 ms timings. :)
No, I note the time before and immediately after the sleep and only then do the slower and variable time 'print' and 'format'. I don't consider timer wraparound but do print both start and end values so I can tell when that has happened.
The 'time_ms' doesn't allow sub-milliseconds so that's no use here, but 'time_us' does seem to work -
Code: Select all
.-------------------.
| RP2040 | RP2350B |
.----------|---------|---------|
| 2000 us | 2080 us | 2035 us |
| 1750 us | 1788 us | 1770 us |
| 1500 us | 1537 us | 1519 us |
| 1250 us | 1289 us | 1270 us |
| 1000 us | 1024 us | 1027 us |
| 750 us | 778 us | 765 us |
| 500 us | 531 us | 523 us |
| 250 us | 273 us | 266 us |
| 0 us | 23 us | 20 us |
`----------^---------^---------'