Getting voltage from battery or usb. How to do it? - Page 1
Forum section: electronics / beginners

author: Moriambar
author_rank: Unknown
timestamp: September 03, 2023, 12:14:01 pm
content: Hi,I'm trying hooking up a low power (MAX 70mA, for around 20s, 20-30 mA standby) for a friend. The circuit works and I thought of using a 9V battery with a LM7805, which I have tons of (and I don't care for the lost power). All fine and dandy, but this friend told me he'd like a micro usb power input too.Now, the problem is that I can't figure out a way to:use the 9V battery only when neededprotect the battery when the usb power is on (and the usb from getting 9V)switch electronically between the two power modesWhat I mean is that unless I use a relay (I could) I see no other way with just trannies or diodes or whatever.Can this be done without specialized ic or a spdt relay?Thanks

author: Doctorandus_P
author_rank: Super Contributor
timestamp: September 03, 2023, 01:15:05 pm
content: The simplest way would be to just use two scottky diodes to OR the inputs from the USB connector and the LM7805. But you will loose some voltage. An additional problem is that USB voltage is not stable. I think worse case specification is somewhere around 4.2V.Also, "officially" you have to request current over 100mA (or thereabouts) from an USB port, and only use more current when the request is granted. It used to be common to just have a PPTC fuse on the PC side of an USB port, and you can pull 500mA out of it with little worries. But as electronics get cheaper, specialized IC's get made and USB ports are abused all too often, this may change or maybe is already changing. But for low current it probably all does not matter much.But if you want to get a good stable 5.0V power supply voltage from a (random?) USB connector, you would already need something like a SEPIC converter.

author: ledtester
author_rank: Super Contributor
timestamp: September 03, 2023, 02:51:48 pm
content: This solution will give you power from the supply which has the greater voltage:https://www.eevblog.com/forum/projects/dual-supply-load-control-using-mosfet/msg4989856/#msg4989856For a specialized IC, do a search for a "power mux" -- e.g.:https://www.ti.com/power-management/power-switches/power-muxes/overview.html

author: Moriambar
author_rank: Unknown
timestamp: September 03, 2023, 03:04:47 pm
content: Quote from: ledtester on September 03, 2023, 02:51:48 pmthanks but it's not my use case. USB should always win

author: Moriambar
author_rank: Unknown
timestamp: September 03, 2023, 03:05:48 pm
content: Quote from: Doctorandus_P on September 03, 2023, 01:15:05 pmmy use case is well below 100mA (I measured a max of 70 mA). I don't have to have the most perfectly precise 5V. usb 5V would do

author: Peabody
author_rank: Super Contributor
timestamp: September 03, 2023, 03:28:06 pm
content: Quote from: Moriambar on September 03, 2023, 03:04:47 pmWell, that circuit might still qualify. If you pick a mosfet that does not have a super-low threshold voltage, then the mosfet will be turned off whenever USB power is present. The gate/source voltage will be the voltage drop across the schottky, so if the threshold voltage is like 1V or higher, USB should always turn the mosfet off. So it's not really the higher of the two inputs that wins.Edit: No, I got that wrong. The gate voltage will actually be higher than the source because of the schottky drop, so the mosfet will be super-off. Still, the 7805 voltage would have to be higher than USB voltage by the threshold voltage of the mosfet before the mosfet could be on. And that would occur only if the mosfet is already on when USB is connected.But then you could still get battery current through the mosfet's body diode. However, that diode will behave like a normal rectifier, with a voltage drop of about 0.7V or higher - versus the drop across the schottky of maybe 0.3V. So as long as your 7805 is reasonably close to USB voltage, I think it should still work. But you can set up a test using an adjustable bench power supply with specific 7805, schottky and mosfet, and see how low the USB voltage would have to go before the battery takes over.

author: Moriambar
author_rank: Unknown
timestamp: September 03, 2023, 03:33:18 pm
content: Quote from: Peabody on September 03, 2023, 03:28:06 pmthanks, I'll definitely try it!

author: Peabody
author_rank: Super Contributor
timestamp: September 03, 2023, 03:39:58 pm
content: Please note that I edited my post. But the answer is still the same.

author: Moriambar
author_rank: Unknown
timestamp: September 03, 2023, 03:53:13 pm
content: Quote from: Peabody on September 03, 2023, 03:39:58 pmI kinda don't understand the edit.I maybe posed the problem wrong: ofc the usb voltage should be injected on the 7805 output, the 5V rail, but I don't like the 9V powering the 7805 if not necessary (well I actually don't know the quiescent current).Thinking on and on I guess that a DPDT relay is the best choice, with a nfet (and flyback diode, plus pulldown) controlled by the usb 5V. NC will be 9V to 7805 and 7805 to +5V. NO will be 9V to nothing and usb to +5V.I am starting to think everything else is kind of overengineering. Also I have some spare relays!

author: Peabody
author_rank: Super Contributor
timestamp: September 03, 2023, 05:10:12 pm
content: A relay would bring its own problems, such as potentially resetting your device when it's switched.If you aren't limited to what you have on hand, instead of the 7805 you could used an MCP1702 regulator, which has quiescent current of about 2uA, and comes in a convenient TO92 package. Then something like the TP2104 P-channel mosfet also comes in TO92. I think even a 9V battery would have a very long life at 2uA current draw.

author: Moriambar
author_rank: Unknown
timestamp: September 03, 2023, 06:50:30 pm
content: Quote from: Peabody on September 03, 2023, 05:10:12 pmthanks for the regulator suggestion.I'll try and answer below:since it's not a "mass" product, but a "one-of", I'll provide detailed instructions to my friend, ie, don't plug the usb when it's onthe "what I have" limitation comes from not finding int worth to spend money (especially shipping), to buy extra components for this projectthanks!

author: ledtester
author_rank: Super Contributor
timestamp: September 03, 2023, 09:39:24 pm
content: It seems the circuit presented in this post could also work:https://www.eevblog.com/forum/projects/dual-supply-load-control-using-mosfet/msg4992802/#msg4992802Tie V3 to V1. Then power from V1 will flow through the MOSFETs only if it is 0.6V higher than V2.ltspice sim attached.

author: JustMeHere
author_rank: Frequent Contributor
timestamp: September 03, 2023, 11:41:13 pm
content: Check out the schematic from the ESP32 Thing by Sparkfun. Top left cornerhttps://cdn.sparkfun.com/assets/learn_tutorials/5/0/7/esp32-thing-schematic.pdfPS, a 9V battery won't power a 70ma circuit for that long.