Fixing my counter's bouncy button
Вставка
- Опубліковано 19 сер 2024
- A long tale of the trials and tribulations of debouncing my pushbutton!
-- Links
Debounce Your Noisy Buttons: hackaday.com/2...
Texas Instruments Hex Schmitt-Trigger Inverters Data Sheet: www.ti.com/lit...
Wolfram|Alpha: www.wolframalp...
Ultimate Guide to Switch Debounce Series: www.eejournal....
Ultimate Guide to Switch Debounce Part 9 (in case the search link above fails): www.eejournal....
-- Stuff
Logic Probe: amzn.to/3SfDRz4
7 Segment Display: amzn.to/3viAu1l
TTL ICs: amzn.to/40WH75c
Breadboard kit: amzn.to/3MYwfho
Power supply: amzn.to/3uAYxIE
Multimeter: amzn.to/49PUg45
Antistatic mat: amzn.to/49RhcQi
My Wife's Books: amzn.to/47yt9Ji
(Maybe you and/or someone you know will like them!) - Наука та технологія
You can learn from somebody or you can learn WITH somebody. I’ve gotten so much out of these videos, such an amazing gift!! Thank you!
40 years ago when I was in the Navy, we made debounce circuit. And gate and a number of inverters on one of the lines to cause a delay.
What if I told you that Digital Electronics is just a very square form of analog. 😉
Sometimes the 'old ways' are the only ways.
Well you wrote what I was thinking from the start of the video. that's how I was taught digital electronics over 30 years ago
You did your homework. De-bounce circuit is one of the basic circuits of the basic electronics course. It is a good explanation.
Appreciate you putting yourself out there in your learning experience. If you’re playing with electronics it’s definitely a good idea to commit the voltage divider and RC filter to memory. Also knowing a few different TTL logic chips is a good idea too!
This video is very effective to convince people the necessity of oscilloscope.You may not believe but some people exists that insists oscilloscopes are not necessary but a cheap logic analyzer is enough.
The reason for the 1k resistor in series with the switch is that it increases the time constant, so provides denounce during capacitor discharge.
No, it is really only there to limit the peak current through the switch.With lots of switches it isn't necessary because their contacts can handle high transient currents. With most "tactile" switches it is necessary because currents of more than a few tens of milliamps, particularly if the contacts are gold plated, can damage the contacts. Some switches are unreliable at low voltage and low current.
Usually you want the cap to be discharged very quickly so as not to introduce delay. It is the time it takes the capacitor to recharge to the upper voltage threshold of the logic device that provides the debounce time.
9:00 This has to do with the lower switching threshold of the IC.
If you had a 74LS or 74HCT (74AHCT) then the switching LOW threshold would be 0.6 volts.
With 74HC (74AHC) the LOW threshold is closer to 1.6V (VCC * 1/3)
A Schmidt trigger is the way to go.
Or use an NE555 as a Schmidt trigger.
an HF 74LS160N has a VIL of 0.8V (VIH = 2V). 10K over 1K should give us 0.454V. So I don't understand why the counter did not increment at all? It should be going from 5V to 0.45V and so it should have worked.
You're right on the money with the reset circuit. On power up capacitor acts basically as a short.
Capacitor will discharge on its own through VCC pin and pull up resistor and also through the reset input.
Just use smaller capacitor to make it work reliable instead of resistor across capacitor otherwise you are making potential divider and reset might not be held to the positive rail but something lower.
On debounce circuit - it does work without shmitt logic gate. I did put it together just to double check. Don't do the R*C calculation tho, please use RC filter calculator to see what frequencies are being cut. for 1k and 100n that'd still let 1kHz spikes through.
What could happen is that you did not pull the voltage low enough to trigger this certain chip.
TTL chips of "LS" series are built slightly different and contain pull-up resistors on the inputs.
The value varies by the manufacturer tho, it could have happened that that resistance paralleled to your 10k resistor in conjunction with 1k resistor connected to the ground did not allow the voltage to fall below 0.8V which is logical "0". But that's me guessing.
Good work figuring it out :-)
It is actually quite difficult to design a power-on reset circuit that performs well. Where things typically go wrong is with brief power outage that doesn't allow a poor POR circuit design to be ready to work proplery when power is restored. I have some name-brand Ethernet switches that have poor POR circuits with the consequence that they don't reset properly on a brief AC mains power drop.
LS-TTL is highly consistent from one manufacture to another. Of course it is now essentially obsolete and has been for a number of years, though many parts are still being made. The inputs don't have pull-up resistors. The inputs are "current sourcing" - "conventional current" (which flows from positive to negative) flows out of the inputs. In order to establish a LOW condition at an input the voltage must be pulled to 0.8 volts or less with respect to circuit ground. With LS TTL the specified current sourced by an input is 0.4 mA. That means if you try to pull the input down with a resistor, that resistor should be no greater than 0.8 V / 0/4 mA = 2000 ohms. You actually also have to be able to provide 20 microamperes (again, "conventioal current) into an input to assure it will meet the minimum logic HIGH threshold voltage.
It is very much time constants that matter in debounce circuits, not frequencies as such. Switches from major manufactures will almost always have a bounce time specification, and what you need to assure is that the debounce circuit is designed based on that time. Depending on the characteristics of the input of the device you are using a simple RC product may be very close with regard to time (e.g. with 4000 series CMOS LOW and HIGH are 1/3 and 2/3 of the ICs supply voltage. In one time constant of an RC circuit the capacitor will charge to about 63% of the applied voltage, so it all works out quite conveniently.
@@d614gakadoug9
That's why there are specialized PoR circuit that can guarantee you that reset has been issued properly but I think that's for now beyond the scope of breadboard experimenting. :)
For ther pull-up resistor and capacitor as the RC circuit yes, the R*C is its time constant, as in PoR circuit, but by introducing extra resistor in series with the switch it is becoming more of a RC filter.
If you look at LS series inputs schematic you'll find there's shottky diode on the input and resistor divider biasing the transistor base. And it all adds up. Actually you can skip the external pull-up resistor and it'll still work. I've seen (as per pdf) different values for the resistances there, usually around 15-20k
@@joruss
The extra resistor, in most debounce circuits, has negligible effect on the timing since it *must* be low in value relative to the pullup resistor with any TTL-compatible input where the voltage can be no higher than 0.8 V for LOW. It is there for one purpose - to limit the peak current through the switch contacts. Typically you might use 200 ohms or so in a 5 V circuit, limiting the peak current to 25 mA. You don't want to make the cap discharge time any longer than necessary so you don't introduce an unwanted delay between start of closure of the switch and response of the down-stream circuit. With a manually-operated switch a delay of even a few milliseconds probably is irrelevant.
The critical delay for debouncing is that produced by the capacitor and the pullup resistor. This is a simple problem in the time domain and transforming it to a frequency domain problem is just silly, in my opinion. If you are learning about this stuff it would add unnecessary and unhelpful complication. Effort would be far better put into understanding basic RC circuits in the time domain and learning how to relate an RC time constant to the time actually required for the voltage on the capacitor to reach the threshold required by the logic device.
_Vc = Vs (1 - e^(-t/RC))_
I'm very familiar with TTL input structures.
First, I have no clue what you mean by "And it all adds up."
The only diode, as such, is that from input to the "ground" of the IC. In normal operation only the tiny reverse biased leakage current of the diode comes into play and its existence can be ignored. The fundamental input circuit is a common-base transistor, the emitter of which goes to the input terminal. In many devices a multi-emitter transistor is used. In general practical terms the transistor behaves as a group of common-anode diodes. If one of the input is pulled sufficiently low the current from the resistor to the base (anodes) from Vcc (just a single resistor, not a divider) is diverted from the base-collector "diode" and the phase splitting transistor turns off. In reality there can be some true common-base transistor behavior in that carriers can actually be "sucked out" of the base region of the phase splutter, for faster switching which would be impossible with just diodes..
You can usually get away without using pullup resistors on unused input that need to be HIGH, but you shouldn't. It is bad practice that can lead to mysterious misoperation. The datasheets very clearly spell out that you must source a small amount of current into a TTL input to assure that it will meet the logic HIGH voltage threshhold.
@@d614gakadoug9 I see your point ov view. Yes, it's bit simpler in time domain.
Give it a second look how LS series inputs look. Datasheet for 74LS04 from texas instruments for example.
Thanks for the trip down memory lane… I was figuring this stuff out with data books and experiments in the late 1970’s…no internet…not UA-cam…just a breadboard and a bunch of TTL parts. Great way to learn! Such a feeling of accomplishment!!!! And yes, there is no difference between the digital and analog worlds-they’re just two sides of the same coin ;-)
In that era there was Don Lancaster's _TTL Cookbook_ which was pretty good. There was also an excellent TTL user's guide from Fairchild. Lancaster's book was aimed at hobbyists, the Fairchild guide at engineers, though most if it was pretty easy for anyone with some basics to follow.
This was very fun to watch and your logical process was spot on. I recently had to do the same thing for one of my projects and I was curious to see your solution. Its hard for me to tell if all your parts were TTL or CMOS but I'd say for the reset line you probably also want a pull up resistor on the reset input to make that RC circuit. Also check out 555 timers as they make great de-bounce and are just fun to play with.
A nice investigation. Bravo. Yes, caps for debounce and pull up/ pull down resistors to maintain the pin's voltage state. Yes, analog solutions are good, too... not just MCU code.
That's cool doing the debounce in the circuitry. I'm more into the programming and have and have always just been using a: millis() - time_since_last_input > THRESHOLD, programmatic solution to debouncing. I like the programmatic solution because it works with basically everything, it doesn't matter what's going on in the internals
Nice to see your learning process. Keep it up, you're doing great.
There's also the opposite application: actually wanting to make switches bounce. Bally had to do this on their pinball machines in the 80s. The CPU was so slow that it couldn't register very fast switch closures (which are quite common in pinball machines). So they fixed it by just slapping a capacitor across every single switch on the playfield. When a switch was closed, the capacitor is just dumped through the switch and the data line stays low while the capacitor charges up again. Just long enough for the CPU to notice that the switch has been pressed. So... that resistor in your circuit is quite crucial for it to work as a debounce, and not as an extra-bounce circuit. 🙂
Ha - that's amazing trivia! Thanks for that!
Making a simple oscilloscope using arduino is much easier than you 'd imagine. Of course, if you demand more, You could claim anything but very simple one would fulfill quite most of needs.
I followed that exact forum post for debounce on my project, and watching this I think I missed a bit.
Try CMOS logics. Inherently immune to bouncing, immune to supply ripple and can be supplied between 3.5V up to 15V unregulated.
SN74LS90 can be replaced by 40160B (up only) or 40168B (up-down) or 40192B (up-down). SN74LS47 (or SN74LS247) can be replaced by 4511B or 4543B. You can even replace both SN74LS90 and SN74LS47 with just a 4026B.
Prefix of CMOS logics are CD, HCF, HEF MC1, MM or TC.
Enjoy your self.
No, CMOS absolutely is not "inherently immune to bouncing." It may have a greater noise marginm will tolerate somewhat longer transition times in signals, and, depending on the family and supply voltage it may be slower, but it is going to see bounce in a mechanical switch just as badly as TTL does. Specified total bounce time for mechanical switches is rarely less than a millisecond. One thing you are slightly more likely to find with 4000 series CMOS parts is inputs in MSI parts that have hysteresis, saving the need for an external Schmitt trigger.
Many of the modern CMOS families are faster than even schottky TTL and certainly much faster than LS or standard TTL.
1:00 I felt that statement.
All unused inputs on your CD40106 must be tied to ground to avoid stray noise making it unstable.
Everyone is telling you that the capacitor should be smaller. They're wrong. Make it bigger to increase the "delay". Time Period or Constant (T) = R * C.
Two time periods/constants exist. One for charging (Tc) and another for discharging (Td) the ground coupled capacitor.
[14:35] Only calculates the time constant (Tc) for charging the capacitor through the pull up resistor.
Calculating the time required to hit each threshold:
Charging Time (tc) = -(Tc) * ln(1 - (Vt+) / (Vcc))
Discharging Time (td) = -(Td) * ln((Vt-) / (Vcc))
PS: The HACKADAY article is messing with everyone. Probably just meant to be a joke because it's full of intentional miscalculations. His time constants are in reality only microseconds long. He states that eveything exists in milliseconds. A lie fabricated for the purpose of causing you to fail. Personally, I think that is just pure evil.
When you are using TTL you must consider the current that flows out of the input when calculating the charge time for the capacitor. Essentially there is a resistor in series with a schottky diode between Vcc and the input. The resistor is typically in the range of about 10k to 15k for LS parts. You can probably ignore this current when calculating the discharge time with LS TTL as long as the current limiting resistor is less than a hundred ohms or so.
With CMOS parts the calculations are simplified because the static input current is, for practical purposes, zero.
Note: "current that flows out of..." is assuming "conventional current" which is considered to flow from positive to negative.
Cheap caps too brother. I've never had luck with them. I always use a 103 mlcc across the pins on the opposite side of the button. Unless I'm using 2pin tact switches on perfboard and I put the cap on bottom. Time is equal to Sqrt of 2nrc is the rate of charge to 63.3 percent I think. With the opposite leg of the tact switch to ground the cap discharges infinitely fast. Each switch and ic should technically be denounced and any unused ic pins are supposed to be pulled low but not many people do that with old logic ics unless you are making it permanent.
You need a calculator before you learn to use a scope brother. Not a knock. I jumped in and got a scope before I was ready.
The resistor would have to be one ohm for the switch to eat 5 amps but that would blow the anemic ams117 voltage regulator on the bb psu. You'd see smoke before the switch melted I think hehe. Learning is fun.
Cool video.
Paul McWhorter has a great course on the elegoo arduino uno kit and he teaches instead of showing. He's a great teacher. You learn all the stuff you wouldn't think of at first as a byproduct. You learn calculus without realizing it when he covers potentiometers. Haha. Everyone uses the map command but it's super inefficient, especially if your circuit has more than one pot to keep track of. He's an incredible teacher. He's a retired PhD engineer but you'd never know it because he's such a good teacher and makes learning fun. I can send you an arduino kit if you email me. If you're in US or Canada, it's on me. I always keep extra stuff on hand to send beginners who are excited to learn. No strings attached. My email is in my channel description. It'll save ya 100 bucks or so
I‘m really enjoying this video - thank you!
Some 30 years ago I used a 4017 decade counter and a 555 timer to make an LED chaser. The design was pretty good, but I had an issue with autonomous triggering out of cycle. I didn't have a scope, I was poor (I was still at school where electronics was limited to 2 lessons a year where you wired a pair of C cell batteries to a bulb holder and bulb - and that was it), I guessed there was radio like interference (my guess I know now was probably 100% spot on) because the incorrect triggering was significantly worse when my hand went anywhere near the board.
Capacitive induced RF is hard to avoid.
Hi,
in your first "RRC", pushing the button should have register, maybe you can make some diagnostics.
-> you minimum input voltage is C=Vcc/11 (if the counter consume 0 curent), is-it low enough ? Maybe 33k instead ok 10k can solve the problem ?
-> your capacitor is shorted or one resistance is bad or a bad connexion, check voltages with button on and off.
-> your button is dead (they are very easy to damage by soldering it and they don't all have the same pinout)
-> your capacitor does not seems to be a 0.1 microfarad one.
-> your slew rate is too slow to be register (input coupled internally by a capacitor + pull up/down resistor)
-> your impedance is too high (try 330 instead of 1k)
You are doing great ! Keep the videos coming. I liked and shared for your hard work at learning.
You really should get an oscilloscope! Siglent are pretty decent at reasonable prices!
I see an oscilloscope in your future. Inexpensive ones can easily be found online. For instance, several listed on Amazon at $100 or less with decent reviews.
The standard way of debouncing is by using a mono stable multivibrator and not a Schmidt trigger or RC networks.... A mono stable multivibrator is in fact a timer set to a couple of ten milliseconds.
Schmitt trigger debounce circuits are far more common from what I've seen and I've been in electronics for decades. You can get into trouble with a monostable triggered by a switch because it may trigger on both closing and opening bounce of the switch. A monostable is the right circuit to use if you need to "stretch" a clean pulse or shorten a long one, though in the latter case you have to be careful to select the right monostable.
Arduino you set pinmode to pull up and write a 1 so you can do the conditional on a zero. It's a hack
Whats missing is a schmidt trigger, otherwise it can still bounce due to input threshold
I prefer CMOS chips. Far superior to TTL and you aren’t strapped to a 5V power supply. You should look at the CD4026 IC and a CD40106. I can’t stand the 7400 series and everyone uses it.
I just made a 4-wire 12 button interface with multi sample input value suming and both hardware and software debouncing :D lmfao I feel so nerdy saying that and I'm still learning this stuff myself.
You will NEVER be able to run away from analog electronics... MUAHAHAHAHAHAHAHA!
Don't be mean!
Your statement is completely true, of course. The real world is almost entirely analog. Learning some basics is important if you want to understand circuits and certainly if you want to design them.
Liked and subscribed! Look forward to future videos in your journey. I'm on a similar journey myself.
With RC/LC...one is doing analog level delay shift of the signal..before further processing...
these are ok for analog signals where the time span is increased between 2 voltage levels to then process with
" schmitt trigger " ckt...
This also is ok in cases where the "switch " contacts have contamination & cannot swing to either extreme voltage levels..but may traverse midway..
For a good switch..., A single Physical switch closure will always have multiple bounces ,swinging to extrmes of supply...here voltage hysterisis/schmitt trigger , by itself is of no use.....
Here's where a non-retriggetred one shot.(monostable) is more effective.....this is a " time " dependent delay type filter.
i.e. within the monoshot time , multiple bounces are locked out, from causing false operations.
Somebody get this channel a scope! :D Great video.
Isn't it recommended to ground all the unused input pins to keep them from "floating"?
Just use a different switch. I take apart old mice and un-solder their switches and use them.
what about just putting a small capacitor in parallel to the switch?
That alone won't do the job.
With a digital input you must be able to establish conditions that fully meet the logic HIGH and LOW requirements. If you are dealing with CMOS, typically you don't have to worry about steady-state current into or out of an input, only about voltage levels. If you connect a switch from an input to "ground" ("zero volts") you have a way to get the input voltage to essentially zero volts which the vast majority of common logic families will accept as a good "0" or "LOW." A resistor between the input and the positive supply voltage for the device can be used to produce a good "1" or "HIGH" when the switch is off.
4000 series CMOS is convenient to consider because any voltage less than 1/3 of the supply voltage will be a good LOW and any voltage above 2/3 of the supply voltage will be a good HIGH.
Without a capacitor across your switch the pullup resistor to VDD (the positive supply for the IC) you get your good LOW when the switch is on and good HIGH when it is off, but if the contacts bound open then closed again you'll get an unwanted transition. If you put a capacitor across the switch, things get more complicated. When the switch is off, the capacitor will charge to VCC through the pullup resistor, so all is well in the steady state. When you turn the switch on, the capacitor will rapidly discharge (ignore the potential problem with high transient current through the switch). If the switch contacts bounce open, the cap starts to charge again through the pullup resistor, but as soon as the contacts close the cap will discharge. Depending on the R, C and switch bounce characteristics, the voltage at the input might actually stay at a good LOW through the whole bounce time, especially with 4000 series where the LOW threshold is quite high (5/3 or 1.67 volts for a 5 volt supply. With something that is specified to be have "TTL compatible" input voltages, you may have more problems since a good LOW must be no more than 0.8 volts. Bounce might allow the voltage to rise above that (which you can fix with a longer RC time constant, but that doesn't deal with the whole problem.)
When you release the switch things get messy. Now the capacitor is going to charge toward the supply voltage through the pullup resistor. It will take some time for it to make the transition between 1/3 of VCC (LOW) and 2/3 of VDD (HIGH; again considering 4000 series). An input voltage in that region is "forbidden" or more properly, the behavior of the device is undefined if the voltage is in that region. Any noise on the input or the power supply of the part can cause the device to switch, as can bouncing on opening. You must stay out of that forbidden voltage zone except when the signal is making a fast transition.
With devices with "hysteresis" the output state is defined for any input voltage. For example if the input has been LOW, it wouldn't be interpreted as HIGH until it rose 2/3 of VDD. If it had been high, it wouldn't be interpreted as LOW until it fell to 1/3 of VDD. Slow transitions are now OK. Digital gates with hysteresis are often called "Schmitt trigger" devices (Schmitt should be capitalized but often isn't). The actual logic zero and one thresholds will be specified in the datasheet. There are generally Schmitt trigger inverters and gates available in most logic families. Modern versions of the ancient 7414 hex Schmitt trigger inverter are available in most modern CMOS families. If you are using surface mount you can get a single Schmitt trigger device in a very tiny package. The CD4013 was a popular quad two-input NAND gate. Some microcontrollers have inputs with Schmitt trigger characteristics.A few logic devices may have hysteresis on a particular input. An example is the 74HC123 dual monostable multivibrator. Schmitt trigger devices are also good for converting any signal with slow rise or fall time to clean digial output.
5 amps at the button😂 I made the same assumption myself once 😂, you should read a little on the physics of electricity once you realize it is a transfer of information
Have you tried a grounding resistor from the button to ground
A condenser with 10pF should stop the bouncing
Capacitor* 😉
I was going to reply the same lol @@Rob_III
@@Rob_III Condenser is an older term for capacitor, it's the same thing.
@@mikepanchaud1 I know, I'm aware. In Dutch, my native language, it's also "still" called a "condensator". Doesn't mean that the common english term nowadays is capacitor and I wanted to clarify for people being confused by "condenser".
10 pF is far too little capacitance for any practical circuit.
Bounce time of typical switches is typically in the range of a few milliseconds, so you want a time constant at least that long. For a 5 ms time constant you'd need a resistor of 500 megohms with a 10 pF capacitor.
Even with CMOS devices it is best to keep resistances down in the range of 10 megohms or less. I'd stick with 1M or less in most circuits.