Close

Glitches, and how to get rid of them -Part II like a pro!

A project log for Digi:Arka

Dirt-cheap Vaus paddle clone for MSX - Now supports Standard Paddles too.

danjovicdanjovic 04/02/2020 at 01:310 Comments

I have studied the nature of the glitch for this particular device and verified the following fact:

then I have added another facts:

Then just as I was considering the last fact.....

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