Switchable 5V/12V supply

Thread Starter

jwfx

Joined Jan 15, 2025
13
I have two regulated supplies, 5V and 12V. I need to switch an output between OFF, 5V, and 12V using a microcontroller. The output must be able to source up to 1A.

It should not be possible to short 5V and 12V together due to a software glitch.

Here's my "unsafe" design (possible to short the 2 together by bringing both 12V_EN and 5V_EN high):

1745960212323.png

It uses back-to-back MOSFETs for 5V to avoid current flowing from 12V to 5V through the body diode whilst 5V_EN is low.

Here's a simulation of it: https://www.falstad.com/circuit/cir...dNRseEo7JA4R7eh-Jz3MorKhlOKk-aUvCEg4-VSUtHqIA

How can I improve this to make it "safe"?
 

crutschow

Joined Mar 14, 2008
38,319
You need a resistor from the gate of Q2 to +12V to turn it off when Q1 is off, as you have in your sim.
How can I improve this to make it "safe"?
You can add an NPN transistor from either Q1's base or Q5's base to ground, which is connected to, and turned on by the opposite input.
That will inhibit the input and prevent both from turning on at the same time.

Whichever one you choose to add the transistor to, will determine what the output voltage will be if both inputs go high.

1kΩ resistors are rather low for the base resistors.
Is there a reason you selected that low value?
 

WBahn

Joined Mar 31, 2012
32,703
I have two regulated supplies, 5V and 12V. I need to switch an output between OFF, 5V, and 12V using a microcontroller. The output must be able to source up to 1A.

It should not be possible to short 5V and 12V together due to a software glitch.

Here's my "unsafe" design (possible to short the 2 together by bringing both 12V_EN and 5V_EN high):

View attachment 348091

It uses back-to-back MOSFETs for 5V to avoid current flowing from 12V to 5V through the body diode whilst 5V_EN is low.

Here's a simulation of it: https://www.falstad.com/circuit/cir...dNRseEo7JA4R7eh-Jz3MorKhlOKk-aUvCEg4-VSUtHqIA

How can I improve this to make it "safe"?
When designing fail-safe systems, you need to take a step back and decide what you want to have happen (or are willing to accept having happen) under the various fault scenarios.

You are already assuming the possibility for software glitches attempting to power up both supplies at the same time.

So... what should happen if this software glitch tries to do that?

Is it truly sufficient that the two supplies not be shorted together, but any other outcome is tolerable?

That means that if you wanted the output to be OFF, or 5 V, that it would be tolerable for the output to actually be 12 V? Is this acceptable, or could this cause damage?

Only you can answer this question, because the answer depends on the application. It might be that you should have it so that if the MCU tries to turn on both supplies at the same time, that neither is turned on.

Are you stuck with the MCU providing one signal that means turn on the 12 V and another signal that means turn on the 5 V, or do you have the option of defining your signal definitions? If so, I would recommend having one signal that means 12 V or 5 V and the other that means Enable the Output.
 

MisterBill2

Joined Jan 23, 2018
27,181
Understand that the five volt supply will never force current into the 12 volt supply. And to keep the 12 volts out ofthe5 volt supply a simple diode will be enough, although there will be a voltage drop when current flows from the 5 volt supply to the load.

NOW, how about telling us about the application of such a scheme. I have seen that there are some seriously brilliant folks who show up in these forums and have some really great solutions to challenges. So if you present the whole problem they may deliver a whole solution.
 

crutschow

Joined Mar 14, 2008
38,319
In my deleted post I stated that my sim showed that the connection with the Schottky diode as shown in Post#3 didn't completely inhibit the transistor, but there was an error in my sim connections.
Fixing that error then did show that the circuit worked as shown.
 

MisterBill2

Joined Jan 23, 2018
27,181
Oh Well! In a free country I can let folks disagree, although it is better if they are more specific about just what it is that they do not agree with.
And I suppose it is even legal for somebody to be just plain disagreeable. But probably I will tend to avoid them. There are people and companies that I will not do business with.
 

