I've built a quick test program to determine how quickly the Teensy 4.1 could handle a simple ISR. I've done this many times with UNOs and DUEs , by no means an expert programmer, but this is my first time using a Teensy.
When using a scope to check the Ext clock input vs output, I do see the expected delay as the Teensy handles the interrupt. The problem I've run into is that delay does not remain constant. The delay will be around 160nS for a few seconds, then will have a few longer delays (see traces below) before returning to 160nS. I need the 2 signals to remain phase locked. As shown below , my ext clock is yellow, Teensy output is green, triggered on the ext clock. Its acting like there is some other process running that I'm un aware of... interesting thing is that if I lower the ext clock frequency, then the time between these excursions gets longer , 10s of seconds. Hoping some can see some easy mistake I've made...
When using a scope to check the Ext clock input vs output, I do see the expected delay as the Teensy handles the interrupt. The problem I've run into is that delay does not remain constant. The delay will be around 160nS for a few seconds, then will have a few longer delays (see traces below) before returning to 160nS. I need the 2 signals to remain phase locked. As shown below , my ext clock is yellow, Teensy output is green, triggered on the ext clock. Its acting like there is some other process running that I'm un aware of... interesting thing is that if I lower the ext clock frequency, then the time between these excursions gets longer , 10s of seconds. Hoping some can see some easy mistake I've made...
Code:
// Test how fast I can use a pin interrupt to
// trigger on external clock and write port values.
const int ExtClockPin = 34; // External clock input
volatile boolean SpeedFlag1 = false;
volatile boolean ExtClkVal = LOW;
void setup() {
GPIO6_GDIR |= 0x10000; // 0000 0000 0000 0001 0000 0000 0000 0000
// Set up pin 19 (GPIO16) as output
pinMode(ExtClockPin, INPUT);
attachInterrupt(digitalPinToInterrupt(ExtClockPin), ClkInterrupt, CHANGE);
}
void ClkInterrupt() {
ExtClkVal = GPIO7_DR & 0x20000000; // Read only GPIO7-29
if (ExtClkVal == LOW) // Write to both DACs
GPIO6_DR &= 0xFFFEFFFF; // pin 19 low
else
GPIO6_DR |= (1 << 16); // pin 19 high
}
//void ClkInterrupt() {
// SpeedFlag1 = !SpeedFlag1;
// if (SpeedFlag1 == true)
// GPIO6_DR &= 0xFFFEFFFF; // pin 19 low
// else
// GPIO6_DR |= 0x10000; // pin 19 high
//}
void loop()
{
}