74HC14 for debouncing - question about the type of capacitor - Page 1
Forum section: electronics / beginners

author: bodzio_stawski
author_rank: Regular Contributor
timestamp: August 14, 2022, 07:13:54 am
content: Hello!I am trying to analyze some layout solutions aimed at reducing the button reflection effect (especially with 74HC14 IC).I will use one of the most common system solutions from the internet:I am aware that eliminating debouncing by software solutions is the most flexible solution to the problem anyway. However, insisting on this circuit, I am thinking about the type of capacitor.A schematic like that suggests that when the breaker is closed, the capacitor will discharge through R2. The capacitor, by maintaining some potential on the line for a while, will mask any bouncing of the switch.My question:The use of a capacitor, as well as the nature of the disturbance it is supposed to eliminate, would suggest that it should be a polarized capacitor with quite a large capacity.Meanwhile, I often find diagrams with a non-polarized capacitor. Even without a capacitor discharging resistor, with which it lives in symbiosis and determines its discharge rate. If we can afford the circuit for reducing debouncing effect, why not use, for example, tantalum capacitors instead of 100nF ceramic, which is sensationally often seen on ready-made PCBs?

author: retiredfeline
author_rank: Frequent Contributor
timestamp: August 14, 2022, 07:38:25 am
content: HC being CMOS has high imput inpedance so you can raise the value of the charging resistor and bring the capacitor value down to sub-µF. You just need enough time constant to tide over contact bounce, not the entire depression.

author: jfiresto
author_rank: Frequent Contributor
timestamp: August 14, 2022, 07:44:37 am
content: +1. I would favor the first circuit. Its CMOS inverter allows you to use a small C and a large R2 to produce the desired RC switch debouncing time, for example, a 100nF capacitor and a 220K resistor.

author: RoGeorge
author_rank: Super Contributor
timestamp: August 14, 2022, 07:44:46 am
content: Assign some values of those RC in the schematic to be clear.Never seen uF big caps for debouncing. Beware the same circuit can be used to generate a Reset signal, and that is where usually uF caps will be seen. For a reset circuit the RC constant time has to be much longer than in a button debounce, because it has to give time for the power supply to stabilize its voltage before the reset will be de-asserted by the reset circuit made out of the RC + trigger Schmitt.For a casual button debouncing (not the reset button) debouncing time constants are in the range of ms to tens of ms when done in software. The RC constant doesn't need to be that long. Usually caps in nF to tens of nf range are enough for hardware debouncing.Without values of the RC parts is hard to tell what would be best.

author: bodzio_stawski
author_rank: Regular Contributor
timestamp: August 14, 2022, 08:50:55 am
content: Ok, so on request, I provide examples of values, at the same time following the suggestion of jfiresto.By lowering the capacitance of the capacitor and increasing the resistor R2, the result would be T = 22 ms.So in this case it looks that we can simply save money thanks to the smaller ceramic capacitor.Quote from: RoGeorge on August 14, 2022, 07:44:46 amAs I took a closer look, the larger (uF) capacitors are rather used together with the 74LS14 instead of the 74HC14 - that's right.But I am still wondering, according to the topic, about the type of capacitor. I still can't understand why sometimes ceramic capacitors are used, and other times polarized capacitors are placed - as below:(from here):https://www.researchgate.net/figure/Switch-interface-Figure-4-Switch-interface-equipped-with-debouncing-circuity_fig2_344781796

author: Zero999
author_rank: Super Contributor
timestamp: August 14, 2022, 09:01:01 am
content: All the schematics shown in this thread have non-polarised capacitors. The symbol with the straight and curved line is depicts non-polarised. The reason for the curve is, some film capacitors have one plate more exposed to electrical noise than the other, so it's better to have that plate biased at a constant voltage, i.e. 0V at signal level and the curved line indicates this.The second schematic has an advantage over the first. Some switches have a minimum wetting current required for the contacts to make properly and a capacitor can provide a surge of current to meet this requirement.Here's a chart showing the different capacitor symbols.

author: wraper
author_rank: Unknown
timestamp: August 14, 2022, 09:24:27 am
content: Second circuit in the first post is not safe for a switch. When pressing the button you are shorting the capacitor resulting in a spark which damages switch contacts. Large capacitance is not useful, you are supposed to debounce for tens of milliseconds at most, not delay the switch for seconds. UI becomes totally abysmal when there is a half of a second delay. However it's much better to use R1 with more than an order of magnitude higher resistance than R2. The reason is obvious if you think a bit about how switches physically work. They heavily bounce on making connection but not on release which is almost instant. Therefore you want circuit to act fast when switch is pressed and act slow when it is released. In other words it's fine and even preferable do decide that switch is pressed while it's still bouncing. You don't need to make equal press and release doubouncing time. Not to say delay on release is way less noticeable than delay on press. The only problem when doing so in hardware like this is that you will need much larger capacitance to keep switch wetting current high enough (by not increasing resistance of R1 too much).BTW the worst type of software debounce is when code waits for a number of polls (say 10) to be in the same state before taking action and resets the counter even if a single poll is different. Results in laggy UI and missed presses, especially when switches become bouncy from age. It's actually very popular if not the most popular SW debounce algorithm which is beyond me, I guess people implementing that garbage don't see the problem at all.

