trying to debounce

I note that those spikes are the same voltage as the signal after stable contact is made, no higher.

You are right. These are normal logic signals when switch makes to-and-from movements. These are not those 'High Voltage Peaks' that damage the devices! In digital environment, the chances for the occurrences of these spikes are very remote; but, the possibility can't be denied. This is the reason for which the the Arduino has installed diode (D2) at the RST/-pin of the ATmega328 as a measure of protection against a spike. If a spike occurs, the diode will conduct; the low energy spike will be immediately squeezed to 5.7V.

What we get is sparks jumping between contacts when the get close enough or on opening, until they get far enough to quit crossing the tiny gap that 5V and 3V will cross.

This is the exact point - the electrical sparks! Why do they happen? They happen when a switch suddenly breaks a current flow, and the surrounding dielectric breaks. To break a dielectric, there is a need of High Voltage of sufficient magnitude in the form of high amplitude like a delta function or wider duration. This is the interpretation of electrical engineering. This is the reason for the Electrical Circuit Breakers to have built-in 'spark extinguishers' to absorb the sparks; sparks do not spread around and the nearby electronic trip circuits are not affected.

There have been reports in this Forum that the nearby MCUs were being resetted when the relays were operating. This happened, probably, due to the sparks of the relay contacts.

They happen when the gap between conductors is small enough for the voltage to spark across the gap.

Air breaks down at about 30 kV/cm, depending on humidity, temperature, etc.

You can calculate the voltage needed for electricity to jump across a spark gap with a simple formula: voltage equals the air gap length in centimeters times 30,000.

At some small fraction of a millimeter, 5V will jump across the open gap.

GolamMostafa:
There have been reports in this Forum that the nearby MCUs were being resetted when the relays were operating. This happened, probably, due to the sparks of the relay contacts.

Mostly it happens because the relay pulled enough current to lower the voltage going to the board when the power wiring let that happen.

I think I was creating a problem that didn't really exist.

Once your code gets fast enough to catch bouncing it becomes a problem. But that problem is less than slow jerky code!

You can debounce in hardware simply by wiring a 0.1uF capacitor across the button. It will eat the spikes, there will be no bounce.

You can debounce a switch by reading it slowly, every 50ms.

.

You can debounce in hardware simply by wiring a 0.1uF capacitor across the button. It will eat the spikes, there will be no bounce.

Practically, it does not always help; if so, Maxim Integrated wouldn't spend so much efforts to develop dedicated debouncing circuitry! Software based debouncing logic also does not work well!

They happen when the gap between conductors is small enough for the voltage to spark across the gap.

Let me tell you a little bit of 'High Voltage Break Down' theory that I received from GEC Rugby, UK in 1979.

A certain amount of current (almost fixed for that session) is passing through a contact. The contact is suddenly broken. The current that was flowing before the break now tends to flow (constant current source) through this very high impedance air-gap. As a result there develops a very high voltage (constant current * very high impedance) across the air-gap. The result is the break down of the air-gap with spark. That's why in the Switch Gear, when the relay is taken out for maintenance, the CT-terminals at the Switch Gear side are automatically shorted to create a no impedance path. Fortunately, in digital electronics, it does not happen much (very very rare!); but, in electrical engineering it is a common phenomenon due high current in the range of 5A - 1000A and even more!! However, electronics engineers do not take risks, they always implement debouncing circuitry where needed.

"Software based debounching logic also does not work well!"
If we are talking about Arduino applications for this crowd, this statement is just nonsense.

.

If we are talking about Arduino applications for this crowd, this statement is just nonsense.

I have not referred it to the current discussion of the current thread. To avoid misunderstanding, I am striking it off from my post.

Why not just delete the whole thing?

I did misremember the cap value, Nick used 1 uF cap and shows the result on his scope.
Look under hardware debounce,

BTW, "I can't think of why" is specious reasoning at best for why something isn't done. That's arguing from ignorance.

A bit of software that saves even a single cap each on millions of devices, reducing size as well as cost does make sense.

I debounce in software because it's so damned easy and only uses 4 bytes of RAM per switch... with my library.

GolamMostafa:
[...] A certain amount of current (almost fixed for that session) is passing through a contact. The contact is suddenly broken. The current that was flowing before the break now tends to flow (constant current source) through this very high impedance air-gap. As a result there develops a very high voltage (constant current * very high impedance) across the air-gap. [...]

