Debouncing a momentary switch

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

Previous topic - Next topic

R.G.

Quote from: Mark Hammer on October 21, 2020, 08:50:23 AM
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?
In my experience, yes. The RC network converts any short string of bounce pulses to a more smoothly varying ramp-ish change. CMOS Schmitts are designed to deal with this. The hysteresis ignores any wandering around in the middle that happens.  Some CMOS Schmitts are better than others. Most of them have hysteresis of about 1/3 of the power supply to the chip, so on 9V you'd get about 3V of hysteresis. The CD40106 is an example of this. Others have smaller hysteresis. An example is the CD4584.

Opamp based Schmitts can work reliably, too. I just avoid them because I had some bad experiences with them early on and the burn-ed child avoideth the fire.  :icon_lol:
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.

amptramp

There used to be some IC's devoted to switch debouncing such as the Motorola MC14490, the Maxim MAX6818 and a few others.  The MC14490 is the one I am familiar with.  It is a hex device that can debiounce six inputs.  It clocks the signal through a four-bit shift register and does not permit the output to change unless all four bits are the same, so if the input goes down then up then down in less than four clock cycles (the clock is internal), the output does not change until all the bits are equal.  The inputs have internal pullups for use with grounded switches.  The problem with this device is that it cannot be initialized so if the shift registers all come up in the wrong state, it cannot be corrected until the first clock pulse, which is why I was interested in them but never used them.  It could debounce both the positive and negative transitions.  If you have a system initialize that lets you ignore switch positions for a certain time, this device may be usable.

R.G.

That's very similar to what I do with uCs. I usually shift in the state of the input pin and run it into a short 3-4 long shift register (done as one of the memory locations). I keep the current debounced state (1 or 0) in another bit, often a higher bit in the same register that keeps the input states. The code ignores all strings of input bits that are not uniformly different from the previously debounced state, and changes when there are three or four (depending on my mood when I write the code  :)  ) new inputs different. The output pin is either set to the current debounced state every pass through this or only changed when I get a "new state detected" result from shifting switch samples in. I generally run a timer to set about 10-20ms between input pin samples, and usually on an interrupt level so the controller can be off doing other things between input pin readings.

This lends itself to doing other things as well. One variant I've used is to make the output be a fixed-length pulse when the input switch either makes or breaks, or to make the output toggle, again either on a debounced make or debounced break. In one variant, I used a vertical adder (!!) to read and debounce eight independent switches both independently or simultaneously, and to allow the option of selecting momentary or toggle action on any input switch with a mask bit.

@Mark: the biggest issue with uCs is that they live in a 5V world and you would need to drive a transistor to make it to the 9V world if you have to have 9V signals. Some 9V applications can use the raw 5V output of a uC as is.

The smallest uC I've found for these application is a 6-pin SMD or 8-pin DIP to debounce either one or two switches  for you.
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.

Rob Strand

QuoteIncrease 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)?

A high value of R3 prevents the Schmitt input being detected as low because current flows through the Schmitt resistors.   (That was my concern a few posts back.  The 22k doesn't leave much margin.)
Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

kraal

#24
Maybe it's a stupid question (maybe I'm missing the purpose of IC1 or the purpose of the whole circuit), but why not using something like this to avoid bouncing issues (with a SPDT switch) ?

https://tinyurl.com/y47eux7a

Where the resistor is your IC2.

Edit: modified circuit

Ben N

  • SUPPORTER

Mark Hammer

So would this circuit generate the needed pulse? (100ms wide)

anotherjim

I have sneaking suspicion it can work more directly. The Clock input of a 4017 has a Schmitt trigger already as well as a positive edge action.

Mark Hammer

The "it" being the 555 timer circuit or the 4017 itself?

Rob Strand

FWIW, the opamp version is doing three jobs:
- provide trigger input
- level translating the *ground referenced* trigger input to the +6V/-6V power CMOS-gate.
- provide manual switch

Presumably you want the trigger to work from a 0 to 5V signal.     AC coupling the trigger like in Jack's schematic gets around the DC shift bit a 12V powered NE555 is going to need a bit more massaging to trigger from a 0/+5V trigger signal.
Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.


Rob Strand

Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.

Mark Hammer

I thought it was a new steam-punk edition of the Novation Launchpad series.

duck_arse

" I will say no more "


anotherjim

It's not a shaver, its a portable version of this...


And back on subject.
I've may be wrong, but I think Mark is using an existing circuit - his use may not have the same needs as the original design - the trigger arrangement can be whatever he wants. I'm pretty sure it can be worked direct into the 4017 clock, but it ain't my project.

amptramp

Quote from: kraal on October 21, 2020, 12:08:59 PM
Maybe it's a stupid question (maybe I'm missing the purpose of IC1 or the purpose of the whole circuit), but why not using something like this to avoid bouncing issues (with a SPDT switch) ?

https://tinyurl.com/y47eux7a

Where the resistor is your IC2.

Edit: modified circuit

This always works but it requires an SPDT switch.  Debouncing is for SPST switches.

Mark Hammer

That's more or less the issue.  Almost everything I see online either requires a momentary SPDT, or else relies on grounding out a SPST switch.  Mind you, if such a circuit generates the needed +5V pulse, I'm fine with that.

Mark Hammer

#38
Okay, will this work?  I gather as much, since I see identical circuits used to step 4017 chips in sequencers.  I was able to find a 74HC14 in my parts bin.  But what do I need to do with the 5 unused inverter/Schmitt triggers?

Rob Strand

QuoteIt's not a shaver, its a portable version of this...
And all that just for the A and B keys  :)

Send:     . .- .-. - .... / - --- / --. --- .-. -
According to the water analogy of electricity, transistor leakage is caused by holes.