Encoder library modifications

I am using a standard industrial rotary encoders, which I use with my RPI and Microchip project. I am slowly changing to use Pico W as I am finding it a remarkable unit.

I respectfully wonder if the UF2 library could be altered to match standard type encoder routines. I will try to explain having looked at the encoder source in uf2 1.20.1. The encoder setup is:

Encoder::Encoder(PIO pio, uint sm, const pin_pair &pins, uint common_pin, Direction direction,
float counts_per_rev, bool count_microsteps, uint16_t freq_divider)

  1. The uint common_pin setup is not needed as the common pin of an encoder really ought go to 0v. This setup is wasting a valuable and precious GPIO pin on the pico for no purpose whatsoever.

Presumably that common pin setup is to be used to alter the polarity of the ‘common’ pin (changing the pin from 0v to Vcc) so as to effectively alter the direction of rotation. If so, this pin change is not needed as all that is needed is to swap over the ENC_A and ENC_B pin definitions, which alters the rotation direction from CW to ACW.

  1. Then the ‘Direction direction’ setup is not needed as the direction will have been decided by the ENC_A/B pin definitions and in any event the direction init value cannot be re-entered and re-inited whilst running.

  2. On a typical industrial encoder with multiple micro pulses per click, using the bool count_microsteps setup value of False you will get 2 steps counts per mechanical indent click and when using a value of True you will need to do 2 mechanical indent clicks to get a step count of 1.

This count_microsteps setting does not allow you to achieve 1 step count per 1 mechanical indent click, which is usually what the end user wants.

To easily achieve that with any make of encoder, the setup could to be changed to uint16_t microstep_divider (and you can enter eg 2 or whatever value to suit the model of encoder). The routine should read every micro step all of the time and divide those micro steps by this entered value, eg 2 (which will then give a step of 1 per click), so that any encoder (some have 1, 2, 4, 8, etc, micro steps per 1 mechanical click) can actually be setup to output 1 step count per 1 mechanical click.

I am not sure who supports these excellent encoder and other library routines and hope this feedback is taken as it is meant, to be constructive because the pico with the Pimoroni add-ons is a very powerful device, however it has precious GPIO which ought not to be wasted.

if this library was able to be changed a GPIO would be saved and any encoder with differing micro steps could be used in industrial projects.

Thanks for looking