Is there a way to test time.ticks_diff() ? #16897
-
I wanted to test the rollover behavior of time.ticks_diff() so I tried the following: import time
t1 = 2**30 - 1000 # 1000ms before rollover
t2 = 1000
print(time.ticks_diff(t2, t1))
When I asked perplexity (ai) what was was wrong it said ticks_diff needs to get actual 'timing values' instead of integers. And if so, how could timing values be created if at all? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
ticks_diff() takes integers. Only they must be in the range of the ticks_xxx() functions, usually 30 bits. So your result looks odd. Which platform did you use for the test? Edit: Using your code snippet on a RP2 I get as result 2000. |
Beta Was this translation helpful? Give feedback.
-
Note that the warning on the documentation page for |
Beta Was this translation helpful? Give feedback.
On a XIAO nRF52840 Sense with NRF52840 I get the same result of 2000 with the first code snippet and MicroPython 1.24.0. 2**30 is by 1 out of the range of a 30 Bit number, which will then give you unexpected results.
With
2**30 - 1
instead I get a result of 268470025 with your second test script, which is reasonable.Try updating the firmware. to v1.24.1.
Edit: It may be that the v1.22.2 version you use has a smaller ticks_xxx() range.