Switch debouncing

For one of my projects I decided to use a momentary switch(where its held on as long as you push it in and when you release it will disconnect... I think its called momentary switch). The switch basically selects presets and I will have a couple of them. The idea is like the buttons on a blender where you press one and it mechanically turns off all the others. I'm trying to do the same thing digitally. i.e., if I press button A it will turn off all the others(only one will be on ofcourse). I do this by basicaly using toggle FF's.

The main issue I have, I think, is the switch debouncing part of it. I've look on some web sites and they basicaly give a few methods such as a simple filter circuit(which I think won't work on mine because of the switch type) and an monostable vibrator. Anways, I feel that I can do this with just some resistors and capactiors. By looking at the idea for a monoastable vibrator where they used a capacitor to "slow the change" I figure I can sorta do the same.

Basicaly the way I see it is that when the switch bounces it will discharge a capacitor... the more bouncing the more discharge. By setting the capacitor to slowly charge but discharge quickly when the switch is pressed the voltage across the capacitor is 0... any bouncing will discharge the capacitor as it slowly charges. By using a schmitt trigger then I can get a high only after the capacitor has charged enough. By setting the time constant one should be able to get rid of the bouncing(its effect is to length the time it takes to charge).

The circuit is

---- Schmitt Trigger - Out | V --- R1 --+-- Switch --- R2 --- GND | --- C1 -- GND

What I'm wondering is if this is an effective circuit(i.e., if its practical). I can simulate it and it seems like it would work but I have no idea if it will work in the real world(and I have no components to test it but will order some soon after I get a general idea what I need).

I figure the only problem is that if the person pushing the button pushes it to fast then it will increase the time the button is "activated" and it won't change anything... not sure if one could get the time constant down enough so that the bouncing is fixed but not part of the button pressing of the user.

Heres a link to the a pic:

formatting link

the green is ofcourse the charge on the capacitor(well, voltage) and the red is my "output". Whenever I hit the switch the capacitor discharges(drop on the green line) rather quickly and tries to "recover". Each suscessful time I hit the switch I try to hit it several more times a row to simulate the bouncing. Note at the last time there are two red "boxes" next to each other which would be problem I think... I think this can be fixed with setting the appropriate resistor and capacitor values though.

Any ideas?

Thanks, AD

Reply to
Abstract Dissonance
Loading thread data ...

formatting link

It's got a good bit of research on the problem, and ways to solve it with various hardware and software solutions.

Cheers, Richard

Reply to
Richard H.

?

I'm toggling though. If the switch bounces an odd number of times I'll end up toggling it to the same state it was(hence no toggle) ;/ right?

i.e.

In - Toggle FF - Out

if In = 1 then Out = 0, if In = 0 then Out = 1... i.e. basicaly an inverter except it holds the state... so consecutive presses of the button will toggle the original state... but since the switch will bounce those consecutive presses could be from the bounce and there might be a random number of them.

I hope so ;)

Reply to
Abstract Dissonance

Cool. While from glancing over it I don't think it deals with momentary switches I might be able to adapt one of the methods.

Thanks, AD

Reply to
Abstract Dissonance

Ben was suggesting this set-up:

buttons: A, B, C, reset

setA = A resetA = B+C+reset setB = B resetB = A+C+reset setC = C reset C = A+B+reset

This uses s-r bistables (set/resetA, set/resetB...). The ON buttons simply sets its own bistable as well as resets all other bistables. An extra reset button simply resets all bistables. This requires a lot of OR gates. Of course, you can diodes and pull-ups to implement wired-OR.

In this set-up, there is no toggling. So you don't have to really worry about debouncing.

Reply to
slebetman

yes, but its cause the button itself is not a switch but a momentary button. So the button is always off except for a few impulses.. this will cause the state to toggle "randomly". This is similar to a standard switch but the standard switch always toggles its state after the bounces(so after a little time the switch will be in the opposite state... for the momentary switch it always ends up in its same state after a little time).

