DIYstompboxes.com

DIY Stompboxes => Building your own stompbox => Topic started by: Mark Hammer on October 20, 2020, 10:44:02 AM

Title: Debouncing a momentary switch
Post by: Mark Hammer on October 20, 2020, 10:44:02 AM
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?
(http://www.muzines.co.uk/images_mag/articles/pl/PL_81_01_quad_sequent_2.jpg)
(https://i.imgur.com/nQ7NvCS.jpg)
Title: Re: Debouncing a momentary switch
Post by: vigilante397 on October 20, 2020, 11:20:04 AM
I generally throw a 100nF cap across the pins of a momentary switch. Fixes it 95% of the time.
Title: Re: Debouncing a momentary switch
Post by: Mark Hammer on October 20, 2020, 11:26:25 AM
Sounds about right.  I'll try that.
Title: Re: Debouncing a momentary switch
Post by: amz-fx on October 20, 2020, 11:43:40 AM
I was going to suggest .05uF in the same config.

(https://i.postimg.cc/tCBH673H/trig1.gif)

regards, Jack
Title: Re: Debouncing a momentary switch
Post by: 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.
Title: Re: Debouncing a momentary switch
Post by: marcelomd on October 20, 2020, 01:40:41 PM
An alternative is a small micro controller. 8 or16 pins.
Title: Re: Debouncing a momentary switch
Post by: Rob Strand on October 20, 2020, 04:52:39 PM
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.
Title: Re: Debouncing a momentary switch
Post by: mozz on October 20, 2020, 05:22:02 PM
The value of the cap is the time constant.
Title: Re: Debouncing a momentary switch
Post by: Mark Hammer on October 20, 2020, 05:35:12 PM
I tried 68nf and 330nf.  Neither did the trick.  Still kinda random.
Title: Re: Debouncing a momentary switch
Post by: Rob Strand on October 20, 2020, 05:46:34 PM
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.
Title: Re: Debouncing a momentary switch
Post by: Rob Strand on October 20, 2020, 05:58:52 PM
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.
Title: Re: Debouncing a momentary switch
Post by: bushidov on October 20, 2020, 06:55:36 PM
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.
Title: Re: Debouncing a momentary switch
Post by: Rob Strand on October 20, 2020, 07:52:03 PM
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.
Title: Re: Debouncing a momentary switch
Post by: mozz on October 20, 2020, 08:36:49 PM
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.
Title: Re: Debouncing a momentary switch
Post by: Ripthorn on October 20, 2020, 08:53:59 PM
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.
Title: Re: Debouncing a momentary switch
Post by: Rob Strand on October 20, 2020, 09:31:41 PM
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.)
Title: Re: Debouncing a momentary switch
Post by: R.G. on October 20, 2020, 11:15:13 PM
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 (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.
Title: Re: Debouncing a momentary switch
Post by: 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?
Title: Re: Debouncing a momentary switch
Post by: amz-fx on October 21, 2020, 08:55:52 AM
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
Title: Re: Debouncing a momentary switch
Post by: amz-fx on October 21, 2020, 09:49:36 AM
One of my drum synth designs from many years ago used this trigger input:

(https://i.postimg.cc/053DYLwX/trig2.gif)

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

regards, Jack
Title: Re: Debouncing a momentary switch
Post by: R.G. on October 21, 2020, 10:18:43 AM
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:
Title: Re: Debouncing a momentary switch
Post by: amptramp on October 21, 2020, 11:04:25 AM
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.
Title: Re: Debouncing a momentary switch
Post by: R.G. on October 21, 2020, 11:26:13 AM
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.
Title: Re: Debouncing a momentary switch
Post by: Rob Strand on October 21, 2020, 11:53:38 AM
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.)
Title: Re: Debouncing a momentary switch
Post by: 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
Title: Re: Debouncing a momentary switch
Post by: Ben N on October 21, 2020, 01:07:35 PM
Quote from: R.G. on October 20, 2020, 11:15:13 PM... I like either a vertical adder ...
Must be a Texas thing.
(https://ichef.bbci.co.uk/news/1024/branded_news/6EB0/production/_103963382_adder2.jpg)
Title: Re: Debouncing a momentary switch
Post by: Mark Hammer on October 21, 2020, 03:57:20 PM
So would this circuit generate the needed pulse? (100ms wide)
(https://www.electronics-tutorials.ws/wp-content/uploads/2019/07/tim71.gif)
Title: Re: Debouncing a momentary switch
Post by: anotherjim on October 21, 2020, 05:10:39 PM
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.
Title: Re: Debouncing a momentary switch
Post by: Mark Hammer on October 21, 2020, 05:37:36 PM
The "it" being the 555 timer circuit or the 4017 itself?
Title: Re: Debouncing a momentary switch
Post by: Rob Strand on October 21, 2020, 06:30:32 PM
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.
Title: Re: Debouncing a momentary switch
Post by: PRR on October 21, 2020, 10:11:04 PM
Quote from: Ben N on October 21, 2020, 01:07:35 PM
Quote from: R.G. on October 20, 2020, 11:15:13 PM... I like either a vertical adder ...
Must be a Texas thing.

(https://www.typewriter.be/images/remington21verticaladder-01.jpg)

https://www.typewriter.be/remington21verticaladder.htm
Title: Re: Debouncing a momentary switch
Post by: Rob Strand on October 21, 2020, 11:54:41 PM
Quotehttps://www.typewriter.be/remington21verticaladder.htm
Old school programmable shaver.
Title: Re: Debouncing a momentary switch
Post by: Mark Hammer on October 22, 2020, 08:51:39 AM
I thought it was a new steam-punk edition of the Novation Launchpad series.
Title: Re: Debouncing a momentary switch
Post by: duck_arse on October 22, 2020, 09:31:43 AM
Quote from: Rob Strand on October 21, 2020, 11:54:41 PM
Quotehttps://www.typewriter.be/remington21verticaladder.htm
Old school programmable shaver.

where do you put your face?
Title: Re: Debouncing a momentary switch
Post by: kraal on October 22, 2020, 09:46:56 AM
Quote from: duck_arse on October 22, 2020, 09:31:43 AM
Quote from: Rob Strand on October 21, 2020, 11:54:41 PM
Quotehttps://www.typewriter.be/remington21verticaladder.htm
Old school programmable shaver.

where do you put your face?

Who said it was for the face ? ;)
Title: Re: Debouncing a momentary switch
Post by: anotherjim on October 22, 2020, 10:29:33 AM
It's not a shaver, its a portable version of this...
(https://i1.wp.com/120years.net/wordpress/wp-content/uploads/2013/09/guntersmagazine1907-4.png?resize=670%2C1024&ssl=1)

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.
Title: Re: Debouncing a momentary switch
Post by: amptramp on October 22, 2020, 03:25:35 PM
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.
Title: Re: Debouncing a momentary switch
Post by: Mark Hammer on October 22, 2020, 05:08:33 PM
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.
Title: Re: Debouncing a momentary switch
Post by: Mark Hammer on October 22, 2020, 05:40:59 PM
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?
(https://media.cheggcdn.com/media%2Fa61%2Fa61a21b4-0228-4ea3-b8be-00a103588a19%2Fimage)
Title: Re: Debouncing a momentary switch
Post by: Rob Strand on October 22, 2020, 06:26:46 PM
QuoteIt's not a shaver, its a portable version of this...
And all that just for the A and B keys  :)

Title: Re: Debouncing a momentary switch
Post by: Rob Strand on October 22, 2020, 06:55:42 PM
QuoteOkay, will this work?
In order to drive the 4017 you will need to power it from -6V and 6V.     Since the supply is effectively 12V you will then need to use a 74C14 or 40106 chip, as the common 74xx devices are roughly for 5V.   It might fix the switch but it still leaves the problem of the trigger.

From the 40106 datasheet the Schmitt thresholds for 12V,

                                min      typ     max
VP                           5.7      7.4      9.0
VN                           3.3      4.9      6.3
VH  (VP-VN)          1.3      2.9      4.2

While VH max of 4.2V implies you could use a 5V pulse, you would need to bias the input.     If you biased to 9.0V to meet VP max  then 9.0 - 5 = 4.0V   cannot meet the VN min of 3.3V.   In other words a 40106 powered from 12V won't work all the time with a 5V input pulse.

So another option is to power the 40106 from 6V  then you would need an open collector or open drain switch and a resistor to -6V to drive the 4017, which is powered from +/-6.   

All looks too messy.


Why not just try  a different opamp in the original circuit?
Title: Re: Debouncing a momentary switch
Post by: R.G. on October 22, 2020, 06:57:27 PM
I wish the vertical adder was something even nearly as clever as the proposed ones. Those are great ideas for new designs, though!  :icon_lol:

A vertical adder can be thought of as a bank of memory locations. The ongoing results are a vertical slice through the bits, not horizontally across one memory word. So, for instance, if you were using a four bit result, you would use bit 0 (lowest order bit of four different memory words) as the four bit word. Word 0 holds the LSB, wtoord 1 holds bit 1, word 2 holds bit 2 and word 3 holds the MSB. If all the words are cleared to 0, there is 0 in your first four bit word in bit 0 of all the four memory words (and everywhere else).

bit number.........7 6 5 4 3 2 1 0

memory loc  3 = 0 0 0 0 0 0 0 0
memory loc  2 = 0 0 0 0 0 0 0 0
memory loc  1 = 0 0 0 0 0 0 0 0
memory loc  0 = 0 0 0 0 0 0 0 0

In this setup the "words" you're interested in are >vertical< as in "all the bits vertically under bit number 7" is one, all the bits under bit number 6 is a different word, and so on, eight at a time.

If we read 8 pins on the uC, and some of them are 0, others are 1, we can shift that reading into memory location 0. Let's say we only have six input pins we're reading, and we read x x 0 0 1 0 0 1, the "x" meaning the value doesn't matter as it never gets used. So the memory contents become:

bit number.........7 6 5 4 3 2 1 0

memory loc  3 = 0 0 0 0 0 0 0 0
memory loc  2 = 0 0 0 0 0 0 0 0
memory loc  1 = 0 0 0 0 0 0 0 0
memory loc  0 = x x 0 0 1 0 0 1

Some time later, we read the pins again and get "x x 0 0 1 0 1 1"; the memory becomes:

bit number.........7 6 5 4 3 2 1 0

memory loc  3 = 0 0 0 0 0 0 0 0
memory loc  2 = 0 0 0 0 0 0 0 0
memory loc  1 = x x 0 0 1 0 0 1
memory loc  0 = x x 0 0 1 0 1 1

The previous value was just shifted up one location, because the operation we're doing is vertical shifter. If we did a vertical adder, we could simply do the boolean operation for adding the input to memory location 0, instead of shifting. Shifting is simpler to show.
Next read, we read x x 0 0 0 0 0 1, and the memory locations become:

bit number.........7 6 5 4 3 2 1 0

memory loc  3 = 0 0 0 0 0 0 0 0
memory loc  2 = x x 0 0 1 0 0 1
memory loc  1 = x x 0 0 1 0 1 1
memory loc  0 = x x 0 0 0 0 0 1

And one more reading, which shows input pins of "x x 1 0 0 0 0 1" to give

bit number.........7 6 5 4 3 2 1 0

memory loc  3 = x x 0 0 1 0 0 1
memory loc  2 = x x 0 0 1 0 1 1
memory loc  1 = x x 0 0 0 0 0 1
memory loc  0 = x x 1 0 0 0 0 1

We look at vertical rows for debouncing. The lowest order bit position shows four sequential 1s, so presumably the pin that feeds the bit number0 position can be confirmed as a 1. Bit number 2 and 4 have stayed zero for four readings, so they're debounced to 0. Bits 1, 3, and 5 are wobbling around and have not settled.The timing on checking things is important. I use a time of 10mS to 20mS between sampling inputs, so in this example, the time spent for getting a stable debounce is four sampling times. Even horribly bouncing switches tend to settle in 50mS to 100mS.

Why go to something this complicated? Well, for shifting it might be just as easy to go with horizontal shifts, all the incoming bits going into their own memory location; and I have done that as well. However, if you want to do something fancy, like making a running sum of inputs, or ensure that all the inputs are sampled simultaneously, the vertical form works very well, down to a uC cycle. Another is easy masking or different operations on different inputs. In one variant of this, I used a mask word to make debounced switches with a 1 in the mask word be a "toggle" and a 0 caused the input to be a momentary.

Not as fun as vertical pit vipers, but ... what can I say? I'm a computer nerd.  :icon_lol:
Title: Re: Debouncing a momentary switch
Post by: Rob Strand on October 22, 2020, 08:08:59 PM
The power supply design looks a bit marginal.   Maybe the problem is the power.   You might expected the 100uFs to save it but maybe not.

The LEDs are drawing 3mA.

Without the LEDs the zener current is only (9V - 6.2V) / 1k = 2.8mA.

That means any load is going to cause the power supply rail to drop below the zener voltage.
The 3mA LED current is going to cause a 3V drop across the 1K resistor and pretty much rob all the zener current, then the zener won't be doing much regulating.

The nominal zener voltage is 37mA for 6.2V and we probably shouldn't go below 3.7mA to even remotely regulate.      So 3.7mA zener and 3mA LED means we should target 6.7mA through the power supply resistors.

Rpsu = (9 - 6.2) / 6.7mA  = 417 ohm

So we'd probably want no more than 470 ohms instead of 1k's.

I'm not saying that's the problem but it is a possible hole in the design.    The 100uF caps should hold-up the rail but maybe it's not good enough.  The thing is, if the supply glitches it could glitch the clock, it could also glitch the reference voltage for the Schmitt-trigger (R6, R7)
Title: Re: Debouncing a momentary switch
Post by: Mark Hammer on October 22, 2020, 08:33:46 PM
The datasheet for the 74HC14 gives its operating voltage as 2-6VDC.  I figured I'd us the +6.2V line and drop it with a diode.

But while I'm here, just thought I'd say I appreciate the thought you folks are putting into this.
Title: Re: Debouncing a momentary switch
Post by: ElectricDruid on October 22, 2020, 08:40:20 PM
I've seen a different implementation of a vertical counter by Scott Dattalo. Unfortunately the website where he described it no longer exists. Rather than using a byte per reading, like RG suggests, it uses bits like a standard binary counter. So you can count to four with only two bytes vertically.

Here's PIC code for it:


;---------------------------------------------------------
; Test and debounce the digital inputs
;---------------------------------------------------------
; Do Scott Dattalo's vertical counter debounce (www.dattalo.com)
; This debounces eight inputs on PORTA.

; Increment the vertical counter
movf.        DEBOUNCE_LO, w
xorwf DEBOUNCE_HI, f
comf.       DEBOUNCE_LO, f
; See if any changes occured
movf.        PORTA, w
xorwf IN_STATE, w ; Test for changes
; Reset the counter if no change occured
andwf DEBOUNCE_LO, f
andwf DEBOUNCE_HI, f
; If there is a pending change and the count has rolled over
; to 0, then the change has been filtered
xorlw 0xFF ; Invert the changes
iorwf DEBOUNCE_HI, w ; If count is 0, both..
iorwf DEBOUNCE_LO, w ; ..A and B bits are 0
; Any bit in W that is clear at this point means that the input
; has changed and the count rolled over
xorlw 0xFF ; Invert the changes
xorwf IN_STATE, f ; Update the changes
; W is left holding state of all filtered bits that have changed.
movwf IN_CHANGES


It's a neat method for debouncing eight inputs in only a few instructions (all credit to Scott, not me). And having STATE and CHANGES variables afterwards is very useful for detecting various different states (you can toggle things based on CHANGES, or you can just follow STATE) so you can do momentary or latching code without difficulty.

HTH,
Tom
Title: Re: Debouncing a momentary switch
Post by: Rob Strand on October 22, 2020, 08:41:44 PM
QuoteThe datasheet for the 74HC14 gives its operating voltage as 2-6VDC.  I figured I'd us the +6.2V line and drop it with a diode.
Yep, if you can power the Schmitt-trigger off one rail you can use the 74HC14 (the *absolute max* is 7V)..    However the 74HC14 output will swing 0 to 6.2V (approx) but the 4017 clock needs -6V to 6V.
Title: Re: Debouncing a momentary switch
Post by: Rob Strand on October 22, 2020, 08:54:49 PM
Something like this is about as simple as I can think of.

Note you need to use two Schmitt-triggers to emulate the original circuit.


(https://i.postimg.cc/nswF2qMN/Level-Translator-V1-1-2020-10-23.png) (https://postimg.cc/nswF2qMN)

The clock will swing -6V (via resistor) and +6V via transistor *and* gate output.


This one is more conventional but uses an extra resistor,  you might be able to remove R3 anyway,


(https://i.postimg.cc/FfJrP7cR/Level-Translator-V2-0-2020-10-23.png) (https://postimg.cc/FfJrP7cR)
Title: Re: Debouncing a momentary switch
Post by: anotherjim on October 23, 2020, 02:31:37 PM
Have to say that I absolutely hate panel push buttons for direct switching plain logic. They are rarely well made, no matter how big & chunky. Keep then for the bell push!

I prefer direct switching with a spring biased toggle.

(https://i.postimg.cc/023C4w4w/4017step.png)

Top is a simple switch. I'm assuming the external jack is for a momentary footswitch and carries no signal and sources no voltage. Using the 4017 Schmitt input and RC debounce.
Below is prefered flip-flop arrangement with biased toggle. Need no cap to debounce. External input not so easy to provide - may need a cap across it. Thing with the flip-flop is that the switch contact would have to bounce all the way to the opposite throw to bounce the output.
VDD is +6v and VSS -6v.

Title: Re: Debouncing a momentary switch
Post by: marcelomd on October 23, 2020, 05:54:33 PM
Debouncing in software is one of those things that you end up coding over and over again. It's always the same thing (checking a stream of bits), but different enough (read operation, number of bits, multiplexing, etc.) that you can't have a standard library.
Title: Re: Debouncing a momentary switch
Post by: R.G. on October 23, 2020, 11:02:19 PM
Quote from: ElectricDruid on October 22, 2020, 08:40:20 PM
I've seen a different implementation of a vertical counter by Scott Dattalo. Unfortunately the website where he described it no longer exists. Rather than using a byte per reading, like RG suggests, it uses bits like a standard binary counter. So you can count to four with only two bytes vertically.
I've used that variant before as well. It's a very clever idea - and Scott's page is what got me started on the idea. The logic operations between each horizontal stage are open to modification. I used it a byte wide, eight inputs wide, and two stages tall, binary encoded, and added masking and so on. I deliberately skipped the byte-wide logic operations for computing add and carry so that the operation would be clearer. As you say, all thanks to Scott for explaining it to me.

Title: Re: Debouncing a momentary switch
Post by: ElectricDruid on October 24, 2020, 02:31:10 PM
I miss that website! I'd have liked to have known what else he might have come up with. Now he's probably got a *proper job* or something...sigh...poor chap.

Still, Wayback Machine ftw!

https://web.archive.org/web/20060222014359/http://www.dattalo.com/technical/software/software.php (https://web.archive.org/web/20060222014359/http://www.dattalo.com/technical/software/software.php)
Title: Re: Debouncing a momentary switch
Post by: Rob Strand on October 24, 2020, 06:32:00 PM
QuoteI miss that website! I'd have liked to have known what else he might have come up with. Now he's probably got a *proper job* or something...sigh...poor chap.

Still, Wayback Machine ftw!

https://web.archive.org/web/20060222014359/http://www.dattalo.com/technical/software/software.php
Unless you come across it in a course, only hardcore micro programmers know about non-restore binary square roots.