Debouncing a momentary switch

Started by Mark Hammer, October 20, 2020, 10:44:02 AM

Previous topic - Next topic

Mark Hammer

I finally got around to making this circuit as yet another module for my modular effects system.  Rather than employing the 4 separate outputs, they all go to the single normalled out-jack, so I could step through effects fed from an external splitter, whether for purposes of instant comparison, or simply to vary things up.  It works, but the big momentary push-button I'm using to actuate it will not reliably step through the choices in order.  It will get to all of them...eventually...but not a dependable sequence, often skipping steps.
I'm assuming that I'm facing a switch-debouncing issue.  Given the design of the circuit, any recommendations one might make?  Looking up drawings for suggested strategies results in 95% of them being for momentary switching that connects to ground.  The 5% where the switch connects to V+ all seem to show something that I believe I see in the quad-switch schematic.  Is there something I might change with respect to the input to IC1 that would potentially alleviate this problem?


vigilante397

I generally throw a 100nF cap across the pins of a momentary switch. Fixes it 95% of the time.
  • SUPPORTER
"Some people love music the way other people love chocolate. Some of us love music the way other people love oxygen."

www.sushiboxfx.com

Mark Hammer

Sounds about right.  I'll try that.

amz-fx

#3
I was going to suggest .05uF in the same config.



regards, Jack

mozz

I was gonna say .01 but maybe you can catch the bounce on a scope to see what works best.
  • SUPPORTER

marcelomd

An alternative is a small micro controller. 8 or16 pins.

Rob Strand

It's not the value of the cap that's important it's the time constant.   A 10ms time constant is a good place to start.  New switches might work with 1ms or less, but then fail later on - the good old Ibanez footswitch failure problem.
Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

mozz

The value of the cap is the time constant.
  • SUPPORTER

Mark Hammer

I tried 68nf and 330nf.  Neither did the trick.  Still kinda random.

Rob Strand

#9
QuoteThe value of the cap is the time constant.
Different circuits have different resistors so the same C gives different time constants.  1M pull-up will be 100 times slower than a 10k pull-up.

QuoteI tried 68nf and 330nf.  Neither did the trick.  Still kinda random.

It might be a "bigger" problem.  The clock to the IC2, pin 14 might be bouncing.  A common "hack" fix is to connect a small cap like 100pF between pin 14 and  pin 8.   Slightly better would be to also add a 1k resistor between IC1's output and IC2 pin 14, with the cap present.  You can play with the values, an oscilloscope helps.
Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

Rob Strand

FWIW, it's not nice to short the cap out with the switch,  better would be to put a 100ohm resistor in series with the contact (see Boss and Ibanez footswitch ckts).    It's possible but not likely the absence of the 100ohm could cause a glitch in the circuit.
Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

bushidov

Aside from the 0.1uF "debounce" capacitor, a trick I've used a lot on my works' industrial pump equipment is using a 74HC14 Hex Schmitt Inverter. For debouncing and cleaning up encoder chop, I just feed the signal into the 74'14 to invert, then invert again, and that tends to clean "noise" decently. I know 74HC logic is more "5V" style logic chips, but the CD4000 series should work in a similar way.
"A designer knows he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away."

- Antoine de Saint-Exupéry

Rob Strand

QuoteI've used a lot on my works' industrial pump equipment is using a 74HC14 Hex Schmitt Inverter. For debouncing and cleaning up encoder chop, I just feed the signal into the 74'14 to invert, then invert again, and that tends to clean "noise" decently. I know 74HC logic is more "5V" style logic chips, but the CD4000 series should work in a similar way.

In principle the opamp is a Schmitt trigger and *should* do what the 74HC14 gate does, more or less.   However in reality the opamp output might not be clean.    Another difference is the opamp doesn't swing rail to rail like a 74HC14.   A "hack" fix for that is to put a resistor from the opamp output to ground.

It should be possible to see what is wrong with an oscilloscope, and see what is required to fix it.   One of the "hack" fixes could work but if you can see a cause and fixed the problem then it's no longer a "hack" since the reason for the fix is known.
Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

mozz

I said that above.

Quote from: mozz on October 20, 2020, 01:33:11 PM
I was gonna say .01 but maybe you can catch the bounce on a scope to see what works best.
  • SUPPORTER

Ripthorn

I actually like to do a simple RC filter on low pass configuration. The cutoff frequency should be lower than the bounce frequency as seen on a scope, but experimentation works also.
Exact science is not an exact science - Nikola Tesla in The Prestige
https://scientificguitarist.wixsite.com/home

Rob Strand

#15
Something in the back of my mind tells me that Schmitt trigger isn't right.

(Edit: It was the 22k to ground being large compared to the 22k Schmitt input resistor -  I think it's actually OK.)
Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

R.G.

I have designed in a few debouncers for my day job. For background, google "ganssle debounce", or go here:
http://www.ganssle.com/debouncing.htm
Stuff designed to his guidelines just seems to work.

But in my microprocessor-programming dotage, I've turned to software debouncing. I do a variant of the self-resetting counter. You poll the switch(es) every 10-20mS and shift each new reading into a shift register. There are several ways to do this, but I like either a vertical adder or a case statement to interpret the several states for whether the newest state has been stable for "long enough". As Ganssle says, that time period varies by switch.

Ganssle's two resistors and a cap seems to work most times, but as he says, a Schmitt trigger input makes it pretty foolproof.
R.G.

In response to the questions in the forum - PCB Layout for Musical Effects is available from The Book Patch. Search "PCB Layout" and it ought to appear.

Mark Hammer

So would a better solution be to omit the op-amp-based trigger/pulse generator feeding the 4017 and just go straight to a CMOS-based Schmitt trigger?

amz-fx

Quote from: Mark Hammer on October 20, 2020, 05:35:12 PM
I tried 68nf and 330nf.  Neither did the trick.  Still kinda random.

Increase R3 value to 100k and see if that helps. Go as high as 1M on R3 if you need more debounce.

Have you considered that your switch may be excessively bouncy (from a mechanical perspective)?

regards, Jack

amz-fx

#19
One of my drum synth designs from many years ago used this trigger input:



Your switch tied to V+ could be the trigger input.

regards, Jack