In this example for Teensy 4.0 I'm using a 200kHz timer interrupt to generate a short pulse at pin D1.
In the main loop pin D0 is toggled as fast as possible, so that I can see on the scope the duration of the interrupt.
On the scope yellow is D0 (main loop) and cyan is D1 (pulse in interrupt):
When the main loop is interrupted, it takes about 180ns until the pulse appears at D1, and additional 40ns until the main loop continues.
Now I change the interrupt source in lines 7 and 8, using PIT instead of GPT1. Everything else is the same as before.
Now the durations have increased to 330ns and 540ns.
I'd like to understand why. What's the microcontroller doing during this time?
In the main loop pin D0 is toggled as fast as possible, so that I can see on the scope the duration of the interrupt.
Code:
#include "TeensyTimerTool.h"
using namespace TeensyTimerTool;
#define repeat_10(a) a;a;a;a;a;a;a;a;a;a
#define repeat_100(a) repeat_10(repeat_10(a))
PeriodicTimer timer1(GPT1); // uses GPT1
//PeriodicTimer timer1(PIT); // uses PIT
void setup()
{
pinMode(0, OUTPUT); // Main loop
pinMode(1, OUTPUT); // Interrupt
timer1.begin(isr, 5); // 200 kHz
NVIC_SET_PRIORITY(IRQ_GPT1, 32); // set high priority
NVIC_SET_PRIORITY(IRQ_PIT, 32); // set high priority
}
void isr(void)
{
digitalWriteFast(1, HIGH);
digitalWriteFast(1, LOW);
}
void loop() // toggle D0 as fast as possible
{
repeat_100(
digitalWriteFast(0, HIGH);
digitalWriteFast(0, LOW);
);
}
When the main loop is interrupted, it takes about 180ns until the pulse appears at D1, and additional 40ns until the main loop continues.
Now I change the interrupt source in lines 7 and 8, using PIT instead of GPT1. Everything else is the same as before.
Now the durations have increased to 330ns and 540ns.
I'd like to understand why. What's the microcontroller doing during this time?
Last edited: