2024-03-18: Expansion to 1 - 4 channels
In the program shown previously, the function for the second channel was implemented by simply copying from PIO1_SM0 to PIO0_SM0. It was quick, but not particularly efficient.
In order to have PIO0 freely available again for other applications, PIO1_SM1 is now used and two additional channels using PIO1_SM2 and PIO1_SM3 are activated. A total of four quadrature decoders are available: Pico-qcnt4x.zip
Channels 2 and 3 are reduced in function as examples. This eliminates the need for an INDEX signal, which saves one input pin, and only uses one DMA channel for data acquisition. The retriggering of the DMA_TRANS_COUNT is done via software.
Basically, this could be achieved via an interrupt after 2^32-1 changes have expired, here it is done by resetting the counter with each function call 'get_qcnt2()' or 'get_qcnt3()'.
For demonstration purposes, the maximum clock frequency was also reduced to 1/10. Like the GPIOx and DMA_CHx used, you can set this differently as you wish.
http://mino-elektronik.de/progs/RP2040/Pico-qcnt4x.zip