Read Motor Speed Better By Making The RP2040 PIO Do It
1 min read
Summary
Afloating point quadrature encoder offers a means of determining the movement and direction of a rotating shaft and they are cheap and simple.
However, the quality of the information they provide depends on the quantity of data they provide, and this is poorer at low speeds compared with high speeds.
Edge transitions in the data are also prone to high levels of noise, and again this is more of an issue at low speeds.
Cheap encoders also often do not provide ideal 50% duty cycle phases that are exactly 90 degrees out of phase with one another, which is a further source of inaccuracy.
To overcome these issues, Paulo Marques has created a lightweight and efficient library that uses the Programme I/O (PIO) hardware on the RP2040 to provide more accurate results.
The library benefits from a hybrid approach that uses a “sub-step” quadrature method that more carefully tracks transitions to avoid noise, and it also accounts for different phase size differences in various encoders.
As the PIO does the low-level work of counting steps and tracking data transitions, it does not require CPU time.