-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
PIO clock divider freq= parameter behaviour at extreme values. #7025
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
Comments
possible duplicate of this issue. |
The problem is that the frequency cannot go below 1908Hz. When trying to set it to 1907 the calculation of the clock divider overflows a 16-bit integer and you get about 10MHz PIO frequency. To get a lower frequency for the PIO you can decrease the CPU frequency using It would probably make sense to raise an exception when trying to set the PIO frequency too high or low. And also provide a way to inspect the actual frequency (which may be slightly different to the one requested). |
acknowledged. |
IMHO this should be reopened, as (although they're related) these issues aren't duplicates... This issue is about the PIO clock divider overflowing when the frequency is set too low (a bug in MicroPython). raspberrypi/pico-micropython-examples#18 is asking about the frequency in the provided examples being too low (a bug in |
@dpgeorge I did a bit of poking about, and (although it's not documented at https://raspberrypi.github.io/pico-sdk-doxygen/group__sm__config.html#gae8c09c7a4372da95ad777faae51c5a24 ), section 3.5.5. of https://datasheets.raspberrypi.org/rp2040/rp2040-datasheet.pdf says "The clock dividers are 16-bit integer, 8-bit fractional, with first-order delta-sigma for the fractional divider. The clock divisor can vary between 1 and 65536, in increments of 1/256". @richardbarlow I was curious about how the maths works out, so I dug into that too... 😃
|
Yep, agreed. What do you think about raising a ValueError if the user passes in a value that is too small or too big? |
Sounds like a good idea 👍 It has the potential to "break" old code that was previously setting a freq < 1908, but that code wouldn't have been doing what the user expected anyway. (and RP2040 is only a couple of months old, so not much "legacy code" yet!) |
Fixes issue micropython#7025. Signed-off-by: Damien George <damien@micropython.org>
See #7033 for a patch which validates the frequency. |
Fixes issue micropython#7025. Signed-off-by: Damien George <damien@micropython.org>
Fixed by 2c9af1c |
Fixes issue micropython#7025. Signed-off-by: Damien George <damien@micropython.org>
Setting a low frequency that would generate a high number of decimal places causes the clock to be off but more than jitter.
sm = rp2.StateMachine(0, irq_test, freq=1907)
The edge case of freq=1907 generates tens of thousands of interrupts when expecting around 2000. Appears to be rounding issue more than just jitter?
Sample code:
The text was updated successfully, but these errors were encountered: