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?
|
|
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. |
|||||||||
|
|
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. |
|||
|
|