Thread Starter

jwfx

Joined Jan 15, 2025
13
You need a resistor from the gate of Q2 to +12V to turn it off when Q1 is off, as you have in your sim.
Oops, good catch!

1kΩ resistors are rather low for the base resistors.
Is there a reason you selected that low value?
Is that value not in the right range?

Here's my current understanding and calculation for selecting the base resistor (please correct me if anything is off):

For Q2: with a 200 ohm gate resistor (R3), the gate charging current is limited to 60 mA. The A03401A has a total gate charge of 14 nC, so using Q = It, the charge time is about 233 ns. I don’t have a specific turn-on time requirement, so this seems reasonable.

The MMB2222A (Q1) has a minimum current gain of 35, so the base current needs to be at least 60 mA / 35. I've read that to achieve saturation, you usually assume a lower gain (typically 10–20) - using a gain of 20 gives a required base current of 3 mA.

To achieve 3 mA at the base, I need 3.5 mA total (accounting for R2), giving R = V/I = 5 V - 0.7V / 3.5 mA = 1228Ω. 1k gives 4.3mA which should be fine.

200 ohm isn't really a requirement either for what it's worth, just a value I found commonly used.

A diode from the collector of Q1 to the base of Q5 will inhibit the 5 volt supply.
This seems like a nice solution and works well with WBahn's suggestion - thanks!

How frequently/rapidly will the 5V/12V be switched?
It's most likely set once at power up and then basically never changed.

Are you stuck with the MCU providing one signal that means turn on the 12 V and another signal that means turn on the 5 V, or do you have the option of defining your signal definitions? If so, I would recommend having one signal that means 12 V or 5 V and the other that means Enable the Output.
Nope not stuck with any specific setup for the IO. I like the sound of a 5V/12V pin and an enable pin.

NOW, how about telling us about the application of such a scheme. I have seen that there are some seriously brilliant folks who show up in these forums and have some really great solutions to challenges. So if you present the whole problem they may deliver a whole solution.
It's for powering an external device. I am trying to support multiple models which may be 5V or 12V, configurable in software. It could just be a hardware switch in reality, but allowing software control allows selection from a list of supported devices (and the device model is used to configure some other parameters).

If switching does not happen often, l would use a relay. Simple and failsafe.
I'm quite space constrained - I guess I could use a reed relay but I'm interested in seeing what options there are using just transistors.

Here's my latest design incorporating sghioto and WBahn's suggestions:
1746008092727.png

And the corresponding simulation: https://www.falstad.com/circuit/cir...nK0IsCTXVZxUlKYxP41UIvENZNm2ABRV9WIAIUYuLWCAA

Is there any way to simplify the design? I tried to find a way to omit Q5 but couldn't quite work it out.
 

MisterBill2

Joined Jan 23, 2018
27,181
Unless the application requires an "OFF" mode, why not replace the three devices used to switch the 5 volts supply with a single adequately rated diode???The five volt supply will not force current into the 12 volt supply, and when the 12 volt supply is on that series diode will be biased to no conduction.
 

crutschow

Joined Mar 14, 2008
38,319
For Q2: with a 200 ohm gate resistor (R3), the gate charging current is limited to 60 mA. The A03401A has a total gate charge of 14 nC, so using Q = It, the charge time is about 233 ns. I don’t have a specific turn-on time requirement, so this seems reasonable.
Since you are not concerned about the switching time, you don't have to design for the minimum time, thus you don't need anything smaller than 10kΩ for the base resistors.
 

crutschow

Joined Mar 14, 2008
38,319
Is there any way to simplify the design? I tried to find a way to omit Q5 but couldn't quite work it out.
No, don't see how that could work.

But you could remove Q7, R9 and R10.
Also remove the ground connections from Q1 and Q5 and connect them both to the collector of Q6.
That makes an AND/OR gate where Q1 or Q5 can't turn ON unless Q6 is also ON (enabled).

As a bonus, it also eliminates the voltage drop across Q7.
 
Last edited:
Top