Page 1 of 1

Timer.ENC_AB Example?

Posted: Wed May 13, 2020 2:09 pm
by metri
Does anyone have a really quick example of how to use Timer.ENC_AB?

I'm confused by the documentation is a few places.

1. I don't understand how to configure the Timer object. Timer.channel?
2. I don't understand how to configure the Pin to use an alternate function
3. Related to 1, I need a callback on rollover so I know direction at that point

I have found the enum for pin alternate functions, but don't really understand how to use it in the Pin definition, though I see I should set Pin.ALT, then pass alt as AF type, but haven't had any success.

enum {
AF_PIN_TYPE_TIM_CH1 = 0,
AF_PIN_TYPE_TIM_CH2,
...

Any help would be very much appreciated.

Thanks!

Re: Timer.ENC_AB Example?

Posted: Wed May 13, 2020 2:28 pm
by dhylands
Here are a few examples:

https://github.com/dhylands/upy-example ... ncoder2.py - uses ENC_AB requires external device to generate quadrature signal

https://github.com/dhylands/upy-example ... ncoder3.py - uses ENC_AB - can wire up some jumpers to use GPIO pins to generate quadrature signal (for testing).

Re: Timer.ENC_AB Example?

Posted: Wed May 13, 2020 10:27 pm
by metri
Thanks so much! That will get me going.

Brian