What's happening is this:
1 - You start Timer 1 and ask it to generate an interrupt once every millisecond
2 - You wrote an interrupt callback routine which consumes 100% of the CPU for just over a millisecond
Timers all run at equal priority (in the IRQ priority sense), but lower numbered timers will have their callbacks processed before higher numbered timers.
As soon as your Timer1 callback has finished running, and interrupts are re-enabled, the timer1 interrupt handler fires again. So the Timer2 callback never runs.
If you're trying to control RC-style servos, you'd be much better off to use PWM.
Timers 1 and 8-11 run at 168 MHz
The remaining timers run at 84 MHz
I notice you're using X1 and X2, which happen to be dealt with already by the Servo class:
http://micropython.org/doc/module/pyb/Servo Servos 1-4 map onto X1-X4
Asssuming you don't want to use the Servo class, then you could do the following:
Code: Select all
t2 = pyb.Timer(2, prescaler=83, period=19999
servo1 = t2.channel(1, pyb.Timer.PWM, pin=pyb.Pin.board.X1)
servo2 = t2.channel(2, pyb.Timer.PWM, pin=pyb.Pin.board.X2
servo1.pulse_width(1000)
servo2.pulse_width(1000)
The simplest place to see the channel mapping is to look at the generated pins_af.py file inside the build directory. I happen to have a copy checked in over here:
https://github.com/dhylands/upy-example ... pins_af.py
We can see that Timer 2 has channels 1- 4 mapped onto X1 to X4.
So we've setup one timer, and setup 2 channels on that timer. The timer has a resolution of 1 microsecond (84 MHz / (83 + 1)) = 1 MHz. It cycles once every (19999 + 1) counts, or once every 20000 microseconds (20 milliseconds), which corresponds to a frequency of 50 Hz.
We can set the pulse width on each channel to be any value between 0 and 20000 in 1 microsecond increments. For RC style servos, we want values in the range of about 500 to 2500 (the nominal values are 1000-2000, with 1500 being the center value), but most servos accept values outside that range.
And it consumes 0% CPU.
As a general rule, you should NEVER put delays into interrupt callbacks. You're just asking for trouble. It should always raise a red flag, and you should always try to find an alternate solution.