using your method also will not physically "push" out the button like it does on a blender. Hence if I used blender like switches there would be an "in" state and an "out" state... something I want to avoid.. I just want an out state basicaly... but when pushed in it "momentarily" shorts across the switch(but doesn't hold it else I gotta figure some way to "undo" it when other switches are pressed(like the blender does)).

So the problem is more serious than a "latching" type of switch since you have to digitally latch it.

Maybe this is the way to describe it: say you have a telephone pad. You want it so that the puttons are momentary... i.e., when you push them it makes contact only for a very short period of time(a few ns or so guess?) but the tone produced lasts until another button is pushed... each button corresponds to some different tone but you don't want to hear multiple tones simulataneously.

i.e., I'm kinda converting a momentary switch into a SPST digitally. I can't use a SPST because of the design I want but I need the momentary switch to act like one. With an normal SPST switch, like I said before, the state will end up, if 0, a 1 after the bounces... so even if you don't worry about the bounces then you will still get a toggle...

for the momentary switch though... when you push it, it will go from 0 to 1 for a few ns then back to 0. Hence you can make it into an SPST with a toggle... but then cause real switches bounce it causes a toggle with each bounce.

There might be a better way to do this though... its just the method I came up with when trying to do my project.

The reason why you can't use some switch that stays in its state when switched is cause somehow you have to mechanically switch the switches state when another button is pressed. The blenders do this mechanically with a lever I guess but I don't think there is a way to do it electronically(except maybe some type of relay like switch). My idea is to allow the buttons to only go into a "set" state mechanically for an instant but to keep track of them digitally.

I could do this in software with an MCU probably much easier by just hooking up each button to an in pin and then detecting when one is changed and just remember it... ignore the bounces and then listen again and on a set just toggle the value stored.

heh, to be a little more clear suppose this circuit is simulated

VCC --- Momentary Switch --- Toggle Flip flop --- resistor --- GND

the Switch is such that when you press space bar the switch is made contact with and a short results across it only for an instant. (i.e., its a momentary switch that you can control by hitting your space bar). Now each time you hit the space bar the output at Out is inverted

now in reality there will be a mechanical bounce that occurs randomly... it would be like hitting the space bar several times in a row... each hit will toggle the output... after n hits the state will be 0, say, if n is even and

1 if n is odd.

you can also think of the momentary switch simply as a SPST switch which is used in such a way that one turns it on then off really quick... never letting it stay switched on for more than a few ns. (ofcourse this requires pressing the button twice to do this while for the momentary switch it is only once). Now the SPST basicaly almost always is in the off position except for "spikes". These spikes can't control the T on a normal flip flop cause immedately when you set T you reset it so its always 0.

I don't know... maybe that makes some sense ;/

Thanks, AD

Reply to
Abstract Dissonance

well, I don't really like the idea of the reset button. It requires the user to press two buttons for just one. There are two reasons for this, one I feel it is inconvienent and not very pratical for the application(the switching has to be seemless not non instrusive as much as possible) and there is limited room. I at most can have 4 buttons(or so, it depends) if that. Each buttons represents a present and I'd rather have 4 presents than

3 and a reset. This is the reason for the specific use of the momentary switch and having to "toggle" and stuff instead of just using a couple of SPST switches.

AD

Reply to
Abstract Dissonance

Ironically, in this application, a bouncing switch won't do anything different than a perfectly operating switch (once a button 'selects' a FF, 'selecting' it again won't change anything).

Long lecture short, you're on the right track. :)

Reply to
Ben Bradley

You might consider this approach in which contact bounce is irrelevant:

Use the temporary closure of the momentary switch contact to activate a latching relay. This relay could be in any form -- mechanical, solid-state. The output (or contact closure) does whatever you want. Multiple switch activations (or contact bounce) will have no effect as the relay is already locked. This circuit would be replicated for each "blender speed" desired.

Concurrently, the output of the momentary switch is fed to the reset function of all other latching relays. This latches them in the "off" mode and again, multiple pushes of the button or any contact bounce is irrelevant as the first pulse has locked the relay in the off mode.

To test this, I spent 5 m> For one of my projects I decided to use a momentary switch(where its held on

Reply to
GrandPaBobby

So this thing only has two states? I was thinking of the blender mechanism with eight or so buttons. To do it with digital logic, each button would go to the set input of its FF, and the reset inputs of all the others (through diodes or OR gates), thus pressing a button will ALLWAYS set its respective FF and clear the others.

Reply to
Ben Bradley

If you can use a SPDT momentary switch, here's an easy way to debounce: Connect 2 2-input NAND gates in a latch configuration (Output of gate A to one input of gate B; Output of gate B to one input of Gate A. Connect the two "fixed" switch terminals to the two remaining gate inputs. Connect the "swinger" of the switch to ground. This circuit will de-bounce for an indefinite bounce period. The only restriction is that the switch "swinger" can not bounce between the other 2 contacts. This should not be a problem. I've never seen a SPDT swith (or relay) that does this.

Reply to
Jon

I don't get it ;/ (sorry.. but I just started in EE about a week ago ;))

oh, I get it now. duh ;) I wasn't think about the other buttons. You guys are right. Not even sure why I wanted to do the toggling now ;/ Maybe it had to do with something else or I was just being dense. I was focusing so much on the single switch but for my application I don't need it. Not sure if I had something else in mind or if I was just being stupid. Brain is kinda fried right now... to much work.

