I have studied the nature of the glitch for this particular device and verified the following fact:
- Glitches are caused by MSX. No doubt on that;
- Glitches occur only when CLOCK signal change its state;
- Glitches occur simultaneously to the change in CLOCK signal.
then I have added another facts:
- CLOCK signal triggers INT0 on AVR;
- PULSE signals either real or glitches triggers Pin Change Interrupt on AVR;
Then just as I was considering the last fact.....
- External Interrupts have priority over Pin Change Interrupts!
The solution slapped me in the face!
"CLEAR PIN CHANGE INTERRUPTS AT THE END OF EXTERNAL INTERRUPT SERVICE"
And that was done...
//
// External Interrupt driven by Clock pin (6)
//
ISR(INT0_vect) {
// output a new bit
if (shiftRegister & (1 << MSBIT)) {
pinMode(DATA, INPUT_PULLUP);
} else {
digitalWrite(DATA, LOW);
pinMode(DATA, OUTPUT);
}
// pre-shift next bit
shiftRegister <<= 1;
GIFR |= (1<<PCIF ); // <- De-glitch in a single instruction!
}
The result can be seen below. Glitches still appear but they do not cause any harm !
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.