The constant current scenario is when you are switching inductive loads. This does not apply to resistively loaded switch contacts such as those used in low voltage digital circuits. All you will see as the contacts separate, is a varying voltage due to the varying resistance.

Why not just delete the whole thing?

I am leaving it to the Moderator.

[This is a Forum; not a Magistrate Court where things are judged by the Rules of Books and the Rational Arguments of the Lawyers.]

This is a technical forum where a suggestion to get rid of garbage is only a suggestion.

Please leave it up where any beginner can find it and get the other side of the dazzle with brilliance coin.

This is a technical forum [...]

It is more than a technical forum; I have seen people here writing poetry to create humor. So, putting garbage in the name of 'I Know' is the other side of the coin!

larryd:
"Software based debounching logic also does not work well!"
If we are talking about Arduino applications for this crowd, this statement is just nonsense.

.

Somebody websurfed a paper and misrepresented it badly.

from the paper:
If asked, most engineers would say that switches are debounced in software and that debouncing
presents "no problem." Both assumptions are true if you pay proper attention to the details. Software
debouncing takes care of the bounce, but it does not address the problems of overvoltage, ESD, or
other transients.

And then the circuit to debounce and handle overvoltage, ESD and other transients becomes "proof" that a capacitor across a switch will not debounce the switch.

The paper itself is interesting and covers conditions that some projects may reach. If I want to code on the Moon I need a space suit, that does not mean I need a space suit to write code!

It is more than a technical forum; I have seen people here writing poetry to create humor. So, putting garbage in the name of 'I Know' is the other side of the coin!

Are you blowing on about the Bar Sport page? REALLY?

Bar Sport

Jokes, mobs, and all sorts of unrelated topics, shout out loud your love, and curse for that burnt battery-pack

This is a TECH FORUM. We have a place to be non-tech does not make the whole forum fair game for BS.

Are you trying out for a job on FOX? You're not ready to work for Trump yet but maybe some day you will.

@aarg

The constant current scenario is when you are switching inductive loads. This does not apply to resistively loaded switch contacts such as those used in low voltage digital circuits. All you will see as the contacts separate, is a varying voltage due to the varying resistance.

Having had a close study of your post and the subsequent discussion with a power system expert/professor, I duly acknowledge that it was an inappropriate move for my part to use the terms 'constant current' in a resistive circuit where the break-before-current quickly decays through the tiny air-gap and the sparks (very negligible in low voltage DC; but, it is tremendous in HVDC) at the moment the switch gets opened. The constant current scenario is effectively present in the case of inductive loads and open-circuited CTs.

Thank you for tracking the thread and giving me the opportunity to convert my ignorance into knowledge.

And low voltage sparks jump just before contacts close giving a source of bounces for about 2ms.
See Nick's tutorial with the scope picture.
The sparks get longer on broken contact but there's fewer of them and they handle just the same.

The Forum is a source of ample information, and it is fine as long as it remains objective. All the problems appear when we make it very subjective. In this Forum, there are about 70000 members among which Nick is the most frequently cited personality; still, there are some who criticise a few of his renderings (not him); this is natural! We live a practical society with practical people where everybody tries to maintain his own personality and thus the conflict arises. We compromise this way or other way as because we have to live together!

How about at least linking to "some who criticise a few of his renderings" to give some context to otherwise empty blah-blah attempting to make yet another non-point. THEN there might have been some substance unless the criticism is also empty.

"We live a practical society with practical people where everybody tries to maintain his own personality and thus the conflict arises. "

Coming from you, this explains sooooo much. If you spent more time on reality you wouldn't need to shovel so much "maintenance" disinformation.

Are you by any chance a post-modernist?

D2 (D3 on my schematic of the Uno), is not there to suppress spikes. The reset line has an on-chip spike filter, check the data sheet. Notwithstanding that, all the digital inputs on the AVR have clamping diodes. I don't know if there is any documentation about the designers intention, but usually such diodes in the reset circuit ensure that the reset capacitor (in this case C5) immediately discharges to a logic low state after power is removed.

There is a minimum pulse length specification for the AVR reset circuit that prevents it from resetting multiple times in the hypothetical case that it was only connected to a bouncy switch. But in this case, and as is usually the case, the relatively huge reset capacitor would remove any switching spikes.