-
Notifications
You must be signed in to change notification settings - Fork 233
Some PIO examples are not working on RP2350/Pico 2 #83
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
ping @peterharperuk |
It looks like it may be a bug in micropython about PIO2: There are only enums |
I think you might be right. From a quick look at the
so So pinging also @dpgeorge (I wonder if this issue should get closed, and a new issue be opened at https://github.com/micropython/micropython ?) |
Ahhh, looks like this is #18 biting us again! 😂 (see additional discussion in micropython/micropython#7025 ) |
Yes; maybe increase to 4 kHz (but then the delay slots look more complicated to a beginner)? diff --git pio/pio_1hz.py pio/pio_1hz.py
index f891a25..b42b09c 100644
--- pio/pio_1hz.py
+++ pio/pio_1hz.py
@@ -7,27 +7,29 @@ import rp2
@rp2.asm_pio(set_init=rp2.PIO.OUT_LOW)
def blink_1hz():
- # Cycles: 1 + 1 + 6 + 32 * (30 + 1) = 1000
+ # Cycles: 1 + 1 + 14 + 32 * (31 + 31) = 2000
irq(rel(0))
set(pins, 1)
- set(x, 31) [5]
+ set(x, 31) [13]
label("delay_high")
- nop() [29]
- jmp(x_dec, "delay_high")
+ nop() [30]
+ jmp(x_dec, "delay_high") [30]
- # Cycles: 1 + 7 + 32 * (30 + 1) = 1000
+ # Cycles: 1 + 15 + 32 * (31 + 31) = 2000
set(pins, 0)
- set(x, 31) [6]
+ set(x, 31) [14]
label("delay_low")
- nop() [29]
- jmp(x_dec, "delay_low")
+ nop() [30]
+ jmp(x_dec, "delay_low") [30]
# Create the StateMachine with the blink_1hz program, outputting on Pin(25).
-sm = rp2.StateMachine(0, blink_1hz, freq=2000, set_base=Pin(25))
+sm = rp2.StateMachine(0, blink_1hz, freq=4000, set_base=Pin(25))
# Set the IRQ handler to print the millisecond timestamp.
sm.irq(lambda p: print(time.ticks_ms()))
# Start the StateMachine.
sm.active(1)
+time.sleep(3)
+sm.active(0) |
I wonder if:
is "easier to read" than
? |
I think one would be [29] and the other [30] (or [31] and [28])? I guess it will also depend on the accompanying documentation that might need to be updated. With my Pico 2, the LED just switches on and doesn't blink at all without the sleep… |
Regarding the pio_blink.py example. I discovered by cut and try method that, in line 23, the minimum value for "freq= " is 2289. I am using "MicroPython v1.24.1 on 2024-11-29; Raspberry Pi Pico2 with RP2350", board: iLabs iPico (RP2350). |
MicroPython v1.25.0-preview.187.g1b4c969ce on 2025-01-14; Raspberry Pi Pico2 with RP2350
pio_1hz.py
prints:ValueError: freq out of range
A quick fix would probably be
machine.freq(125_000_000)
but the LED only switches on and never off (possibly needs somesleep()
at the end).pio_blink.py
works ifmachine.freq(125_000_000)
is prepended, but if the state engine id is changed from0
to8
…11
then nothing happens.pio_exec.py
works even when the state engine id is changed from0
to8
…11
.pio_pwm.py
works as long as the state engine id is not changed to8
…11
(i.e.0
…7
are OK).The text was updated successfully, but these errors were encountered: