Dual Polarity Transistor switch from single polarity source - Page 1
Forum section: electronics / beginners

author: Metalfan1185
author_rank: Contributor
timestamp: October 16, 2023, 01:45:07 pm
content: Hi All,I am having a huge mental block and I feel like someone can answer this pretty easily. I have a 24V relay to be switch on from a dual polarity supply of +12 and -12. I am trying to switch it on with a microcontroller that operates between +5V and GND. How do I do this in a way where the voltage extremes will not pull the MCU pin higher than 5V or lower than GND while still allowing the relay to switch on and off?I've been thinking of MOSFET circuits and transistor circuits, NPN, PNP...I know it could be done with a comparator but there's four of these and I want to try and keep the component count down if I can.Thoughts? Thanks!

author: Peabody
author_rank: Super Contributor
timestamp: October 16, 2023, 01:52:47 pm
content: How is the microcontroller GND referenced to the +/-12V supply?

author: wasedadoc
author_rank: Super Contributor
timestamp: October 16, 2023, 02:07:20 pm
content: Use an optocoupler.

author: Metalfan1185
author_rank: Contributor
timestamp: October 16, 2023, 02:09:14 pm
content: @peabody0VThe power supply transformer has a center tap connected to GND.

author: Ian.M
author_rank: Super Contributor
timestamp: October 16, 2023, 02:21:33 pm
content: ULN2003, with its Gnd pin at -12V and its COM pin returned to +12V to drive all four relays (assuming their coil current is <500mA). To level shift the logic signals down to the ULN2003 inputs, four PNP transistors in common base, base to 0V, with the logic signals applied via resistors to their emitters. If you use a quad PNP array (e.g. MMPQ3906), and a quad resistor array that could be only three components in total, but 'jellybean' discretes would have better availability.

author: Metalfan1185
author_rank: Contributor
timestamp: October 16, 2023, 02:27:45 pm
content: @wasedadoc Thats a good idea, I drew it out in the attachment.@Ian.M I'm pondering that IC you mentioned...

author: Peabody
author_rank: Super Contributor
timestamp: October 16, 2023, 02:49:46 pm
content: I think these circuits would work. I think they make dual N- and P-channel mosfets in one package.

author: David Hess
author_rank: Super Contributor
timestamp: October 16, 2023, 05:14:20 pm
content: Use the microcontroller to switch a simple PNP current source attached to +5 volts, which then drives the NPN which is referenced to -12 volts.The emitter of the PNP is connected to +5 volts through a current limiting resistor. The base is connected directly to the microcontroller output. When the microcontroller output is at 0 volts, then there is 4.3 volts across the resistor creating a current output at the collector of the PNP to drive the NPN. The microcontroller output is set high to disable the current.

author: BrianHG
author_rank: Super Contributor
timestamp: October 16, 2023, 06:32:05 pm
content: Place a PNP transistor, emitter on +5v, resistor from base to MCU IO pin, collector through resistor to base of your relay's NPN transistor. For additional safety from noise, place a resistor from base to -12v on your NPN relay transistor.When the MCU drives 5v to the PNP transistor's base, it is off, leaving the NPN's base at -12v and the relay will be off.When the MCU drives 0v to the PNP transistor's base, it's collector will be pulled up to +5v, turning on the base of the NPN transistor which will no longer be resting at -12v, hence turning on the relay.Other easier positive logic solutions exist if you want to use a PNP transistor to drive the relay and use a tiny NPN driven right from the MCU.

author: dietert1
author_rank: Super Contributor
timestamp: October 16, 2023, 07:45:16 pm
content: One could use a zener for level shifting, with two resistors to fit the logic levels for the npn transistor base. This requires the -12 V to be regulated. Or use a pnp transistor with base at ground for current transfer, again with two resistors. Different from Peabodies proposal the second resistor should not be in the base connection but in the emitter connection to limit current from the GPIO.Regards, Dieter

author: BrianHG
author_rank: Super Contributor
timestamp: October 17, 2023, 02:52:47 am
content: Quote from: Metalfan1185 on October 16, 2023, 02:27:45 pmWhat's that optocoupler for?Why not just wire in a transistor like this?

author: dietert1
author_rank: Super Contributor
timestamp: October 17, 2023, 07:33:49 am
content: This requires 3 resistors per channel. I would stick with the original proposal to use NPN relay drivers, as those are available as arrays with built-in suppressor diodes. e.g. ULN2003. They have built-in resistors and only need one 12 V zener per channel for level shift.Regards, Dieter

author: BrianHG
author_rank: Super Contributor
timestamp: October 17, 2023, 06:31:20 pm
content: Quote from: dietert1 on October 17, 2023, 07:33:49 amZeners have a wide range of leakage currents and have their own voltage drift with temperature. You will have to be careful in the voltage choice and curve, especially if the -12v drifts with temperature and load.I cannot argue with the ubiquity of the ULN2003, but I may think about adding an additional pulldown resistors on the inputs to ensure no leakage across the zener and make sure that the -12v supply is rigorously decoupled to the system GND.

author: dietert1
author_rank: Super Contributor
timestamp: October 18, 2023, 11:54:53 am
content: I think you are making up objections that appear meaningless once you check the numbers. This is a digital interface. Of course one selects small zeners for low leakage, e.g. BZX84C12S-7-F. One can make the four relay drivers with three parts.Regards, Dieter

author: Ian.M
author_rank: Super Contributor
timestamp: October 18, 2023, 12:13:43 pm
content: Quote from: dietert1 on October 18, 2023, 11:54:53 amSo you can with any of the PNP level shifter solutions, using quad PNP and resistor arrays without having to worry about an unfavourable stackup of Zener and supply rail voltage tolerances.

author: Metalfan1185
author_rank: Contributor
timestamp: October 18, 2023, 02:56:18 pm
content: Thanks for the input. Here's what I got:RL3 is 0V to 5V, everything else is +/- 12V dual polarity. I know it's a higher part count but those resistors can all be 0805's and I think the MOSFETs are SOT23's, so I can try to conserve real estate with the PCB layout.

author: Alex Nikitin
author_rank: Super Contributor
timestamp: October 18, 2023, 03:03:28 pm
content: Quote from: Metalfan1185 on October 18, 2023, 02:56:18 pmEven if youneeda permanently engaged relay, this looks like a somewhat extravagant way of doing it.CheersAlex

author: Ian.M
author_rank: Super Contributor
timestamp: October 18, 2023, 03:07:28 pm
content: +1That cant work as the IRLML9301 body diode will conduct all the time. If you are using a P-MOSFET, it needs to be high side.

author: Metalfan1185
author_rank: Contributor
timestamp: October 18, 2023, 03:31:36 pm
content: My P-ch MOSFET symbols were upside down haha oop.

author: Peabody
author_rank: Super Contributor
timestamp: October 18, 2023, 03:51:16 pm
content: It still doesn't work. When you turn on the N-channel, and ground the gate of the P-channel, the voltage at its source will not fall lower than ground plus the threshold voltage. So the voltage across the coil will be something less than 12V instead of 24V, and it may not even pull in. As Ian.M said, you need to put the coil below the P-channel. Then the coil sees 24V.

author: Metalfan1185
author_rank: Contributor
timestamp: October 18, 2023, 07:01:17 pm
content: Oh ok, So like this then

author: Ian.M
author_rank: Super Contributor
timestamp: October 18, 2023, 07:27:40 pm
content: Delete R5! Otherwise OK.However its still a ridiculous part count vs the ULN2003 with PNP level shifters.

author: Metalfan1185
author_rank: Contributor
timestamp: October 19, 2023, 12:18:57 am
content: Not sure exactly what is meant by the zener level shifters...

author: BrianHG
author_rank: Super Contributor
timestamp: October 19, 2023, 01:32:56 am
content: Place the ULN2003's E at the -12v.Place the ULN2003's COM at +12v.Wire each relay to each output of the ULN2003 an the +12v.You will have 3 spare outputs as the ULN2003 has 7 channels, IE it can drive 7 relays.(A) Now, for the zener dropper solution:Place a 13v, 350mw or less zener diode between you MCU IO pin and the input of the ULN2003.Place a 10k resistor at the input pin of the ULN2003 to -12v.Now, when your MCU IO is at 0v, that will be only 12v across the zener diode, so, the input of the ULN2003 will be at -12v as it has a 10k resistor to -12v. This means the relay will be off.Now when your MCU IO is at 5v, (-12v to 5v = 17v), that 17v going through the 13v zener will drop by 13v, meaning that on the other side by the ULN2003 input, it will see -8v instead of the off voltage of -12v. This will now turn on the relay as 4v above the -12v logic low reference of the ULN2003 will turn it on.(B) The PNP transistor option. (Use this solution if your -12v supply is not regulated)Tie a PNP transistor's emitter to +5v. Tie the Collector to the input of the ULN2003. Tie the base of the transistor to your MCU IO through a 10k series resistor. (You may use a PNP transistor array meaning like the ULN2003, 1 SO-16 IC package can give you 4-6 transistors)Now when your MCU IO is at 5v, the PNP will not conduct and allow the ULN2003's input to sit at -12v, meaning the relay is off.Change your MCU IO to 0v, this will turn on the PNP transistor and pull the input of the ULN2003 from -12v to +5v, meaning it will switch on the relay.(You may notice the logic here for the relay switch has become inverted...)These are your 2 solutions. The PNP transistor option (B) allows for a widely varying negative supply, like even -15v or -24v, while the zener dropper requires that your -12v supply stays within approximately -11v to -13v to function, otherwise at around -14v, all the relays will switch on.

author: BrianHG
author_rank: Super Contributor
timestamp: October 19, 2023, 01:37:58 am
content: Example zener diodes:Single ones: (Easy to find from multiple manufacturers)BZX84C13-TPArray, IE 2 in one package: (Packages are more specific to a very few manufacturers)BZX84C13S-7-FYou can also use a ULN2002 or ULN2004 for lower input current when using my option (B) with the PNP driver.Also, there exists the 'MMPQ3906' what has 4x 2N3906 PNP transistors in it if you don't mind the 2$ price.

author: EPAIII
author_rank: Super Contributor
timestamp: October 19, 2023, 02:48:41 am
content: Just get a 12 Volt relay. Use +5 and +12 with a common ground. All you need is a common emitter configured transistor if the logic device doesn't already have one. Or a common drain MOSFET. This is done all the time.

author: Ian.M
author_rank: Super Contributor
timestamp: October 19, 2023, 08:14:38 am
content: If you operate the PNP in common (grounded) base, as I described earlier, its emitter resistor (which goes to the digital output), in combination with the logic high voltage, sets the max. ULN200x input current, so you can use whichever ULN200x variant you can most easily/cheaply get and still keep the input current low without extra parts. 900uA input current will guarantee hard saturation at max. Ic for any ULN200x variant, and with 5V CMOS logic, that's easily achievable with a 4K7 emitter resistor. However the fly in the ointment is the load on the digital logic, which must provide the max. input current, so if driving it from bipolar TTL or a weak CMOS output one must calculate the emitter resistor from the loaded Voh voltage.N.B this arrangement is a non-inverting level shifter, i.e logic high == ULN200x input high == Load ON. If you require an inverting level shifter, wire the PNP as a switched current source, i.e. base direct to logic output, and emitter to +5V via the calculated resistor to set the max. current, giving logic low == ULN200x input high == Load ON, which also vastly reduces the load on the logic.

author: Metalfan1185
author_rank: Contributor
timestamp: October 19, 2023, 01:55:30 pm
content: @BrianHG I am having trouble putting your text to a layout in my head...You mean to put the zener diode in series with the MCU output pin? I haven't used zener's much, especially not as level shifters on an I/O pin.@Ian.M The I/O pin is 20mA Max, so not a lot of current is available.

author: dietert1
author_rank: Super Contributor
timestamp: October 19, 2023, 03:09:50 pm
content: The three variants discussed before are shown in the schematic. As i wrote before, the zener version requires the -12 V to be stable (+/- 0.5 V or so). The other versions don't require that, but have more parts. You can make this as a test circuit and see which version you prefer.Regards, Dieter

