Teensy 4.1 PlatformIO 2MHz Timer interrupt GPIO output
The following PlatformIO example uses TeensyTimerTool on the Teensy 4.1 to run a simple GPIO toggle interrupt at 4 MHz interrupt frequency (i.e. the interrupt is being run 4 million times each second), resulting in a 2 MHz GPIO output:
#include <Arduino.h>
#include <TeensyTimerTool.h>
using namespace TeensyTimerTool;
PeriodicTimer t1(GPT2);
void callback() // toggle the LED
{
digitalWriteFast(33, !digitalReadFast(33));
}
void setup()
{
t1.begin(callback, 250ns);
pinMode(33, OUTPUT);
}
void loop()
{
}
platformio.ini:
[env:teensy41]
platform = teensy
board = teensy41
framework = arduino
lib_deps = luni64/TeensyTimerTool @ ^0.3.5
The 2MHz output looks like this on the oscilloscope: