Teensy 4.1 interrupts at multi-MHz speed using TeensyTimerTool
As shown in our example Teensy 4.1 PlatformIO 2MHz Timer interrupt GPIO output you can use TeensyTimerTool to generate multi-MHz timer interrupts. In our experiments, we could generate GPIO-toggling interrupts up to 4 MHz:

The trick here is to use std::chrono time literals. The TeensyTimerTools PeriodicTimer example only shows us how to use microsecond resolution:
periodic_timer_example.cpp
t1.begin(callback, 250'000); // 250ms
but we can simply use 250ns to obtain nanosecond resolution:
periodic_timer_example.cpp
t1.begin(callback, 250ns);Here’s our observation what works and what doesn’t:
- Multi-MHz GPIO-toggling interrupts as shown in our example only work on
GPT1andGPT2, they do NOT work onPITandTMRx. We did not investigate the precise reasoning behind this, and there might also be ways to - As usual, the interrupt must only contain a small number of instructions. We’re using
digitalWriteFast(), but using direct register access would be even faster.
Check out similar posts by category:
Electronics, Embedded, PlatformIO, Teensy
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow