Push button detection through a very long wire

Discussion in 'General Electronics Chat' started by cmartinez, Sep 28, 2015.

  1. cmartinez

    Thread Starter AAC Fanatic!

    Jan 17, 2007
    3,574
    2,549
    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?
     
  2. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,692
    2,762
  3. cmartinez

    Thread Starter AAC Fanatic!

    Jan 17, 2007
    3,574
    2,549
  4. cmartinez

    Thread Starter AAC Fanatic!

    Jan 17, 2007
    3,574
    2,549
    Never mind, Joey. I've already read the whole thread and now I understand your opinion on this issue.... thanks again!
     
  5. RichardO

    Well-Known Member

    May 4, 2013
    1,238
    385
    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.
     
    cmartinez likes this.
  6. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,692
    2,762
    Do it in software. Caps fail. Code never does. And code is free.
     
    Last edited: Sep 28, 2015
    InspectorGadget and cmartinez like this.
  7. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,692
    2,762
    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.
     
  8. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,692
    2,762
    Oh, and you won't need the shielded wire. Twisted pair will be fine.
     
    InspectorGadget likes this.
  9. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,692
    2,762
    cmartinez likes this.
  10. RichardO

    Well-Known Member

    May 4, 2013
    1,238
    385
    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!
     
  11. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,692
    2,762
    Ok. Well, regardless of what you said or didn't say, it's no matter in this case -- especially if he uses software debouncing.
     
  12. RichardO

    Well-Known Member

    May 4, 2013
    1,238
    385
    Um. You can't debounce a damaged switch. :(
     
  13. cmartinez

    Thread Starter AAC Fanatic!

    Jan 17, 2007
    3,574
    2,549
    My first guess about that diode, for once, was right.

    So tell me, other than:
    and
    what's not to like about this setup?

    attachment.png
     
    Veracohr likes this.
  14. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,692
    2,762
    Please don't.
     
    cmartinez likes this.
  15. cmartinez

    Thread Starter AAC Fanatic!

    Jan 17, 2007
    3,574
    2,549
    Thanks.... I'm still laughing here while trying to understand the ignoble mess I did with your circuit... I meant no disrespect
     
  16. cmartinez

    Thread Starter AAC Fanatic!

    Jan 17, 2007
    3,574
    2,549
    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.
     
    Last edited: Sep 30, 2015
  17. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,692
    2,762
    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.
     
    cmartinez likes this.
  18. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,692
    2,762
    Oh, and a 200uS rise time will not be all that effective for many switches, which may bounce out to 5 - 15 ms.
     
  19. strantor

    AAC Fanatic!

    Oct 3, 2010
    4,302
    1,988
    Why not make it an active high and switch pulls it low?
     
  20. InspectorGadget

    Active Member

    Nov 5, 2010
    211
    42
    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.
     
Loading...