Push button detection through a very long wire

Thread Starter

cmartinez

Joined Jan 17, 2007
8,257
I've been designing special controllers for a few years now, and the one thing that gives me a headache every now and then is when I need to read a push-button connected to the circuit through a very long wire... say, 20 meters long.

Since 5V was being such an annoyance due to spurious detection, I decided to switch to a 12V signal that would arrive at the MCU's input through a shielded cable (whose shield is grounded at one side only, to prevent a ground loop), and into a voltage divider formed by R1 and R2, as shown in the following figure.

PB01.JPG

C1 is there to help de-bounce the switch and to further minimize false detections.
This modification improved things significantly.


The circuit, however, still gets false readings every once in a long while, and I'm beginning to feel that the wire arriving into R1 from the push-button is acting as an antenna of sorts... so I figure that adding a weak pull-down (that is, R3 in the following figure) should improve things further.

PB02.JPG

Am I right in this last assumption? O is there a better way to accomplish what I'm trying to do?
 

Thread Starter

cmartinez

Joined Jan 17, 2007
8,257
Excellent tip, Joey, thanks!
Question: you said The circuit *will not* alleviate the need for software debouncing, if you haven't done it.
Can the circuit be debounced using a simple cap? Or will I be forced to do it through software?
Never mind, Joey. I've already read the whole thread and now I understand your opinion on this issue.... thanks again!
 

RichardO

Joined May 4, 2013
2,270
You may want to add some resistance at the switch end. I have been told that discharging the capacitance of a long cable can burn the contacts on the switch.
 

joeyd999

Joined Jun 6, 2011
5,286
You may want to add some resistance at the switch end. I have been told that discharging the capacitance of a long cable can burn the contacts on the switch.
So, you are suggesting that a cap on a long wire somehow has higher instantaneous discharge current than a cap on a short wire?????? I'd like to see your mathematical proof.
 

RichardO

Joined May 4, 2013
2,270
So, you are suggesting that a cap on a long wire somehow has higher instantaneous discharge current than a cap on a short wire?????? I'd like to see your mathematical proof.
I did not say that... I said that the capacitance of the wire can damage a switch. A cap can also burn switch contacts. A resistor in series with the switch, at the switch, can protect against both. To add some confusion, switch contacts need both a minimum current and voltage to last their longest. Sometimes, a cap across a switch can actually make it last longer!
 

joeyd999

Joined Jun 6, 2011
5,286
I did not say that... I said that the capacitance of the wire can damage a switch. A cap can also burn switch contacts. A resistor in series with the switch, at the switch, can protect against both. To add some confusion, switch contacts need both a minimum current and voltage to last their longest. Sometimes, a cap across a switch can actually make it last longer!
Ok. Well, regardless of what you said or didn't say, it's no matter in this case -- especially if he uses software debouncing.
 

Thread Starter

cmartinez

Joined Jan 17, 2007
8,257
The diode will shunt negative excursions to ground that may be induced inductively, protecting the base from exceeding its Vbe reverse breakdown voltage.
My first guess about that diode, for once, was right.

So tell me, other than:
I don't like putting caps on inputs -- I prefer sharp edges.
and
Caps fail. Code never does. And code is free.
what's not to like about this setup?

attachment.png
 

Thread Starter

cmartinez

Joined Jan 17, 2007
8,257
Alright...

I've simmed the thing in LTspice and here's the result. It seems obvious now that the 0.47uF value that I first posted was waaaaayyy too high for debouncing purposes. But placing a 1 nF cap seems to do the trick and protect against microsecond-level glitches by generating a nice smooth edge at the beginning of the switching cycle...

You'd be doing me a huge service by telling me what it is exactly that you don't like about this setup.
 

Attachments

Last edited:

joeyd999

Joined Jun 6, 2011
5,286
You'd be doing me a huge service by telling me what it is exactly that you don't like about this setup.
1. I don't like unnecessary components -- especially when failure of one of those unnecessary components will cause malfunction.
2. I don't like soft edges -- at least confirm the digital input is schmitt trigger -- otherwise, it may "bounce" regardless.
3. I don't like asymmetrical edges.
4. At least put the cap to ground. The cap to Vdd will inject AC transients (on the Vdd bus) into the input during the switch 'on' period.

What, exactly, is wrong with code? In all seriousness, that is the right way.
 
Alright...

I've simmed the thing in LTspice and here's the result. It seems obvious now that the 0.47uF value that I first posted was waaaaayyy to high for debouncing purposes. But placing a 1 nF cap seems to do the trick and protect against microsecond-level glitches by generating a nice smooth edge at the beginning of the switching cycle...

You'd be doing me a huge service by telling me what it is exactly that you don't like about this setup.
1. DO NOT use a transistor. You're just amplifying noise. There is no need for it, no use for it; it's nothing but trouble. You have a very strong signal already; you don't need any amplification.

2. DO NOT use 12V in the switch line. You have plenty of signal with a 5V source. Oh, and it's more conventional to pull up the signal at the MCU input and have the switch pull it down to ground.

3. The idea of capacitance in the wire burning the switch contacts is pure fantasy. UTP network cable has a capacitance of about 15pf/ft, which is about 50pf/m, so you're talking about 1nF of capacitance in 20m. This will not store enough energy to arc switch contacts.

4. It sounds like your only problem, like joeyd999 says, is that you don't debounce your switch. Putting a capacitor across it is not debouncing. There are good posts on this site about software debouncing. Essentially, you make a resettable timer to detect the contact closure: You time about 20 ms on switch closure but reset it on any glitch open. At the end of 20ms with no open glitches the switch is considered activated. You do the same thing on release if you're detecting release. Put a scope on the input to the MCU and see what kind of glitches you have over what time period. You may have to adjust the total timer duration to suit.

Do the real debounce and you'll see your issues will be over.
 
Top