I connected an encoder to the ports Y1 and Y2. I checked the signals with the oscilloscope and it looks fine. These two pins have an alternate function for Ch1/Ch2 of the timer 8 (af=3). I want to use the timer 8 as a counter, so that the peripheral evaluates the encoder signals without interrupting the CPU. I followed the documentation on the wiki page, but I cant get it running. I also tried different timers and I also used the latest (threading) firmware: v1.12-535-g509359754
My code looks like this:
Code: Select all
from pyb import Pin, Timer
class QEncoder:
def __init__(self):
# setup input pins, alternate function: encoder
ENCP_A = Pin('Y1', Pin.AF_PP, pull=Pin.PULL_NONE, af=3)
ENCP_B = Pin('Y2', Pin.AF_PP, pull=Pin.PULL_NONE, af=3)
# setup timer peripheral
self.Timer_Peripheral = Timer(8)
temp = self.Timer_Peripheral.channel(1, mode=Timer.ENC_AB, pin=None)
#self.Timer_Peripheral.counter(50)
def get_value(self):
return self.Timer_Peripheral.counter()
e = QEncoder()
for i in range(10):
print(e.get_value())
sleep(0.1)