I have a quadrature encoder connected on a PyBoard to X1 and X2. I am trying to set up Timer2 in encoder mode to use with the encoder. I am inputting with REPL - I have tried..
timer = pyb.Timer(2)
pin1 = pyb.Pin(pyb.Pin.board.X1,mode=pyb.Pin.AF_PP,af=pyb.Pin.AF1_TIM2)
pin2 = pyb.Pin(pyb.Pin.board.X2,mode=pyb.Pin.AF_PP,af=pyb.Pin.AF1_TIM2)
ch1 = timer.channel(1,pyb.Timer.ENC_AB)
ch2 = timer.channel(2,pyb.Timer.ENC_AB)
Then move the encoder to generate some pulses and then read the timer counter
timer.counter()
but response is always 0, I have also tried reading the timer channel capture value - but that's 0 as well
Docs say create the timer, define the two inputs as af timer using pin, set the timer channel modes to encoder, read value from timer counter.
I have also tried config of the channels as
ch1 = timer.channel(1,pyb.Timer.ENC_AB,pin=pyb.Pin(pyb.Pin.board.X1,mode=pyb.Pin.AF_PP,af=1))
but this doesn't work either.
Any one know what I am doing wrong?
Timer Encoder mode
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Timer Encoder mode
See this thread viewtopic.php?f=6&t=1735.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Timer Encoder mode
Thank you Peter - initialising the gpio's correctly fixed the problem