The Pico has a set of PIO co-processors. They are real-time controllers that can execute logic with deterministic timing. Ideal to run strict-timed sequences and state machines. And to implement extra peripherals (like a quadrature decoder here). |
This is an interesting case. Most quadrature decoder examples (such as this one) count steps per time. Works great in many cases, but has its issues. This one takes a different approach. It calculates the time per step, and derives speed from that.
The code uses a PIO state machine to read the encoder's activity and translate it into the info we need.
Adapt to PICO-EUROCARD rotary encoder
The Raspberry Pico code uses pin 10 and 11 as rotary encoder pins A and B. On the eurocard, the controller is attached to pins 6 and 7. In the example you have to change 1 line of code:
int main(void) { substep_state_t state; // base pin to connect the A phase of the encoder. the B phase must be // connected to the next pin // const uint PIN_A = 10; const uint PIN_A = 6;
That's it :). Build and test.
Testing
To test this, you just need to connect a terminal program to the debugger. Then wiggle the encoder ...
An alternative decoding solution that fits when the common technique isn't granular enough.
Thank you for reading.