Timer Encoder mode
Posted: Mon Nov 13, 2017 5:43 pm
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 = 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?