-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
time.sleep waits less than expected #9693
Comments
You should try that on CircuitPython 9.1 or better. |
Similar in 9.1.4. A sliver of the loss (<8us) is from the time it takes to call
But the point remains that Similar results on Pico [W]:
|
Re @todbot, if you followed the linked forum discussion you'll see that bug was reproduced on 9.1.1 as well |
Right, thanks I see that now. Also, thanks @anecdata. In my experience trying to do tight-timing on CircuitPython this isn't very surprising. CircuitPython has no concept of atomic or critical sections so who knows what happens during those three function calls: USB handling and garbage collection come to mind as tasks that eat up several milliseconds. Perhaps a similar test that was disconnected from USB, does a |
What I think is odd here is that the time is less that the requested time. I'd expect overhead to make it longer. So I'm suspecting a ticks-vs-msec issue: a tick is 1/1024 of a second vs the msec 1/1000 of a second. It could be an error in converting ticks to msecs or assuming one is the other. |
Oh yes, under the requested value. You are correct. I need more coffee. |
I think adafruit_support_bill got it right way back in August: here. Plus, any short sleep will be accentuated by the floored division |
Ah yes, I have experienced this. In #9237 I was convinced it was a problem with floats in CircuitPython because 0.004 seconds * 1000 millis/sec != 4 milliseconds. |
My favorite quote from the discussion:
|
I think this is still something to follow up on. We might round instead of truncating. And I am still suspicious of 1024 vs 1000. 9.7 vs 10 is not a few least-significant bits of difference. |
I had played around with altering the value given time.sleep; the handful of substitute values tried were enough to suggest that expressions are perhaps being evaluated according to The Price is Right rules, which is to say what it returns is as near as possible the specified value without going over, within the limits of floating point/ (1000/1024) math. Using values for sleep from 0.08 to 0.011 returned results which were either 986x(- up to 90) or 1076x(- up to 20). Using 0.1 (and adjusting divisor to 10000) returned 9985(- up to 20). (These tests were done on a Metro RP2040 running 9.2.0-beta.0) |
CircuitPython version
Code/REPL
Behavior
The result shows:
expected 10000 us, got 9799.07 us
Description
see:
https://forums.adafruit.com/viewtopic.php?p=1024856#p1024856
Additional information
No response
The text was updated successfully, but these errors were encountered: