I set a Pin Change Interrupt on an ATMega644 MCU but the final result is not exactly what I expected.. Though the trigger is a clear, 500 Hz, 250 ns pulse width signal (comes form an AFE4490 chip Data Ready pin), the ISR is running twice:
What's more, sometimes, randomly, the second ISR is missing:
Well, it would be the normal case but the vast majority of interrupts are duplicated.
Here is the code:
void setup() {
pinMode(PIN_PC1, INPUT); // PCINT17 pin defined as input
cli();
PCICR = B00000100; // PORTC active for INT (PCINT23:16 pins enabled for interrupt)
PCMSK2 = B00000010; // PCINT17 pin active
sei();
}
ISR(PCINT2_vect) {
// 10 µs pulse width square wave on PC7 to check ISR cycles:
PORTC |= (1<<PC7); // set HIGH
delayMicroseconds(10);
PORTC &= ~(1<<PC7); // set LOW
}
I don't know for sure, I can only guess.
Your pulse is too short compared to the length of the interrupt itself, so the second interrupt has to wait for the first to finish. Probably in some cases something clears the wait flag before the second interrupt fires... but what - I have no idea.
If you want the interrupt to fire once - replace CHANGE irq with RAISING or FAILING
I see now that I gave you the bit mnemonic instead of the register name. I'm not familiar with that specific MCU but anyway you worked it out. It has simply cleared the pending second (unwanted) interrupt (as @b707 has said)