pulse counter quadrature encoder
How can I use this firmware to get the output of the quadrature encoder
PIO does not work on RP2350B with GPIO pin >=32
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