Digital Inputs - Best Practice?
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
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
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
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.
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.
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).