author: Zero999
author_rank: Super Contributor
timestamp: August 14, 2022, 09:36:26 am
content: Quote from: wraper on August 14, 2022, 09:24:27 amThat depends on the switch and the size of the capacitor. If it's a small switch with gold plated contacts, then you're right. The capacitor discharging into the switch can damage it, especially if it's above a couple of nF or so. On the other hand, if the switch is designed to switch heavy currents, the capacitor is beneficial as it provides a surge of current to wet the contacts. Obviously don't use too large capacitor: 100nF is plenty.

author: wraper
author_rank: Unknown
timestamp: August 14, 2022, 09:45:32 am
content: Quote from: Zero999 on August 14, 2022, 09:36:26 amEven a small capacitance can cause a lot of current exceeding contact rating of a large switch for a very short period. So I would not call it beneficial, unless verified that there is enough impedance in the current path to limit it enough. Another problem is inductive kickback from traces/wires for a short moment while switch is bouncing after making a contact.

author: Zero999
author_rank: Super Contributor
timestamp: August 14, 2022, 09:56:14 am
content: Quote from: wraper on August 14, 2022, 09:45:32 amPower switches can switch a fairly large capacitance without any problems. If it was an issue then sensibly sized decoupling capacitors would be damaging power switches all the time. If you're paranoid, put a resistor (10R to 100R) in series with the capacitor. Another option is to use the second circuit with a decent size capacitor, say 100nF and a low value for R2.

author: Peabody
author_rank: Super Contributor
timestamp: August 14, 2022, 03:17:40 pm
content: What about adding a diode in parallel with the resistor? I guess you would still have the capacitor discharge problem, but it seems it would improve performance, and/or possibly allow the use of a smaller capacitor.

author: Peabody
author_rank: Super Contributor
timestamp: August 14, 2022, 03:25:51 pm
content: Quote from: wraper on August 14, 2022, 09:24:27 amWell, you don't wait 10 polls to take action. You take action immediately on the first detection of a press. But you don't look for another press until there have been 10 consecutive "released" polls. I don't find that method to be laggy at all, but if there's a better way to determine that bouncing has stopped, I'd like to know what it is.

author: wraper
author_rank: Unknown
timestamp: August 14, 2022, 03:37:18 pm
content: Quote from: Peabody on August 14, 2022, 03:25:51 pmWhat you mentioned is fine and I actually suggested using something similar to this in the past. However in various tutorials usually it's suggested to be done on both press and release which totally sucks. Although you may want to do a little of SW debounce on button press as well (not of this kind) to avoid false operation in presence of EMI if there is no HW filtering in the circuit at all.I personally prefer a counter to which you add/substract a value depending on input state and detect state change when it runs to zero or max value which is opposite to the previous one. For example max value is 20, min 0. When button is pressed - add 5, when released - substract 1 to get asymmetrical response. Or you can make it symmetrical too, still works pretty well for most applications as bounce on button press causes a bit of additional delay rather than completely resetting the counter.

author: wraper
author_rank: Unknown
timestamp: August 15, 2022, 12:55:56 pm
content: To get asymmetrical response but not increase capacitance too much, a diode can be added. Also I reduced resistance of R2 and increased capacitance because I personally would not be comfortable using resistance this high.

author: Zero999
author_rank: Super Contributor
timestamp: August 15, 2022, 01:29:13 pm
content: What's the rationale for the diode?When the switched is closed the time constant is C*100R and when C is opened, it's C(R1+R2). You could get rid of the diode and use 100R for R2 and 56k for R1 and get virtually the same result.

author: wraper
author_rank: Unknown
timestamp: August 15, 2022, 01:34:48 pm
content: Quote from: Zero999 on August 15, 2022, 01:29:13 pmI guess it's fine too. The idea was to not decrease wetting current, however as capacitor is discharged into a switch through low resistance, keeping low pull-up resistance should be pretty much rudimentary.EDIT: although there is a downside actually, and I'm uncomfortable with high resistance pull-ups. When repairing TVs, monitors and other stuff in the in the past I often replaced TACT switches which became leaky. IIRC usually they had resistance above a few tens of kOHm. In a variant with a diode and low resistance pull-up device will continue to function, with high pull-up resistance it will fail. With microswitches this is not really relevant though unless they were in really harmful environment. I actually posted pictures of such TACT switches under microscope on this forum years ago.

author: Zero999
author_rank: Super Contributor
timestamp: August 15, 2022, 06:45:47 pm
content: Quote from: wraper on August 15, 2022, 01:34:48 pmIt sounds like case of crappy switches and contamination. Decent switches with gold plated contacts with an appropriate IP ratings shouldn't have that issue.If leakage is a problem, use a lower value for R1. I don't see what difference the diode makes.

author: wraper
author_rank: Unknown
timestamp: August 15, 2022, 07:07:36 pm
content: Quote from: Zero999 on August 15, 2022, 06:45:47 pmThe difference is you can use smaller capacitor as said in the post with schematic (while keeping the same pull-up resistance). TACT switches generally have silver plated contacts which are flush with plastic. And silver is very prone to electromigration in presence of some moisture, therefore dendrites easily grow over the plastic. You could use switches with gold plated contacts instead but they are way less common and an order of magnitude more expensive.

author: Zero999
author_rank: Super Contributor
timestamp: August 15, 2022, 07:57:28 pm
content: Quote from: wraper on August 15, 2022, 07:07:36 pmDoes it matter? A larger capacitor is still cheaper and uses less space than an extra diode.QuoteThe last time I looked, switches with gold plated contacts weren't expensive. The amount of gold is tiny. I suppose it's the usual trade-off between cost and reliability.