I just tested the code from my first post and noticed the same problem on a brand new DUE, so I don't think that my hardware is damaged. Here are other things I have tested:
Using different pins - problem persists
Using RISING instead of FALLING - problem persists
Using CHANGE instead of FALLING - similar problem
Using higher and lower input frequencies - problem persists
I changed the code to only have a counter in the interrupt and it worked correctly, but that doesn't help me. Here is the code:
volatile int counter = 0;
void setup() {
Serial.begin(115200);
attachInterrupt(2, FallEdge, FALLING);
}
void loop() {
interrupts();
if (counter >= 1) {
Serial.println(micros());
counter = 0;
}
}
void FallEdge(){
counter++;
}
Then I moved the print statement out of the interrupt, but kept the micros() in the interrupt. It still had the same problem. Here is the code:
volatile unsigned long counter = 0;
void setup() {
Serial.begin(115200);
attachInterrupt(2, FallEdge, FALLING);
}
void loop() {
interrupts();
if (counter >= 1) {
Serial.println(counter);
counter = 0;
}
}
void FallEdge(){
counter = micros();
}