Tell me more ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

When the switch is closed I need the pin on the microcontroller to be high impedance, when the switch is open I need it connected to the ground. I need the leakage current to be minimal. What should I use? An inverter, an open drain transistor, or are there any other options, like an inverting relay package?

share|improve this question
Why not just use a different switch? Or invert the control signal (could affect the state on power-up)? – The Photon Apr 10 '12 at 15:38
Also, is the switch controlling the microcontroller (like you wrote), or is the microcontroller controlling the switch? – The Photon Apr 10 '12 at 15:39

2 Answers

up vote 5 down vote accepted

Fix the overall design so you don't have inconvenient issues like this at the lower levels.

The first obvious solution is to use a normally closed reed switch. Second, why is the polarity important when it's going into a micro that can interpret high or low any way it wants to? If you need to minimize power, have the micro sample the switch periodically, turning on the pullup or pulldown for a few 10s of µs only around the test. If this switch needs to be detected on a human time scale, then sampling every 50 ms will probably be good enough.

If you really really need to have a switch cause high impedance when closed and pull to ground when open, one FET and one resistor can do this:

This won't work well if there is any noise on the switch line, since the FET gate is at high impedance. You can use a lower resistor, but that increases current too. If you're going to reduce the resistor to have a few mA thru it when the switch is closed, you might as well substitute a NPN bipolar transistor for the N FET shown.

share|improve this answer
This is a low-cost, low-energy (coin cell) application, and NC reed switches are more expensive than NO. I am writing code on a very high level and don't want to change the hardware interface which was written by the manufacturer (this is a SoC), but I guess that's what I will have to do, I will try the sampling, that sounds good. Thank you for your answer. – mynameis Apr 10 '12 at 16:20
You probably need to run more current than that for long-term reliability. – markrages Apr 10 '12 at 17:34
Quoting an email from a reed switch manufacturer: "The low current that you switch probably causes these problems. Every time the switch opens, a small needle of ruthenium is formed in the space between the blades. If you switch higher currents and voltages , these needles are vaporized." – markrages Apr 10 '12 at 17:34
They recommend 1mA or more. This is fairly easy with a capacitor across the contacts, but this makes low-current polling more difficult. (The low->high transition time must be taken into account.) – markrages Apr 10 '12 at 17:36

Depending upon how quickly you need the switch to react to events, and depending upon what other circuitry you have in your design, I would suggest that you might want to consider using a port pin with a switchable pull-up resistor. Periodically wake up, enable the pull-up, and check the pin state. If high, and if if the processor can wake on a falling edge, leave the pull-up enabled. Otherwise disable it. An alternative approach in some cases if you have available a signal which is mostly low but occasionally pulses high is to connect both that signal and the switch to inputs of an "or" gate, and have the output of that gate connect back to the switch via high-value resistor. This will offer instant response to switch closures, and will respond to switch opening at a time dependent upon the pulse signal; the logic level on the switch pin will only change, though, when the switch opens or closes.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.