author: BrianHG
author_rank: Super Contributor
timestamp: October 19, 2023, 10:23:56 pm
content: Quote from: Metalfan1185 on October 19, 2023, 01:55:30 pmNo problem Metalfan1185. Take a look at my example schematic:You notice I wired a few zener diodes to and 0-5v MCU IO pin and 10k pull-down to -12v on the other side.At point #1, I wired the zener diode like one would assume you would use a normal diode. Wired like this, the zener actually operates like a normal silicon diode meaning if you measured the voltage at point #1, you will see the normal 0.7v drop of a silicon diode. This means when the MCU outputs 0v to 5v you will measure at point #1 from -0.7v to 4.3v since the output has been lightly pulled down to -12v while you expect to see the normal silicon diode 0.7v drop.But, zener diodes are supposed to be used backwards.At point #2, you see I have a 5v zener diode. This means that with the -12v pull down, when the MCU outputs 0v to 5v you will measure at point #2 from -5v to 0v. This is that '5v' drop which the zener allows before it begins to conduct like a normal diode in it's reverse bias.At point #3, you see I have a 10v zener diode. This means that with the -12v pull down, when the MCU outputs 0v to 5v you will measure at point #3 from -10v to -5v.At point #4, you see I have a 13v zener diode. This means that with the -12v pull down, when the MCU outputs 0v to 5v you will measure at point #4 from -12v to -8v. As you see, because the zener allows a 13v drop before it begins to conduct, when the MCU has a 0v output, point #4 reads -12v because the pulldown only goes to -12v. When the MCU outputs 5v, the pulldown through the 13v of the zener means 5v to 0v is the first 5v of the drop + 8v more equals the zener total voltage drop of 13v. This is how we arrived at -8v for when the MCU has 5v on the IO pin.At point #5, you see I placed a 17v zener. When the MCU outputs 0v, the zener wont begin to conduct and the -12v pulldown will mean you measure -12v at point #5. When the MCU output 5v, that's 5v more than before meaning with the -12v pulldown, a total of a 17v drop, the zener will still not turn on, or just begin to turn on. So, you will still measure -12v at point #5.This also means that the MCU IO will see almost no current at all, high or low.If your pulldown voltage was -24v instead of -12v, then at point #5, you would measure -17v when the MCU output 0v, and -12v when the MCU output +5v.As for the Zener milliwatts, that just define the maximum power the zener can handle.As for the pulldown, you may switch the 10k for 100k to make the current draw a little less for the MCU IO pin. But, it wont change much because of the zener voltage drop.Also remember that the ULN2003's input off voltage is -12v since it's E is tied to your -12v. It's turn on voltage is around 2v higher than the E pin which you have at -12v, IE -10v or higher voltage at the input pin.

author: dietert1
author_rank: Super Contributor
timestamp: October 20, 2023, 06:59:34 am
content: The 10 KOhm pulldown shown for didactical reasons is included in each ULN2003 input. So with the ULN2003 that part won't be needed.Regards, Dieter

author: Ian.M
author_rank: Super Contributor
timestamp: October 20, 2023, 09:56:50 am
content: Quote from: Metalfan1185 on October 19, 2023, 01:55:30 pmActually, that's quite a bit of current for a logic output, though I would expect the output voltage to droop significantly well below that limit. As my non-inverting proposal is to give the ULN200xA input 900uA, which is sourced from the logic via a 4K7 resistor, no problem. My inverting proposal requires the logic to sink at most tens of uA.The Zener options also rely on the logic to supply the full input current, which even working properly, depending n Zener and rail tolerances, may be higher than mine.

author: BrianHG
author_rank: Super Contributor
timestamp: October 20, 2023, 01:21:39 pm
content: In dietert1's example schematic with inverting input, replacing his 'T1' with a small P-Channel mosfet like a BSS84 and removing his R1 would operate the MCU IO with 0ma of current.Or, still use his PNP transistor but move R1 inbetween the base of the transistor and MCU IO, increasing it to 10k would leave your MCU IO with a maximum sink current of 0.5ma.Using the zener solution, you may see the MCU IO pin source ~1.5ma.

author: Alex Nikitin
author_rank: Super Contributor
timestamp: October 20, 2023, 01:36:29 pm
content: OK, that is the smallest number of components I can come up with.CheersAlex

author: Ian.M
author_rank: Super Contributor
timestamp: October 20, 2023, 02:01:55 pm
content: Smallest number of discretes, maybe, though an avalanche rated MOSFET could loose the free-wheeling diode, and a 'digital' transistor with integral base resistors could eliminate the pulldown. As mentioned earlier, all four channels could be done with only three components if you allow ULN2003, and quad PNP and resistor arrays.

