I have a digital signal from somewhere else and a microcontroller. The microctontroller can set it's output pins to be high, low, or high-Z. If the uC pin is high or low, I'd like the output to match it. If the uC pin is high-Z I would like the output to match the other signal, and ideally the uC can read it. But I'd also like to be able to turn the microcontroller off completely, and not have it damaged by an overvoltage on the pin. Expressed as a table:
| uC Power uC out Ext in | output |
+----------------------------+--------+
| H H - | H |
| H L - | L |
| H HighZ H | H |
| H HighZ L | L |
| L - H | H |
| L - L | L |
| - HighZ HighZ | L |
+----------------------------+--------+
The external input could come from a few different sources, most likely +-12V or 0-5V logic. I would like to be compatible as wide a range of bench test equipment and PLCs etc as possible without adding too many more components.
The output goes to a typical CMOS digital input. I may add a Schmitt trigger.
The microcontroller can source or sink about 10mA on that pin (limited by total through the port). The absolute maximum voltage rating on it is 0.3V below GND or 0.3V above Vcc.
Here is my solution so far:
simulate this circuit – Schematic created using CircuitLab
Will this work, and is there anything I might have forgotten to think about? Or a simpler all-in-one IC option I wasn't aware of?