Timer.ENC_AB Example?

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
metri
Posts: 13
Joined: Sat Aug 17, 2019 4:23 am

Timer.ENC_AB Example?

Post by metri » Wed May 13, 2020 2:09 pm

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!

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Timer.ENC_AB Example?

Post by dhylands » Wed May 13, 2020 2:28 pm

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).

metri
Posts: 13
Joined: Sat Aug 17, 2019 4:23 am

Re: Timer.ENC_AB Example?

Post by metri » Wed May 13, 2020 10:27 pm

Thanks so much! That will get me going.

Brian

Post Reply