Author Topic: 74HC14 for debouncing - question about the type of capacitor  (Read 1821 times)

0 Members and 1 Guest are viewing this topic.

Offline bodzio_stawskiTopic starter

  • Contributor
  • Posts: 48
  • Country: lt
74HC14 for debouncing - question about the type of capacitor
« on: August 14, 2022, 07:13:54 am »
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?
 

Offline retiredfeline

  • Frequent Contributor
  • **
  • Posts: 539
  • Country: au
Re: 74HC14 for debouncing - question about the type of capacitor
« Reply #1 on: August 14, 2022, 07:38:25 am »
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.
 

Offline jfiresto

  • Frequent Contributor
  • **
  • Posts: 809
  • Country: de
Re: 74HC14 for debouncing - question about the type of capacitor
« Reply #2 on: August 14, 2022, 07:44:37 am »
+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.
-John
 

Online RoGeorge

  • Super Contributor
  • ***
  • Posts: 6186
  • Country: ro
Re: 74HC14 for debouncing - question about the type of capacitor
« Reply #3 on: August 14, 2022, 07:44:46 am »
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.

Offline bodzio_stawskiTopic starter

  • Contributor
  • Posts: 48
  • Country: lt
Re: 74HC14 for debouncing - question about the type of capacitor
« Reply #4 on: August 14, 2022, 08:50:55 am »
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.

Never seen uF big caps for debouncing. 

As 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
« Last Edit: August 14, 2022, 08:53:44 am by bodzio_stawski »
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19494
  • Country: gb
  • 0999
Re: 74HC14 for debouncing - question about the type of capacitor
« Reply #5 on: August 14, 2022, 09:01:01 am »
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.
« Last Edit: August 14, 2022, 10:26:54 am by Zero999 »
 

Online wraper

  • Supporter
  • ****
  • Posts: 16849
  • Country: lv
Re: 74HC14 for debouncing - question about the type of capacitor
« Reply #6 on: August 14, 2022, 09:24:27 am »
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.
« Last Edit: August 14, 2022, 09:27:45 am by wraper »
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19494
  • Country: gb
  • 0999
Re: 74HC14 for debouncing - question about the type of capacitor
« Reply #7 on: August 14, 2022, 09:36:26 am »
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.
That 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.
 

Online wraper

  • Supporter
  • ****
  • Posts: 16849
  • Country: lv
Re: 74HC14 for debouncing - question about the type of capacitor
« Reply #8 on: August 14, 2022, 09:45:32 am »
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.
That 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.
Even 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.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19494
  • Country: gb
  • 0999
Re: 74HC14 for debouncing - question about the type of capacitor
« Reply #9 on: August 14, 2022, 09:56:14 am »
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.
That 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.
Even 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.
Power 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.
« Last Edit: August 14, 2022, 10:56:04 am by Zero999 »
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 1995
  • Country: us
Re: 74HC14 for debouncing - question about the type of capacitor
« Reply #10 on: August 14, 2022, 03:17:40 pm »
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.

 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 1995
  • Country: us
Re: 74HC14 for debouncing - question about the type of capacitor
« Reply #11 on: August 14, 2022, 03:25:51 pm »

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.

Well, 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.
 

Online wraper

  • Supporter
  • ****
  • Posts: 16849
  • Country: lv
Re: 74HC14 for debouncing - question about the type of capacitor
« Reply #12 on: August 14, 2022, 03:37:18 pm »

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.

Well, 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.
What 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.
« Last Edit: August 14, 2022, 04:13:24 pm by wraper »
 

Online wraper

  • Supporter
  • ****
  • Posts: 16849
  • Country: lv
Re: 74HC14 for debouncing - question about the type of capacitor
« Reply #13 on: August 15, 2022, 12:55:56 pm »
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.

 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19494
  • Country: gb
  • 0999
Re: 74HC14 for debouncing - question about the type of capacitor
« Reply #14 on: August 15, 2022, 01:29:13 pm »
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.
 

Online wraper

  • Supporter
  • ****
  • Posts: 16849
  • Country: lv
Re: 74HC14 for debouncing - question about the type of capacitor
« Reply #15 on: August 15, 2022, 01:34:48 pm »
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.

I 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.
« Last Edit: August 15, 2022, 01:45:54 pm by wraper »
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19494
  • Country: gb
  • 0999
Re: 74HC14 for debouncing - question about the type of capacitor
« Reply #16 on: August 15, 2022, 06:45:47 pm »
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.

I 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.
It 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.
 

Online wraper

  • Supporter
  • ****
  • Posts: 16849
  • Country: lv
Re: 74HC14 for debouncing - question about the type of capacitor
« Reply #17 on: August 15, 2022, 07:07:36 pm »
It 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.
The 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.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19494
  • Country: gb
  • 0999
Re: 74HC14 for debouncing - question about the type of capacitor
« Reply #18 on: August 15, 2022, 07:57:28 pm »
It 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.
The difference is you can use smaller capacitor as said in the post with schematic (while keeping the same pull-up resistance).
Does it matter? A larger capacitor is still cheaper and uses less space than an extra diode.

Quote
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.
The 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf