I want to use a micro-controller to send data through a max232 that will convert the 0v/5v signals into -12/+12v signals. The problem with this IC is that when there's no signal, it sends a +12v signal which I don't want. I want to be able to control exactly when to send a signal. So I would like to use a transistor (or something else) to make an electronic switch and connect an additional pin of my micro-controller to open and close the switch when I need to. I've made a diagram so it makes more sense. This diagram is an idea I've had, but I don't know how to make it work, I read the data-sheet of the 2n2222 transistor and seems like negative current won't go through.
Here's the Schema simplified : Basically, it sends the data to the receiver when and only when the Switch is turned on, the rest of the time, the switch is off and no data transit. I'm just looking for an electronic equivalent of that switch that I could control with a microcontroller.
Answer
Here is how I would do (well, I don't like relays, but it's a personal preference...).
The upper signal is the +12/-12 coming from MAX232. The lower signal is a +3.3/0V signal coming directly from the MCU to enable the "switch".
When the enable signal is high (3.3V), it drives the P channel FET gate low. Then, if the MAX232 signal is high, it will pass (because the mosfet gate sees a positive voltage). If the MAX 232 signal is low (-12V), the gate is not triggered, but the signal will still pass, because of the body diode (there will be a slight voltage drop, but not of big consequences at these levels).
When the enable signal is low and the MAX232 signal is high, the output is driven high impedance.
There is one big constraint: The MAX232 signal must always be high (+12V) when you disable the switch. Otherwise, if it is negative (-12V), the body diode will make the signal pass anyway. But this can easily be made sure in the firmware.
Note: Circuit has been updated In the previous circuit, I was using BJT NPN at the bottom. I realized that the negative voltage could have been destructive to the transistor, so an additional diode would have been necessary to protect it. So, actually, I changed it to a NFET, because then, there is no need for such a diode, and the base resistor can also be avoided. So it's only three components, now. And you can even get Nfet and Pfet in a single package, so that would be two components.
No comments:
Post a Comment