How to init a counter for QEI mode?
Posted: Fri Sep 04, 2015 12:59 am
Just tried a quick experiment to set up a QEI interface, and the "obvious" thing didn't work for me. After reading the code in stmhal/timer.c, it isn't clear to me how initializing the counter for QEI is supposed to work. (I admit that I've used other brands before, not ST parts, so I'm still climbing that learning curve with respect to the bare metal.)
The Timer object seems to want to be initialized either with a frequency or a prescaler/divisor, which then starts it running as a timer. So, for the QEI modes, isn't it necessary to init the counter without setting either a frequency or prescaler/divisor? But with a bare call to pyb.Timer(<n>), is the timer correctly initialized for encoder mode?
The following code prints zeroes, so the counter isn't moving for me:
Also, the compiler complains if the channel number isn't given on the tim.channel() call, even though the value is ignored.
Also tried with:
-dave
The Timer object seems to want to be initialized either with a frequency or a prescaler/divisor, which then starts it running as a timer. So, for the QEI modes, isn't it necessary to init the counter without setting either a frequency or prescaler/divisor? But with a bare call to pyb.Timer(<n>), is the timer correctly initialized for encoder mode?
The following code prints zeroes, so the counter isn't moving for me:
Code: Select all
import pyb
from pyb import Timer
from time import sleep
tim = pyb.Timer(8)
c1 = pyb.Pin('Y1',pyb.Pin.IN)
c2 = pyb.Pin('Y2',pyb.Pin.IN)
tim.channel(1,Timer.ENC_AB)
while True:
print(tim.counter())
sleep(1)
Also tried with:
Code: Select all
tim.channel(1,Timer.ENC_AB, pin=c1)
-dave