I translated that to Python, and got this:
Code: Select all
from pyb import Timer
from stm import mem16, TIM2, TIM_SMCR, TIM_CCER
# Configure timer2 as a microsecond counter.
tim = Timer(2, prescaler=84, period=0x3fffffff)
# Configure channel1 on PA0 for timer IC.
ch = tim.channel(1, Timer.IC, pin=pyb.Pin('PA0'), polarity=Timer.FALLING)
# Reset the timer counter on rising edge.
mem16[TIM2 + TIM_SMCR] = (5 << 4) + 4
# Capture counter on falling edge.
mem16[TIM2 + TIM_CCER] = 11
That I couldn't find examples of this worries me - is there something I overlooked that makes this expensive/painful/bad compared to using the ATMEGA interrupt handler style?
I'd also like to know if there are values somewhere for the TIM_SMCR & TIM_CCER field positions I'm using, so I can replace the constants with names?
Thanks,
Mike