author: Metalfan1185
author_rank: Contributor
timestamp: October 22, 2023, 06:39:09 pm
content: Quote from: BrianHG on October 19, 2023, 10:23:56 pmI think the negative voltages are throwing me off on understanding this as well as I should. I took a step back and revisited zener basics, which is how I understood it in the past. A Zener acts as a voltage regulator of a sort (or a voltage reference, see attached). If 12V goes in and it's a 5.1V zener, you get 5.1V out. Easy peasy.I never saw Zeners used with negative voltages before and now I think I have it somewhat figured out. It's almost like you simply just subtract the Zener voltage from the input voltage (so long as that number is within the range of the negative voltage. If it does not, then it can only be as low as the negative voltage limit). GND reference is easy, but when it shifts to a negative voltage, 0V into a 10V zener becomes -10V. 5V into that same 10V zener now becomes -5V (because the voltage difference between 5V and -5V is 10V). Which sounds ridiculously easy I know, but it's been years since I've studied Zeners haha. This is all very helpful and thank you all for taking the time to explain it. I want to draw out a schematic with the ULN2003 to keep for my notes (which I will also add your helpful explanation @BrianHG) and get back to you all with it just to be sure I understand it. Then I'll decide how I want to go about this from there, now that I have more options than I originally thought.Sidenote: I spoke to an engineer and he told me the opto-isolators are a good idea in the case of a MOSFET/Transistor failure, any shorts wont damage the MCU by pulling the I/O pins to any voltages above or below the recommended operating voltages of the pins. Though to be fair, my OP did say the least amount of components...

author: BrianHG
author_rank: Super Contributor
timestamp: October 22, 2023, 06:58:58 pm
content: Quote from: Metalfan1185 on October 22, 2023, 06:39:09 pmFor your designed circuit, if mosfet/transistor failure is a concern, the use an optocoupler.However, note that because of the series input resistor inside the ULN2003, even if it's primary output transistor blows, this means a 2.7k short to either rail. It it was a mosfet instead without where you had directly tied your IO to the gate, then you MCU IO would be nailed to the rail and fried. You would need a rather nasty high voltage surge, like 3-4x on your -12v rail to kill your MCU.

author: BrianHG
author_rank: Super Contributor
timestamp: October 22, 2023, 07:10:18 pm
content: This is what we are doing with the Zener.Rs is just the input load on the ULN2003.What you see is a negative regulator where if V+ would be tied to GND, 0v would be your un-regulated -15 to -50v.If you had a 12v zener, you would see -12v at vout. (THIS IS MEASURED BETWEEN THE Vs pin and the resistor connected to the Zener.)If your negative power supply was too weak, like -10v or -8v, then your Vout will be -10v or -8v since the zener diode will never turn on.So, if you have a -12v supply, with a 12v zener where the V+ in that schematic it tied to your MCU driving 0v, IE GND logic low lever, what will the Vout = ?Now, say you turn on your MCU IO and it becomes 5v. The point in the same regulator schematic, now instead of 0v, but 5v. What will the Vout = which used to be at -12v?

author: Metalfan1185
author_rank: Contributor
timestamp: October 23, 2023, 11:17:48 am
content: Quote from: BrianHG on October 22, 2023, 07:10:18 pm-If the input (+V) is 0V with a 12V Zener, I would think between the zener and resistor connection you'd see about 0V.Quote from: BrianHG on October 22, 2023, 07:10:18 pm-The difference between the input (now +5V) and the negative rail (-12V) would be 17V. The 12V Zener will subtract 12V, so I believe the output would shift up to +5V. Interesting.

author: Psi
author_rank: Super Contributor
timestamp: October 23, 2023, 12:02:20 pm
content: I wish opto-fets were more common than they are.

author: BrianHG
author_rank: Super Contributor
timestamp: October 23, 2023, 01:13:25 pm
content: Quote from: Metalfan1185 on October 23, 2023, 11:17:48 amYour getting it.If you placed your volt meter between the 0v line and the zener, basically across the resistor in the schematic, it would measure 5v if you had a -12v supply at that point. If you placed your volt meter across the zener, it would still read only 12v.Think of the 12v zener as a 12v battery so long as there is enough voltage to allow some current to be pulled through it, keeping it charged. Otherwise, it is such a busted dead battery that it appears as an open circuit.

author: David Hess
author_rank: Super Contributor
timestamp: October 24, 2023, 08:54:28 am
content: Quote from: Metalfan1185 on October 19, 2023, 12:18:57 amShown below is an analog example of a zener level shifter from a Tektronix high voltage power supply.Operational amplifier U4411A is a 358 type operating with a 22 volt supply, but controls a 55 volt output through a 43 volt zener diode. Bootstrapped resistor R4316 provides a constant current of 1 milliamp through 43 volt zener diode VR4304 which shifts the 15 volt output of U4411A from 15 volts to 57.3 volts as shown.The advantage of this configuration is that no voltage gain is added within the feedback loop, so unity gain stability is maintained without adjusting the frequency compensation. The disadvantage is that the control range of the output is limited to a range of about 42 to 60 volts, but this does not matter since the output operates at a fixed 55 volts, and the current limiting is external through Q4303.