Replies: 3 comments
-
the 30-bit format is required for the micropython 'small integer' that can be passed around without creating an object. That's why the |
Beta Was this translation helpful? Give feedback.
-
as you can see in the code above, I used ticks_diff()... but still the overflow happens at 2^30. |
Beta Was this translation helpful? Give feedback.
-
micropython stores small integers directly where ordinarily the pointer to an object would go, thus saving allocating a full object when an integer is of a suitable size. This makes handling 30 bit integers, which covers the most common cases, very fast. These are flagged by the high 2 bits being zero. It's an optimization. I saw you used the ticks_diff. The reason I commented on it is that this abstracts away the funny wraparound. Incidentally, never try to use a regular integer with ticks_diff, other than the values pretty much directly returned by the ticks() functions. If you hand it a regular integer, which may have been created by other math, it could well be an object. In this case |
Beta Was this translation helpful? Give feedback.
-
Port, board and/or hardware
esp32
MicroPython version
MicroPython v1.24.1 on 2024-11-29; Generic ESP32 module with ESP32
Reproduction
Expected behaviour
it seems that time.ticks_cpu() is 30 bit signed.
it overflows at 1073741824 (2^30)
Observed behaviour
shouldn't it be 2^31 or just a 32 bit INT?
is there a reason for that?
because of this the maximum elapsed ticks measurable are:
53.6870912 seconds @ 20 Mhz
26.8435456 seconds @ 40 Mhz
13.4217728 seconds @ 80 Mhz
6.7108864 seconds @ 160 Mhz
4.47392426 seconds @ 240 Mhz
please if possible, express ticks as a 32 bit integer
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree
Beta Was this translation helpful? Give feedback.
All reactions