I'm assuming that when it is in this mode, the timer hardware will take care of the pulse counting, counting up or down depending on the phase of the A and B signals from the quadrature encoder, but I'm now not sure of my assumption. I have written a simple program that generates quadrature signals on pins X1 and X2, I connect these to the alternate function pins on timer 2, i.e X4 and X3 and use the configuration shown below, but I can not get the timer to count. Ive tried different combinations of modes on the timer channels but I'm now clutching at straws. Has anyone a simple working example?
Code: Select all
timer = pyb.Timer(2)
timer_ch1=timer.channel(1,pyb.Timer.ENC_A)
timer_ch2=timer.channel(2,pyb.Timer.ENC_B)
pin_x4=pyb.Pin('X4')
pin_x4.init(pyb.Pin.IN,af=pyb.Pin.AF1_TIM2)
pin_x3=pyb.Pin('X3')
pin_x3.init(pyb.Pin.IN,af=pyb.Pin.AF1_TIM2)