← index #5214Issue #16199
Related · high · value 0.549
QUERY · ISSUE

pulse counter quadrature encoder

openby ZeshuiLiopened 2019-10-15updated 2025-10-03
enhancement

How can I use this firmware to get the output of the quadrature encoder

CANDIDATE · ISSUE

PIO does not work on RP2350B with GPIO pin >=32

closedby sfe-SparkFroopened 2024-11-09updated 2025-12-01
bugport-rp2

Port, board and/or hardware

rp2 port with RP2350B

MicroPython version

v1.24.0-preview.461.gb8227a3f7.dirty

Reproduction

Connect a quadrature encoder to any pair of GPIO pins. Then create an instance of this class, which implements a quadrature decoder using PIO: https://github.com/Open-STEM/XRP_MicroPython/blob/main/XRPLib/encoder.py

Then run the following while rotating the encoder:

pinA = 0
pinB = 1

myEncoder = Encoder(0, pinA, pinB)

while True:
    print(myEncoder.get_position_counts())
    time.sleep(0.1)

Expected behaviour

A PIO encoder should work on any pair of pins, and the printed output should change as the encoder rotates.

Observed behaviour

A PIO encoder only works if pinA and pinB are <32. If they're >=32, the printed output is fixed at 0.

Additional Information

I'm not super familiar with MicroPython, but this appears to be where the state machine is created:

https://github.com/micropython/micropython/blob/5dfbd4371480c175e6f54e57e4e5eb5d579cbd00/ports/rp2/rp2_pio.c#L726-L743

Which eventually calls this Pico SDK function:

https://github.com/micropython/micropython/blob/5dfbd4371480c175e6f54e57e4e5eb5d579cbd00/ports/rp2/rp2_pio.c#L666-L669

~Not sure whether the root problem is with MicroPython or the Pico SDK, but I suspect it may be related to https://github.com/raspberrypi/pico-sdk/issues/2030 TLDR; need to set pio->gpiobase to 16 if the pin is >=32.~

Edit: Just realized that sm_config_set_in_pins() only accepts pins 0-31, so that's likely the root problem. Not sure what the solution would be.

Code of Conduct

Yes, I agree

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied