timer questions
Posted: Fri Jan 19, 2018 5:12 am
Hi all,
I am new to micropython and the pyboard. I had a few questions about the timer functions.
I've been able to get the basic blink an LED at the timer freq using a callback working. However when i tried the same thing using a prescaler and period I didn't get the expected result.
tim = pyb.Timer(4)
tim.init(prescaler=83, period=1000000)
tim.callback(lambda t: pyb.LED(1).toggle())
as i understand it this should make a 1Mhz clock that counts up to 1000000 and then triggers the interrupt which should toggle the led once a second? But it just seems to stay on (or maybe blinking very rapidly).
Second deals with output compare
t2 = pyb.Timer(2, freq=2000)
oc = t2.channel(2, pyb.Timer.OC_TIMING)
oc.compare(500)
oc.callback(lambda t: pyb.LED(2).toggle())
I was hoping to set a timer at a fixed freq and use OC_TIMING to make an interrupt when the counter reaches a value. at 2000hz that should make LED blink 2 per second? but it just appears on again. What happens after outputcompare reaches the value does it start counting again?
Thanks for any help!
I am new to micropython and the pyboard. I had a few questions about the timer functions.
I've been able to get the basic blink an LED at the timer freq using a callback working. However when i tried the same thing using a prescaler and period I didn't get the expected result.
tim = pyb.Timer(4)
tim.init(prescaler=83, period=1000000)
tim.callback(lambda t: pyb.LED(1).toggle())
as i understand it this should make a 1Mhz clock that counts up to 1000000 and then triggers the interrupt which should toggle the led once a second? But it just seems to stay on (or maybe blinking very rapidly).
Second deals with output compare
t2 = pyb.Timer(2, freq=2000)
oc = t2.channel(2, pyb.Timer.OC_TIMING)
oc.compare(500)
oc.callback(lambda t: pyb.LED(2).toggle())
I was hoping to set a timer at a fixed freq and use OC_TIMING to make an interrupt when the counter reaches a value. at 2000hz that should make LED blink 2 per second? but it just appears on again. What happens after outputcompare reaches the value does it start counting again?
Thanks for any help!