Shop OBEX P1 Docs P2 Docs Learn Events
Digital Inputs - Best Practice? — Parallax Forums

Digital Inputs - Best Practice?

JoeLuciaJoeLucia Posts: 3
edited 2011-02-23 12:48 in Propeller 1
I am wondering about the best way to configure hardware for Digital Inputs.

If I have 24 inputs being used to monitor 24 normally-closed switches.

Option A: Inputs are pulled-Down with a 10k resistor and 3.3v run through the switch directly to the input pin when closed. (as described in the "Propeller Protoboard Designs for the Beginner" document)

Option B: Inputs are pulled-Up with a 10k resistor and the pin shorted directly to Ground through the switch when closed.

Which of these options (or otherwise) would be best from an engineering (and current consumption) point-of-view for the Propeller (while ALL switches are in the Closed position)?

Also, please consider that the "normally closed switch" could be at the other end of a 50-foot pair of wire. And, would one option be better for long external switch runs as opposed to On-Board switches.

(basically talking about connect window and door sensors for hard-wired alarm system directly to the propeller pins for simple open/close detection with minimal hardware)

Feel free to elaborate on the problems that could surface from a 50' run and zapping the propeller somehow. I am putting a TVS (Transient Voltage Suppressor) on each input.

Thanks,
Joe

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-02-23 11:20
    It's usually better to have a 10K pullup close to the Propeller where there's 3.3V (Vdd) readily available and run the signal line and ground out to the switch. A TVS probably won't help much since they're slow to switch on. You could use a large (10K) series resistor between the signal line and the Propeller pin. As long as you're using switch contacts with low resistance rather than switching transistor outputs, you should be fine. You could even increase the resistor values with little effect. Make sure to allow enough debounce time (maybe 10ms) in your code.
  • JoeLuciaJoeLucia Posts: 3
    edited 2011-02-23 12:15
    Mike Green wrote: »
    ...You could use a large (10K) series resistor between the signal line and the Propeller pin. ....

    Just want to clarify... Use a 10k pullup AND use a 10k in series to ground to help diminish transient voltage (for when the switch is Open). So the PIN will normally have a 10k to 3.3v and a 10k to Ground at the same time (with switch closed). Since this is a voltage divider, the PIN will be sitting at 1.65v with the switch closed, and since Logic High is 0.6Vdd (1.9v) then the Prop will detect the Ground over the 3.3v while closed.

    Im a thinking Correctly?

    GND -> <N/C Switch> -> 10k -> PIN -> 10k -> 3.3v

    Thanks again,
    Joe
  • Mike GreenMike Green Posts: 23,101
    edited 2011-02-23 12:31
    Not 10K to ground. There's a 10K to Vdd and a 2nd 10K from the junction of the switch and the 10K pullup to the I/O pin.
    Gnd -> N/C switch ----> 10K -> Vdd
                        |
                        V
                       10K
                        |
                        V
                      I/O Pin
    
    In terms of wiring, you'd want to use a twisted pair or a shielded single conductor between the switch and the controller. That would reduce the effect of any electrical noise running along the same path. As I mentioned, you could increase either or both resistor values. Increasing the pullup value would reduce the current drain when the switch is closed. You need some current to keep the switch contacts clean. Increasing the series resistor increases its protection for the I/O pin, but increases the sensitivity of the circuit to electrostatic noise and slows down the signal transitions. That's why you need more time to make sure the switch has really opened.
  • tonyp12tonyp12 Posts: 1,951
    edited 2011-02-23 12:48
    Most of the time I would say switches are normally open.



    Normally Closed Switch
    A "normally closed" switch takes two wires and connects them together ("closed") most of the time, which completes the electrical circuit.
    When you activate the switch, it disconnects the wires, leaving them dangling in space ("open").

    For positive logic, hook one end of the switch to the input, the other end of the switch to ground, and use a pull-up resistor.
    A normally closed switch, wired for positive logic.

    When the switch is quiet, the switch gives the input a nice clean low.
    When the switch is pressed, the switch lets the pullup make the input high.
    cioinp_NormallyClosedSwitch.bmp

    Use a higher value pull-up try up to 470k,
    as you can see if the normally closed switch is mostly left
    closed all the time the power will go from +5 to gnd all the time, contiues drain.
    A mcu input have 2-5mega ohms and creates very little drain.

    I always think of the wires being water pipes when it comes to pull-up/pull-down.
    If you have a small trickle of water in the pipe will fill up eventually, but if you open up a drain the pipe will empty out fast
    and drain faster than the water coming in from a restricted pipe (one with a resistor).
Sign In or Register to comment.