I'm testing the Interrupt reponse times for Teensy 2.0 and Teensy 3.1 in preparation of a new project. Doing this, I wrote a very simple program, which activates an interrupt if an external event happens, and simply toggles an output line once the interrupt arrives. Th eocde is attached. Th eexternal event is genearted by a pulse generator, which fires a 200 ns pulse each ms. With Teensy 2.0 this works fine, besides some jitter, since the timer interrupt is still enabled. With Teens 3.1, this does not work reliable, saying that only about every third interrupt it catched. The behabiour does not depend on the lelngt of the pulse (1 tried it up to 10 µs) or the frequency of the pulses. Does someona have any clue what is to be changed?
--------------- Code -----------
void setup()
{
// Initialize the digital pin as an output.
pinMode(10, OUTPUT);
pinMode(2, INPUT);
attachInterrupt(2, flagIsr, RISING);
}
volatile int intarrived = 1;
void loop()
{
// Main code loop
while (intarrived) {
}
digitalWrite(10, HIGH);
delayMicroseconds(5);
digitalWrite(10, LOW);
intarrived = 1;
}
/// --------------------------
/// Custom ISR Routine
/// --------------------------
void flagIsr()
{
intarrived = 0;
digitalWrite(10, HIGH);
digitalWrite(10, LOW);
}
--------------- Code -----------
void setup()
{
// Initialize the digital pin as an output.
pinMode(10, OUTPUT);
pinMode(2, INPUT);
attachInterrupt(2, flagIsr, RISING);
}
volatile int intarrived = 1;
void loop()
{
// Main code loop
while (intarrived) {
}
digitalWrite(10, HIGH);
delayMicroseconds(5);
digitalWrite(10, LOW);
intarrived = 1;
}
/// --------------------------
/// Custom ISR Routine
/// --------------------------
void flagIsr()
{
intarrived = 0;
digitalWrite(10, HIGH);
digitalWrite(10, LOW);
}