This is all great for my purpose. But, I am seeing up to 8.7 microseconds of variation between when the UEV occurs, and when the interrupt runs. This is not great.
From what I have read, there should be a way to increase the importance of this Timer interrupt, I believe this should be in the EXTI register, and according to the STM32F401RET6 datasheet (this is in the G30TH dev board) on page 203:
"TIM1_UP_TIM10" should be at 0x000000A4
but when I read:
stm.mem16[stm.EXTI + 0xA4]
I get zeros, and writing a value there doesn't have any effect.
Code: Select all
import pyb from pyb import Timer import micropython import stm from machine import Pin micropython.alloc_emergency_exception_buf(100) period = 10000 width = 1000 def adjust_tim1_pulses(number_pulses): stm.mem16[stm.TIM1 + stm.TIM_RCR] = (stm.mem16[stm.TIM1 + stm.TIM_RCR] & 0xff<<8) | ((number_pulses - 1) & 0xff) def adjust_tim1(period, width, number_pulses=None): stm.mem16[stm.TIM1 + stm.TIM_ARR] = period stm.mem16[stm.TIM1 + stm.TIM_CCR1] = period - width if number_pulses != None: adjust_tim1_pulses(number_pulses) p32_pin = Pin('JP32', Pin.OUT) p32_pin.value(0) def tim1_opm_end_cb(t): p32_pin.value(0) # Timer 1 to repeat a burst every burst_period counting up: t1 = pyb.Timer(1, prescaler=11, period=period, mode=Timer.UP, callback=tim1_opm_end_cb) stm.mem16[stm.TIM1 + stm.TIM_CR1] &= ~1 & 0xFFFF # disable Clock-Enable adjust_tim1_pulses(8) # pulse tim1 8 times before the next UEV stm.mem16[stm.TIM1 + stm.TIM_CR1] |= (1 << 3) # want one-time mode t1ch1 = t1.channel(1, pyb.Timer.PWM, pulse_width=1, polarity=pyb.Timer.LOW, pin=pyb.Pin.board.JP17) def pulse(): stm.mem16[stm.TIM1 + stm.TIM_CNT] = 0 # set the counter to 0 stm.mem16[stm.TIM1 + stm.TIM_EGR] |= 1 # generate an event to ensure any shadow registers are updated p32_pin.value(1) stm.mem16[stm.TIM1 + stm.TIM_CR1] |= 1 # Clock Enable