After the neopixel discussion: Not all WS2812Bs light up under certain configurations (not a power problem) - #14 by nefelim4ag
I just brought my attention to the timer dispatch again, and realized there are AVR-specific optimizations: klipper/src/avr/timer.c at master · Klipper3d/klipper · GitHub
Namely, a more “precise” min try ticks time.
I would expect that the actual timer enter/exit time on most MCUs would be less than 2us.
And if it is significantly less, it may be useful to adjust it. (If it is larger, I would be puzzled a little).
I sketched timer measurements: GitHub - nefelim4ag/klipper at mcu-timer-measurment
RP2040 ~750ns
$ python3 ./klippy/console.py /dev/serial/by-id/usb-Klipper_rp2040_E66368254F36922C-if00
...
measure_timer
measure_timer
measure_timer
009.529: #output: Starting measure
009.529: #output: enter_time: 4, exit_time: 5, total: 9
009.529: #output: Starting measure
009.529: #output: enter_time: 4, exit_time: 5, total: 9
009.529: #output: Starting measure
009.529: #output: enter_time: 4, exit_time: 4, total: 8
9 / 12_000_000 = 0.000000750 ~= 750ns
I’ve tried to copy the vector table to RAM (for STM32G0), like in the STM32F0, but it only shaves 2 cycles.
STM32G0B1 ~2800ns
~/klippy-env/bin/python3 ./klippy/console.py /dev/serial/by-id/usb-Klipper_stm32g0b1xx_4D003A000C50425539393020-if00
...
measure_timer
measure_timer
measure_timer
measure_timer
017.287: #output: Starting measure
017.287: #output: enter_time: 79, exit_time: 99, total: 178
017.287: #output: Starting measure
017.287: #output: enter_time: 79, exit_time: 99, total: 178
017.287: #output: Starting measure
017.287: #output: enter_time: 79, exit_time: 99, total: 178
017.287: #output: Starting measure
017.287: #output: enter_time: 79, exit_time: 99, total: 178
...
178 / 64_000_000 = 0.000002781 = 2.8us
STM32F042 ~3.5us
~/klippy-env/bin/python3 ./klippy/console.py /dev/serial/by-id/usb-Klipper_stm32g0b1xx_4D003A000C50425539393020-if00
...
measure_timer
006.892: #output: Starting measure
006.892: #output: enter_time: 65, exit_time: 104, total: 169
measure_timer
009.520: #output: Starting measure
009.520: #output: enter_time: 65, exit_time: 104, total: 169
measure_timer
012.095: #output: Starting measure
012.095: #output: enter_time: 65, exit_time: 104, total: 169
measure_timer
014.372: #output: Starting measure
014.372: #output: enter_time: 65, exit_time: 104, total: 169
...
169 / 48_000_000 = 0.000003521 = 3.5us
STM32H7 ~220ns
~/klippy-env/bin/python3 ./klippy/console.py /dev/serial/by-id/usb-Klipper_stm32h723xx_0C0024001951313434373135-if00
...
measure_timer
measure_timer
measure_timer
measure_timer
measure_timer035.576: #output: Starting measure
035.576: #output: enter_time: 44, exit_time: 71, total: 115
035.576: #output: Starting measure
035.576: #output: enter_time: 39, exit_time: 53, total: 92
035.576: #output: Starting measure
035.576: #output: enter_time: 41, exit_time: 69, total: 110
035.576: #output: Starting measure
035.576: #output: enter_time: 41, exit_time: 69, total: 110
035.838: #output: Starting measure
035.838: #output: enter_time: 44, exit_time: 71, total: 115
115 / 520_000_000 = 0.000000221 ~= 221ns
Unfortunately, that’s all the MCUs that I have.
I was somewhat surprised by the STM32G0. I suspect nothing critical, but it probably does try to exit from the timer code and then receives the next one.
Thanks.