Options to debounce interrupt pin

The code below is used to measure a 5V square pulse train from a Reed switch. max frequency is 69 Hz.

To avoid debounce, i had implemented a Software Debounce as in this code sample :

//Setup the Interrupt. Board used is a UNO
//The code for putting the CPU to sleep is not shown.

byte interruptPin   = 2;
byte gfmPulses_LED  = 3;

unsigned long pulseOfGFM;

//***************************

void setup()
{
  Serial.begin(9600);

  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), wakeNcount, FALLING);

}

//***************************

void loop()
{
  Serial.println( pulseOfGFM);

  delay(500);
}

//***************************

// ISR for Interrupt 0. Wake the CPU and count the GFM pulses

void wakeNcount()
{
  static bool ledState;
  static unsigned long last_interrupt_time = 0;
  unsigned long interrupt_time = millis();
  // If interrupts come faster than 10ms, assume it's a bounce and ignore
  if (interrupt_time - last_interrupt_time > 10)               // Debounce logic..
  {
    last_interrupt_time = interrupt_time;
    pulseOfGFM += 1 ;
    ledState = !ledState;
    digitalWrite( gfmPulses_LED, ledState);
  }
}

I had set the debounce for 10ms. In case i want to go the HW de-bounce way as per circuit below how to arrive at the capacitor and resistor values for a max frequency of about 70 Hz ?

To avoid debounce

You want to avoid bounce, not debounce.

In case i want to go the HW de-bounce way as per circuit below how to arrive at the capacitor and resistor values for a max frequency of about 70 Hz ?

How is this a Programming issue?

PaulS:
You want to avoid bounce, not debounce.
How is this a Programming issue?

:frowning:

:slight_smile:

Because a bounce is a (relatively) high frequency signal, a Low Pass Filter is what you are looking for.

To select the components, you can use this Low Pass Filter Calculator (one of many available in internet).
If you enter the paramaters 10uF (arbitrary value) capacitor and 70Hz frequency, you get a resistor around 230R.

giova014:
Because a bounce is a (relatively) high frequency signal, a Low Pass Filter is what you are looking for.

To select the components, you can use this Low Pass Filter Calculator (one of many available in internet).
If you enter the paramaters 10uF (arbitrary value) capacitor and 70Hz frequency, you get a resistor around 230R.

Perfect... this is what I was looking for. More than the calculator I liked the explanation for each one of them. Maybe very basic for the experts around but essential for a non electronics guy like me.

Of course I will still need a discharge resistor across the capacitor - so what I intend doing is to select a capacitor of 200nF and I can use a series resistor of 10K and a parallel resistor of about 33K or so. Guess this should work.

Thanks.

giova014:
Because a bounce is a (relatively) high frequency signal, a Low Pass Filter is what you are looking for.

To select the components, you can use this Low Pass Filter Calculator (one of many available in internet).
If you enter the paramaters 10uF (arbitrary value) capacitor and 70Hz frequency, you get a resistor around 230R.

Ok I am planning to design the PCB with a RC filter of about 820Ohm resistor and 2.2UF capacitor to get a cut off around 100Hz on the signal to Pin 2.

Question is should I retain the 10ms de-bounce logic inside the Interrupt Service Routine as I had posted in my first post or I can do away with it ?? I guess retaining it will not cause any grief ...

A while back I suggested hardware debounce for a reed switch and was admonished because the cap can cause a little arc when the contacts separate. The arc will erode the tiny tiny contact area of the reed switch, shortening its life. Software debounce or a Hall effect sensor may be better in this case.

groundFungus:
A while back I suggested hardware debounce for a reed switch and was admonished because the cap can cause a little arc when the contacts separate. The arc will erode the tiny tiny contact area of the reed switch, shortening its life. Software debounce or a Hall effect sensor may be better in this case.

Were that true, every points-based automotive ignition system used over the last 100+ years would have required the points be replaced about every 5 minutes....
The capacitor will, in fact, have EXACTLY the opposite effect - it PREVENTS arcing when the points open. In ignition systems, that is the entire reason a capacitor/condenser is used.
Regards,
Ray L.

I stand corrected and apologize for disseminating poor advice.

RayLivingston:
Were that true, every points-based automotive ignition system used over the last 100+ years would have required the points be replaced about every 5 minutes....
The capacitor will, in fact, have EXACTLY the opposite effect - it PREVENTS arcing when the points open. In ignition systems, that is the entire reason a capacitor/condenser is used.
Regards,
Ray L.

Oh good to note that correction. I was about to respond to @groundFungus saying that since the time constant is a product of R and C why not lower C and raise R so that the detrimental effects of the C are mitigated.

The reason you gave closes the argument !