Thanks, AD

Reply to
Abstract Dissonance

yeah, I think I got it now. Not sure what I was thinking but I got into the idea about just using one button or something and didn't realize how the others would make it much easier. (cause in fact I don't want to toggle the switches ;)

I think I was looking at some small tree and forgot I was in a forest.

Thanks, AD

Reply to
Abstract Dissonance

user

than

You're not getting Ben's idea. There is no reset button and there are no SPST switches in his setup. Each momentary switch will genereate a pulse when you press and then release it. This pulse is used to set its corresponding flip-flop and to reset the others. Lets assume flip-flops with active low set and reset inputs like the 7474. Each switch is connected to the 0V on one side and the other side to the (pre)set input of its own flip-flop and, through diodes (anode to reset), to the reset (clear) lines of all other flip-flops. Note that you will need pull-up resistors (to +5V) on the set and reset inputs of all flip-flops so that these inputs are in a known (inactive) state when no switches are being pressed. Bouncing is now no longer an issue because it are just more pulses that cannot change the state of the flip-flops once they are set by the first bounce/pulse. Still assuming a 7474, you should also tie all the D and CLK lines (all unused inputs) to a power line like 0V.

If my count is correct, for 4 switches you will need 2 7474, 8 resistors (10k) and 12 diodes (1N4148 or something like that).

--DF

Reply to
Deefoo

...

Notwithstanding what Ben Bradley said about an R-S flip-flop if it gets multiple "sets" or "resets", to answer your debouncer question, lose R2, and go directly from the switch to ground:

That will immediately discharge the capacitor, and with the Schmitt, it doesn't matter how long as it takes to charge, as long as it's quicker than the next time they push the button! ;-)

There are also "Jeopardy buttons"-type circuits on the internet, which would give you your lockout, but with independent buttons, you might even not need that much logic - there isn't going to be any competition between the buttons, so you don't need a priority resolver, just a - OK, I think I've got it.

Take another capacitor, from the switch/R1/cap/ST junction, about 1 nf, and on its other side, put a 1K or so resistor to +Vcc. Condition that with a couple of diodes, (one each to +Vcc and to ground, reverse biased, of course - this clamps the spike), and send it to the "reset" of _all_ of the flip-flops. It resets them, and then the "set" signal from your button sets the target flop.

Kewl! I'll try not to dislocate my elbow patting myself on the back. :-)

Cheers! Rich

Reply to
Rich Grise

...

Are you saying that you have "switches" that, when you press them, you don't know what the state of the switch will be after it gets done bouncing? Even while your finger is still holding it down? ?:-/

If so, then you need to find a real switch.

Good Luck! Rich

Reply to
Rich Grise

Why do you need 12 diodes? Can't you just make a negative OR with 4 of them, and feed all of the resets?

Of course not.

But, if you differentiated it, you could. Just make the negative-going edge a spike by capacitating it, and they'll all clear, and the one with the button down will set when the capacitator charges and it comes out of its indeterminate state. ;-)

Cheers! Rich

Reply to
Rich Grise

Good that you finally understand it (I used + for OR by the way, probably should have used the c-like | symbol instead).

I still think you need that reset button. Consider the blender again. There must be a button to turn it OFF instead of just changing speed. Unless of course that is not important in your application. Don't you usually find something like:

[ 1 ] [ 2 ] [ 3 ] [OFF]
Reply to
slebetman

In that case, have you considered using a rotary switch for this? I know it's a mechanical solution but those mini rotary switches are really small.

Reply to
slebetman

Well, the problem was that I was originally going to have it so n buttons acted like a group. You would make a button combination to select a preset. So with n buttons one would have 2^n potential combinations... then I figured that it might just be to much trouble to do that and much easier just to have one button per preset but got hung up on the debouncing stuff. Its still something I want to look into though since its been pretty interesting.

Thanks for the help though. AD

Reply to
Abstract Dissonance

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.