# Is this power switching circuit ok? Switching between VIN and USB

I am using a STM32F105FBT6 to create a CANbus analyser.

I plan to have a simple PC application that displays the CAN messages and lets the user put messages onto the Bus.

I also what to be able to program the device to continue sending a particular message on the bus when the device is disconnected from the PC and powered by VIN.

The device can be powered by VIN (8-30v) or the USB port, both can be powered at the same time.

I don't need really need 5v as all my components are 3v3.

I have come up with a pre regulator circuit using a MIC4680BM which brings VIN down to 5v. I then have another regulator which brings 5v down to 3.3v.

I have used part of the circuit that switches from VIN to USB from the Arduino Uno because this is the simplest application which is most similar to mine.

Their mosfet switch takes VIN though a voltage divider, I need a way to apply VIN to the mosfet which is always above 3.3v and not greater than 5.5v.

My questions would be:

Is this circuit going to work? (Providing I sort the voltage divider problem).

Could I just replace the voltage divider with a separate LDO circuit to take VIN to 5v solely for use as the input for the LMV358 (IC7)?

• I don't see any circuit attached, but from what you describe - no you don't need your device to be USB OTG. You would only need it to be OTG if you planned to plug other USB devices into it. – brhans Feb 7 '16 at 18:52
• Your circuit does not follow USB specs, which allows only 10µF maximum on the +5V line. Your 100µF cap will be problematic when you attach it to a PC or hub. – Turbo J Feb 7 '16 at 19:02
• How would I overcome this? Should I reduce C1 or is there another way I could power the device from USB? – Terry Gould Feb 7 '16 at 19:26
• You could change the switcher to run faster, thereby requiring smaller inductor and smaller switching capacitor. For instance, a solution with the LM25011 running at 1.51 MHz requires a 10 uH inductor and a 10.0 uF output capacitor. – Pål-Kristian Engstad Feb 8 '16 at 17:19
• You can use a PFET or similar and control its turn-on to limit the in-rush current into your device -- lots of devices have more than 10uF of capacitance on-board as bulk, it's just not directly attached to the USB VIN -- the turn-on current is controlled. – Krunal Desai Feb 9 '16 at 21:49

Your basic question statements seems to be "I have two potential power sources, 8V-30V, or 5Vin from USB, and I need 3.3V out -- what's the best way to do it?"

I would think of the problem as such:

1. What's a good part / module that can take in 4V-30V and output 3V3 stably?
2. How can I make sure I don't destroy an upstream USB host if I attach both supplies at once?

An easy way to do this, but not necessarily the cheapest way, is basically to Diode-OR the supplies together such that they cannot backfeed into each other. Using an actual diode of course will not be very power-efficient, due to the voltage-drop induced by it, but we can use devices known as 'ideal diode' ICs, which is just a marketing term for an integrated MOSFET-based solution.

An example of an IC that might work for you is the LTC4412HV -- take a look at the applications example section. This will take care of problem #2.

They don't have exactly what you need in that particular datasheet in terms of an example circuit, but the above is some food for thought.

Problem #1 can then turn into the general problem of 'find a buck regulator (or LDO) that can take in 4V-30V and output 3V3'. I would use a switching regulator here as 30V to 3V3 is quite the drop. I don't know what your current consumption is on 3V3, but if it's relatively low, the OKI-78SR series from Murata are simple 78xx footprint compatible drop-in replacements that are switching supplies.

In terms of meeting USB in-rush current requirements, I would only place 10uF max. directly on the USB line, and then put the rest of your capacitance on the 3V3 rail (where it's needed), and the VIN capacitors for your regulator will be behind the ideal-diode / PFET controller, which can have its turn-on time controlled to not cause an over-current event on the USB host.

The most simple solution is to simply Diode-OR both supplies like this:

simulate this circuit – Schematic created using CircuitLab

The downside is that you'll drop 0.7V across a regular silicon diode and about 0.15-0.2V across a Schottky, which may or may not be acceptable to you. Also, this circuit has no "primary" or "secondary" arbitration between supplies. Whichever supply is higher will be sourcing the most current. The second circuit below may be a bit better.

simulate this circuit

The FET should be some sort of low-RDSon FET. Either way you will still need some sort of power conditioning circuit, like a buck-boost so that you can accept voltages higher and lower than your required output voltage. These circuits take care of the power source arbitration. In the second circuit, V2 is your "take over" supply; that is to say, V1 is the primary supply that you run your circuit from unless V2 is connected, then it will run from V2.

So after I lot of searching i think I have found the best solution.

I have now simplified the circuit a lot as there is no need for 5V. I have now made the main regulator output 3v3 rather than 5v. VIN enters the regulator through a diode. USBVIN (which has a capacitor not shown on this schematic) connects to a PFET which outputs to the regulator after the diode. I have added a 100k resistor across VIN to help pull down the gate of the FET when VIN is not connected.

Im pretty sure this should now work.