Can you automatically switch between a main and backup battery power supply? - Page 1
Forum section: electronics / beginners

author: logancane
author_rank: Regular Contributor
timestamp: May 25, 2021, 10:28:38 am
content: Hi everyone,Is there such a thing as a circuit or IC component that will automatically switch from a main battery source to a backup battery source when the main battery source drops to a specific voltage? I've trauled google extensively but can't seem to find an adequate solution.I want this to be analog or hardware logic based. I don't want to use a MCU to read voltages and drive a transistor gate for reliability reasons (i.e. I want this functionality to persist even if the MCU stops working for whatever reason, plus I can't justify the cost of an MCU to do that one task). With that said however, I want its power usage and voltage drop to be as small as possible.I would also like the switch to only happen when the main battery source reaches the reference voltage, not when it is merely lower than the backup source. (i.e. not the usual Schottky diode solution).The threshold voltage I would like to use is 6.4V (min V for 2S 18650 cells).If it must be connected in series with the batteries, maximum current draw is likely to be around 10A but only momentarily. Average is more like 2A.Any help would be much appreciated. Thanks!

author: BeBuLamar
author_rank: Super Contributor
timestamp: May 25, 2021, 05:37:32 pm
content: Would it be a problem if there is power interruption during the switching?

author: logancane
author_rank: Regular Contributor
timestamp: May 25, 2021, 10:00:01 pm
content: Quote from: BeBuLamar on May 25, 2021, 05:37:32 pmI was hoping I could get around that with a parallel capacitor or by switching the backup in right before the main battery goes out. I don't know if either of those options would work though

author: james_s
author_rank: Super Contributor
timestamp: May 25, 2021, 10:08:13 pm
content: Well you can use a pair of diodes to isolate the two power sources and whichever one is delivering a higher voltage will power the load. If you use a Schottky diode the losses will be fairly low. You can also use a relay to select the source and a comparator to activate the relay when the voltage is above or below a chosen point.If your device already incorporates a microcontroller you can use ADC pins to monitor the battery voltage and use software to switch a relay based on whatever parameters you like.

author: logancane
author_rank: Regular Contributor
timestamp: May 25, 2021, 10:15:48 pm
content: Quote from: james_s on May 25, 2021, 10:08:13 pmThanks for that, I will definitely look into the idea of using a comparator.

author: BeBuLamar
author_rank: Super Contributor
timestamp: May 25, 2021, 10:32:34 pm
content: You also need some delay circuit. You want to have the diodes as well. I think you should switch on the back up before turning off the main. There will be a time when both batteries are connected but with the diodes only the one with higher voltage will power the load. If you don't want to voltage drop across the diode you can have another relay bypassing the diode after the switching is done.

author: james_s
author_rank: Super Contributor
timestamp: May 25, 2021, 10:41:25 pm
content: Diodes are not necessary if you use a relay to switch between sources. You just need a sufficient filter capacitor on the power rail to ride out the milliseconds it takes the relay to switch. You do want some hysteresis with the comparator so it doesn't rapidly chatter when the voltage is right on the threshold.

author: logancane
author_rank: Regular Contributor
timestamp: May 25, 2021, 10:48:34 pm
content: Ok, so a parallel capacitor on the power rail, positive feedback on the voltage comparator and can I exchange the relays for FET's?

author: bdunham7
author_rank: Super Contributor
timestamp: May 25, 2021, 11:01:43 pm
content: I would start with a low voltage single-supply dual op-amp like the LM358, a voltage reference of some sort (perhaps 2.5V) and two power MOSFETS with a low enough RDSONand high enough current rating for your needs. All of that should be fairly cheap.Use one of the op-amps as a comparator, sensing the main B+ thru an appropriate voltage divider. Use the output of that op-amp to turn on the main B+ MOSFET, then use the other op-amp as an inverter and the output of that to turn on the backup B+ mosfet. Add a little feedback from the output of the first op-amp to the main B+ sense divider so that there is enough hysteresis to prevent the system from going back to the main B+ right away--the battery voltage will rise when you remove the load.

author: logancane
author_rank: Regular Contributor
timestamp: May 25, 2021, 11:05:18 pm
content: Quote from: bdunham7 on May 25, 2021, 11:01:43 pmI think this might be the one. I'm going to go away now and try to design that circuit. Thank you!

author: bdunham7
author_rank: Super Contributor
timestamp: May 25, 2021, 11:48:21 pm
content: You will need some additional stuff, like diodes to prevent backfeeding through the MOSFET body diodes and some resistors for the voltage divider(s). You also need to be careful not to make an oscillator! Post your circuit so we canpick it apartgive you helpful suggestions.

author: JustMeHere
author_rank: Frequent Contributor
timestamp: May 26, 2021, 12:01:26 am
content: Are you asking are there uninterruptable power supplies?

author: logancane
author_rank: Regular Contributor
timestamp: May 26, 2021, 12:04:20 am
content: Quote from: JustMeHere on May 26, 2021, 12:01:26 amWell now I feel silly! Yeah, I guess so. I just assumed they were really expensive.

author: james_s
author_rank: Super Contributor
timestamp: May 26, 2021, 01:57:20 am
content: "Really expensive" is relative.If you want mains voltage, older UPS units can be had for free or very little, usually all that is wrong with them is the batteries are shot. Low voltage UPS's are available but they are less common.

author: logancane
author_rank: Regular Contributor
timestamp: May 26, 2021, 02:35:36 am
content: Quote from: bdunham7 on May 25, 2021, 11:48:21 pmOk, I've had a go at designing the circuit. Below I have attached my circuit and the calculations I did. Hopefully they are ok for you to read.The main questions I have are:1. How do I choose the MOSFETs and the diodes (i.e. what characteristics should I be looking for to make sure I am getting the right one)?2. Are my assumptions about negligible opamp current draw valid, or should I stop being lazy and factor that in?If anyone is willing to pick apart and/or give helpful suggestions on this design it would honestly make my day.Cheers!

author: bdunham7
author_rank: Super Contributor
timestamp: May 26, 2021, 02:55:29 am
content: I won't check your math, but that looks like general idea. Two issues--first I think you need to bias the + input of the LM358 or it won't turn on, second if you are on battery, a low-quiescent LDO like the MCP1703T would make more sense than a zener. You should consider the op-amp draw just for completeness, but if you use an LDO, you should have ample current. Why are you regulating it in the first place--does the ADCMP354 have a low maximum supply voltage?As for which MOSFETS and diodes, that depends on your load, your batteries and your expectations.EDIT: You should also carefully read the data sheet for our ADCMP354 if you haven't already. I just had a look and it has a logic output and needs a pullup resistor to function properly. There's also a section on adding the hysteresis the I mentioned and although your 100K feedback resistor could also provide the pullup in theory, I don't think the math works. Also, you want to use the other half of the LM358 as a buffer because apparently the ADCMP354 cannot sink very much current.

author: logancane
author_rank: Regular Contributor
timestamp: May 26, 2021, 04:00:46 am
content: Quote from: bdunham7 on May 26, 2021, 02:55:29 amThank you so much for your help!I've replaced the zener with a 10/5 V LDO as you said.The reason I need Vcc on the opamps so tightly regulated is because the Schmitt trigger relies on it. The equation for choosing the feedback resistors is T = Vs(R1/R2) where T is the threshold voltage and Vs (as I understand it) is the supply voltage (https://en.wikipedia.org/wiki/Schmitt_trigger). If the supply voltage changes (as it will when the battery discharges), the threshold voltage will change also. Bearing in mind that I am trying to squeeze as much juice out of the main battery as possible before switching over to backup, do you think this might still be overkill?As for the biasing, I think I see what you mean. The positive and negative rails are +5V and 0V respectively, therefore on the ADCMP354 when the - input > + input, the output will be 0V. Since 0V is what the + input of the LM358 is currently "biased" to (i.e. it is tied to GND) there is some question about whether it will actually turn on or not. So what I should do is make a voltage divider network between the LDO and GND to give the + input of the LM358 a non-zero voltage reference of say 2.5V for example? Sorry, I have learnt opamps before but they are still really confusing to me.Thanks again!

author: Peabody
author_rank: Super Contributor
timestamp: May 26, 2021, 04:11:37 am
content: I hate to see the voltage drop across the two blocking diodes. I think maybe you don't need the one on the backup side because the body diode on that side would be reverse biased unless the voltage coming from the main side is about 1V above the 9V battery voltage. With a new battery at about 9.6V, the voltage on the other side would have to be 10.6V before current would pass. But of course it would never actually be higher than 8.4V.Then you might consider replacing the diode on the main side with another mosfet right next to the existing one, but oriented in the opposite direction. Both would turn on and off together, but with the body diodes oriented in opposite directions, no current could ever flow through them. And of course when the mosfets turn on, both body diodes are bypassed, so there's no voltage drop. Or I guess more accurately - the voltage drop across the second mosfet is probably a lot less than the drop across the diode would have been.As for the choice of mosfets, it depends on whether you can get away with a surface mount part. You might have to experiment to see how hot they get. The DMP2045U is a 4A average current part that might work. If a TO-220 is needed, the NDP6020P would probably be fine.

author: bdunham7
author_rank: Super Contributor
timestamp: May 26, 2021, 04:36:00 am
content: Quote from: logancane on May 26, 2021, 04:00:46 amThe data sheet says that the maximum supply voltage is 5.5V, so regulation to 5V is needed. I didn't see any reference to Schmitt triggers in the datasheet and I don't think it it or has one--that's why they have the section on adding hysteresis. The actual math is a bit more complicated as you can see on page 9 of the datasheet--but you may be right in that Vccis in the equation because Rpullupis connected to it. Also note that the thresholds are also dependent on Rloadbeing much higher than the feedback and pullup resistors, which is why I suggested buffering. The MOSFET gate may have enough capacitance to destabilize things even if its steady state current draw is very low. The LM358 will be able to handle that much better. You also might consider only using the 5V regulated line for the ADCMP354 and powering the LM358 directly from the battery. Which brings up another issue--is this expected to work even if the main battery is completely dead or missing? How about the backup battery? Is it OK to run the op-amps from that?

author: logancane
author_rank: Regular Contributor
timestamp: May 26, 2021, 10:55:20 am
content: Ok so I think I have taken into account everything that people have said and have made some changes to my design.I've done some more analysis on my load and it seems the max current will now be closer to 8A at 6.4V (i.e. 52W)I added a 5V LDO to regulate Vcc for the opamps.I have gotten rid of the ADCMP354 and replaced it with the other LM358 opamp in the package. This allowed me to design a Schmitt trigger with maths that I can understand, plus as was pointed out, it can sink more current. The voltage reference from the ADCMP354 has now been replaced by a voltage divider sourced from the regulated 5V Vcc rail.I now only have 1 diode which protects the main battery. It drops 0.45V at 8A, or at least that's what I think Digikey's Vf@If column means (https://www.digikey.co.nz/product-detail/en/microsemi-corporation/UPS840-TR13/UPS840-TR13CT-ND/4395189).I have chosen to use the same MOSFETs for source switching. Assuming Vgs is the positive rail voltage of the opamp (5V), these seem to have a low voltage drop and they also seem to have the current carrying capability (https://assets.nexperia.com/documents/data-sheet/BUK964R8-60E.pdf)Have I got this right? am I missing anything? I've learnt a lot today but I still can't be certain I've got everything.Cheers!

author: Zero999
author_rank: Super Contributor
timestamp: May 26, 2021, 02:04:58 pm
content: How about an ideal diode circuit?There are ICs available, or just do discrete. The BJTs will need to be well-matched for the circuit to work well. Fortunately BJTs are sold in matched pairs, such as the DMMT5401.Ideal diode discrete.aschttps://electronics.stackexchange.com/questions/223935/understanding-an-ideal-diode-made-from-a-p-channel-mosfet-and-pnp-transistors

author: Peabody
author_rank: Super Contributor
timestamp: May 26, 2021, 02:16:32 pm
content: Maybe I don't understand what you're doing, but I don't see how N-channel mosfets can work with high-side switching. The gate voltage has to be higher than the source voltage to turn it on, but the output of your opamp will be less than 5V. It seems to me you will need P-channel mosfets with source terminal connected to the battery, drain to the load, and pullup resistors (to source) on the gates. And then the opamps would need to be comparators instead (LM393) with open collector outputs. They would be wired to ground the gate to turn the mosfet on. But this complicates things because P-channels don't have as low RDSon as N-channels.Also, how many sets of 18650s will you have? I don't think a single 18650 will provide 8A, or that it's protection circuit would let it. And then is the 9V backup battery just a regular PP3 alkaline or lithium primary? If so, I don't think it would provide 8A, or even 2A, for long enough to make any difference.I just wonder if it really makes sense to do this backup structure at all for these current levels. It might be more productive to just add more 2S 18650 sets in parallel, and use your opamp to generate some kind of warning (a buzzer perhaps) when the voltage gets too low. Then you wouldn't have any voltage drops across mosfets or diodes, and the life of the batteries would be at least as long as dividing the batteries between primary and backup.

author: bdunham7
author_rank: Super Contributor
timestamp: May 26, 2021, 02:34:30 pm
content: Quote from: logancane on May 26, 2021, 10:55:20 amNow that I see the whole thing drawn out, it becomes obvious that it won't work.The source of the MOSFETS will be at a higher voltage (~7 volts) than the gate (~5 volts max). You either need different MOSFETS and a slightly different configuration or else replace the 5V regulator with a boost converter and run the op amps at a higher voltage, say 15 volts.A D-MOSFET like this:https://www.mouser.com/datasheet/2/240/ixys_s_a0003807192_1-2272483.pdfwould sort-of work, but would not be fully switched on with the current schematic--which could be fixed. However, those are very expensive, uncommon parts.

author: bdunham7
author_rank: Super Contributor
timestamp: May 26, 2021, 03:12:04 pm
content: Quote from: Peabody on May 26, 2021, 02:16:32 pmYou beat me to it, but it won't work as drawn, which only seemed obvious once I saw the whole thing drawn out with the part number instead of generic magic MOSFETs--which would have to be DMOSFETs for this to work and that's not a winning plan.

author: Peabody
author_rank: Super Contributor
timestamp: May 26, 2021, 05:51:50 pm
content: I think your idea of boosting the opamp power to 15V might work well. Then he could still use the N-channel mosfets with their vanishingly low RDSon values. Or, maybe redesign it for low-side switching using these same mosfets. Then the 5V supply would work.I still think going to 2S2P 18650s, without all this backup stuff, would serve him better. And to get 8 amps, he may have to do that anyway.

author: bdunham7
author_rank: Super Contributor
timestamp: May 26, 2021, 06:02:49 pm
content: Quote from: Peabody on May 26, 2021, 05:51:50 pmWe don't know what his load is or what the backup battery does, exactly. It might be very intermittent and the backup is just to retain memory or something. I don't think low-side switching is an option in his case.Actually I think these "magic MOSFETS" would save the day at a reasonable price:https://www.mouser.com/ProductDetail/Diodes-Incorporated/DML3006LFDS-7?qs=YCa%2FAAYMW01AVvNLyFJLCQ%3D%3DThey have logic and a charge pump to boost the gate drive all built into one 67-cent package and they run on 5 volts. It appears they would work with the current circuit he has laid out.Otherwise, yes, boosting the gate voltage seems to be the only sane way to do high-side switching, unless someone with more experience has a different idea.

author: Peabody
author_rank: Super Contributor
timestamp: May 26, 2021, 06:28:36 pm
content: Those magic mosfets look very interesting. Do you know of any that come in a more hobbyist-friendly package?

author: logancane
author_rank: Regular Contributor
timestamp: May 27, 2021, 12:14:21 am
content: Thanks for the suggestions everyone!Let me add some context if I may. The whole system is for a high altitude balloon that will be carrying some potentially expensive equipment. For this reason, my role in the project is to create an absolutely bulletproof reliable power supply. This is only one part of the larger system which includes a whole lot of independently regulated outputs, each with their own protection and redundancy.I am also trying to build everything solid-state because it is not yet clear what effect the low pressure environment will have on the system. There will be low temperature too but that is taken care of with both the electronics dissipated heat plus an external heater.The loads themselves include sensitive devices such as MCU's and radios, that's why I think it has to be high-side.In reality, the power supply will likely be nowhere near 8A most of the time. There are three things that throw a spanner in the works. First, we must power an unknown payload that could be up to 25W. Secondly, there is a balloon termination system (detaches the parachute from the balloon prematurely if needed) which can draw up to 2A for about 15s and thirdly, there is a heater with bang-bang control (which as we do more research on this, the more unlikely it seems we are going to need it). Nevertheless, I am designing for a worst-case current situation where everything is on at the same time.The reason for the backup battery is that it must be a physically separate power source. If the main battery fails or runs flat, we can terminate the balloon, switch off non-essential loads and bring it down safely. It was an oversight on my behalf to think I could do that with a standard 9V Lithium battery, or even a couple in parallel. I think what I might do is just use more 18650's unless anyone can think of a more energy dense battery that could be used (bearing in mind weight)?If I swap the LDO out for a 15V boost converter, will this work?Alternatively, I found this magic mosfet! And it has easy to use leads! (https://www.digikey.co.nz/product-detail/en/infineon-technologies/BTS6142DAUMA1/BTS6142DAUMA1CT-ND/3819676)It's perhaps a little overkill being rated to 33A, and it is pretty expensive (4.26NZD) but it has some protection features which can act as a redundancy to Efuses I am already using elsewhere in the circuit. When I searched for magic mosfets (or load switches as they are officially names) this was the cheapest >10A rated one I could find that was in stock, had a minimum order of 1 and wasn't a QFN type package. I think for a one-off highly critical application such as this, it is worth it. One question I have about it though. The description of the input pin says "activates the power switch if shorted to ground". Does this mean that this is an active-low device? Also would I still need diodes given the power supplies are still facing each other?Anyway, you have been an enormous help so far. Really keen to hear your suggestions.Cheers!

author: james_s
author_rank: Super Contributor
timestamp: May 27, 2021, 01:54:35 am
content: That context is useful here.IMHO the best way to get reliability is redundancy. If I were trying to do this, I would look at having 2 or 3 completely independent power supplies each consisting of a battery, regulator, etc, each capable of carrying the entire load on its own, that each connect separately to the DC bus powering the equipment via isolating Schottky diodes. You don't necessarily need to wait for one power source to fail for another to kick in, you just have them all feeding the bus at once and if one drops out for some reason the others will just keep carrying the load. There are methods you can use to load share between multiple power sources but it shouldn't really matter in this case, whichever one is producing a slightly higher voltage at the time will carry the load, it doesn't matter which one when they are all capable of doing the job on their own.I'm sure you are already aware of this but a significant challenge of high altitude is that it is very cold, which is especially challenging in regards to batteries but other parts can have thermal issues too so be mindful of temperature ratings. Everything should be well insulated and you may even want to have heating elements that can be energized to keep the equipment bay from getting too cold.

author: logancane
author_rank: Regular Contributor
timestamp: May 27, 2021, 02:19:54 am
content: Quote from: james_s on May 27, 2021, 01:54:35 amGreat suggestions, thanks for the response!It will have a heater on it, though after talking to some people who have done this before, it actually sounds like cooling might be more of an issue. The electronics can generate a lot of heat and because it is in an enclosed space and because at high altitude there is almost no convection, getting the heat out can be a challenge. Anyway, that is the job of another team member to sort out. I think they are looking at wax motors and some really good heat sinking for that.As for your suggestion, thank you for re-framing my initial assumptions. I guess there is no need for a switch per se. That said, there is no way I can have multiple power sources, all capable of driving the load for the full flight-time. That would be simply too much weight. Instead the goal is to have a power source that can power the load for the entire mission and a backup that has only enough power to terminate the balloon and then drive the essential loads (location updates and heater) and only for the time it takes to descend back to earth (+ slow location updates once there).If I were to have both connected to the DC bus through a Schottky as you suggested, but have the backup at a lower voltage, is it true that the backup would only contribute power once the main battery cuts out either through failure or depletion? Also, I would need to look into ways of making the battery cut out instead of continuing to discharge.Cheers

author: james_s
author_rank: Super Contributor
timestamp: May 27, 2021, 02:27:55 am
content: Yes, that was my next thought while reading your reply. If you have a backup source that is lower voltage but still high enough to keep the load operating then it will sit there and do nothing until the voltage of the primary source drops below what it is producing. You could monitor the current out of the backup supply (they make inexpensive high-side current measuring ICs for just this sort of thing) then you can tell when the main supply is having issues. You can also easily monitor the voltage on the primary and backup batteries to get an indication that there may be trouble brewing.

author: bdunham7
author_rank: Super Contributor
timestamp: May 27, 2021, 04:31:04 am
content: Yes, I think it will work if you have 15 volts--somebody correct me if they see a problem.I think what you have found would work although I didn't scour the details. Don't worry about the high current rating, it's not excessive overkill. Components often have high ratings that while not fake, are unrealistic due to other constraints. In this case, that would be heat dissipation and at 10A and 10mR, you have 1 watt. A bigger package is a bit easier to design for.As for whether you need to even do all this, I'm not sure I fully understand your load situation.Is the main battery jettisoned or does the whole thing come back together?Is it accepted that once the main battery is depleted or fails, the high-power functions will become unavailable and the backup battery will only power certain lower-power things?Does everything need to be on the same power bus?How cost-constrained are you? What is your weight budget for the batteries and this controller? How long does the balloon stay up and at what altitude?

author: Peabody
author_rank: Super Contributor
timestamp: May 27, 2021, 03:23:57 pm
content: If you use diodes, the battery with the highest voltage will always power the load. That's because the diode of the other battery will be reverse-biased, so no current will flow through it. If the primary battery fails suddenly, then the transition will take place quickly. But if it's just that the primary is depleting normally, then there will be a point at which the voltages are equal, and I think from that point on, both batteries will be supplying current, and both will be depleting together. I'm not sure that would work for you.You also have to consider that you will always have some voltage drop with diodes - at least 0.3V - and if you're passing amps of current the heat generated could be significant. And of course the heat is just wasted battery power. But mosfets can drop voltage too even with ultra-low RDS if the current is high enough.The other thing is that you will also need to know that the backup has started supplying current so you can take whatever shutdown action is needed at that point. So in addition to the diodes, you will need some way to read the voltages of the two batteries.And while I'm thinking of it, I'm gonna suggest that you consider using unprotected 18650s. The problem is that anything that causes even a temporary high current could trip the protection circuit, and that would completely shut off the battery. I know there are reasons to use protected batteries, but you'll just have to consider what the risks are each way. I believe quadcopter jocks use unprotected batteries so the drone won't suddenly fall from the sky because it has tripped the overdischarge protection. Better to limp home and ruin a battery by overdischarge than lose the aircraft.

author: james_s
author_rank: Super Contributor
timestamp: May 27, 2021, 08:17:33 pm
content: Monitoring current out of the backup battery will also tell you when something is drawing from it. That's a good point about both batteries draining at the same time once the voltage is equal, I don't think that is undesirable though as long as you know the backup battery is being loaded it makes sense to still keep extracting what you can from the primary battery.Yes RC aircraft including multirotors use unprotected batteries, usually li-ion pouch cells usually called LiPos. I fly electric model airplanes that use the same sort of batteries and even a smallish plane can pull 30-40 amps from the battery continuously at full throttle, a protection circuit that could handle that would be bulky and heavy, and it would be another potential single point of failure. For a lower draw protection should not really be a problem, I think some protected cells will auto-reset as soon as the overload is removed. Might make sense to build a custom battery pack that has its own BMS chip in it, or repurpose an off the shelf laptop battery. Lots of battery options that would work.

author: Peabody
author_rank: Super Contributor
timestamp: May 27, 2021, 10:48:28 pm
content: But if the primary and backup are going to discharge together, you're better off just adding 18650s in parallel to the primary, and doing away with the diodes. They still discharge together, but you have longer battery life because you aren't dissipating heat in diodes.Every time you add a protection or safeguard, that's another potential point of failure, and another opportunity to abort the mission prematurely. So suppose some function switches on and there's an inrush current that temporarily drops the primary battery voltage below the switchover level. Are you going to abort because of that?This brings up another issue the OP mentioned originally, and that's not wanting to use a processor to control this stuff. I think something like an ATTiny85 8-pin controller could read the battery voltages and make decisions that include the passage of time, and control the mosfets or magic mosfets, and send a signal to the main controller (assuming there is one) to abort if that's needed. And I don't think it would be any less reliable than the opamps or comparators.I don't know how much leeway he has with what has to be included. If it were up to me, I think if I couldn't provide a redundant full power supply because of weight, I would just make the power supply a simple and foolproof as possible and hope for the best. I might, however, power the locator function completely separately to give it the best chance of working no matter what else happens.

author: JustMeHere
author_rank: Frequent Contributor
timestamp: May 28, 2021, 01:14:11 am
content: Take a look at the schematic for Sparkfun's ESP32 Thing. It has an answer.

author: logancane
author_rank: Regular Contributor
timestamp: May 31, 2021, 04:08:02 pm
content: Sorry I disappeared for a bit there, had more urgent things to work on. Anyway, I went away and worked on a new version and then only saw your replies just now. It seems I have implemented some of the things mentioned here already.I have decided to use the "magic mosfets" mainly because they also have some monitoring functionality (such as battery voltage) and because they don't require a boost converter to turn them on.As far as the type of 18650's is concerned. It was always my intention to use unprotected cells for the very reasons suggested here. Both this circuit and the others that come after it have multiple levels of protection with my goal being to time grade it, meaning that the POL protection will trigger before the protection further upstream. The idea is that if any of the separately regulated multiple loads that faults, its protection will trip and take it out before the main protections trips and takes the whole system out.Ultimately I couldn't make the diode idea work because once I added up the worst-case voltage drops across the components on the main battery side it would require too low of a backup battery voltage, plus as I mentioned earlier I don't want to rely on an MCU to control anything (in this case to stop the main battery from overly discharging).With that said, in the new design I have used the signals from an MCU as a backup which can take over control of battery selection. The way it works is that if a signal is sent from the MCU, the NOR gates will go low at the output causing the AND gates to also go low, which via the BJT's will cut Vcc to the opamps and thus kill the circuit. The backup load switches which are also controlled by the MCU will turn on and current will continue to flow. I figure this will happen slightly before the circuit turns off due to the signal delay through the gates but I think it will be ok, the load switches will just share and possibly circulate current momentarily.I haven't calculated all of the values yet but I think in principle it should work. Keen to hear what you think, can you see any glaring mistakes?

author: bdunham7
author_rank: Super Contributor
timestamp: May 31, 2021, 05:32:47 pm
content: Without component part numbers and values, nobody can really examine it. Not that I'm promising to do so if you provide them--this is the next level of complexity and you're going to have to breadboard it. Frankly I think you may have just introduced a lot of new ways that the circuit can fail.If you look back a few posts, I asked a few questions about your requirements. I actually think the the whole switchover thing may not be the best way to design your power supply. Energizer L91 AA lithium primary batteries have about half the energy of a good 18650 Li-ion battery--3000mAh+ and 1.7 volts. It takes two AA in series to come pretty close to matching a single 18650, but the L91AA weighs 15g, while a typical 18650 is 45-48g. Thus the L91 AA gives you 50% more energy per unit weight. They also have the additional benefit of working down to 40 degrees below zero.I still don't know the details of your expected max power and energy requirements, but a 2SxP Li-ion pack would be 90x grams in cell weight, the equivalent 4SxP AA L91 pack would be 60x grams cell weight. The AA L91s have a max discharge rate of 2.5A, so calculate from there and see if they work.https://data.energizer.com/pdfs/l91.pdf

author: Peabody
author_rank: Super Contributor
timestamp: May 31, 2021, 05:37:50 pm
content: Well, first a couple questions.So the backup battery is a pair of 18650s - the same as the primary?What magic mosfets are you using? Are you sure they need the blocking diodes?Are you going to simulate this circuit in LTspice?I'm having trouble understanding the logic of all the BJTs and boolean stuff. It seems T7 and T8 are switching ground into the LDO. Shouldn't their emitters be connected to something high? Also, you seem to be missing series base resistors on T2, T3, T5, T6, T7 and T8. And I'm not sure what R15 and R18 do.Well, I'm glad you've decided on such a simple, reliable circuit like this rather than using an MCU. Let's see. Two opamps, two NOR gates, two AND gates, an LDO, four diodes, four NPNs and four PNPs. What could possibly go wrong?Edit: You have the NOR and AND ICs powered from the load. I guess that's ok, but would want to think about it. And what's powering the backup MCU?

author: logancane
author_rank: Regular Contributor
timestamp: June 03, 2021, 06:28:56 am
content: Unfortunately it seems the AA's wouldn't have the current capability. We are looking at potentially topping out at 9-10A in the most extreme case. I also need separate batteries for the situation that one fails. I don't know why it would but that is the design criteria. Although the have the same voltage, the main batteries will have more in parallel so they will definitely do the bulk (hopefully all) of the work.Anyway I read the suggestions and came up with a circuit that seems to work on LTSpice (attached). As it was alluded to, the BJT stuff was complete nonsense. I thought I was going to have to drive more current than I actually was and as was pointed out I had half of them connected to the wrong place. The new circuit doesn't have any of that except a FET to drive the N-channel load switch I ended up going with.I've also attached two plots that demonstrate what I'm trying to achieve.One shows the automatic transition from main to backup during normal discharge (albeit in 30sec) by using the comparator circuit. You can see the Schmitt trigger working by the difference in crossover voltage during discharge and charging. I found that without it, there was in fact some jitter as the load voltage crossed the threshold.The other plot demonstrates a MCU's ability to take authority if need be (perhaps it notices some curly behaviour going on). In this one, I set the "GPIO pin on the MCU" that is associated with the backup battery to logic high, thereby turning off the output of the NOR gate and thus turning off the LDO. You can see however that it actually tracks the main battery voltage first until it reaches the voltage of the backup battery. I'm not entirely sure why it does that. If anyone knows that would be handy. I think LTSpice treats 0V and GND as seperate things, because when I do a DC operating point analysis on it, it says the output from the gate is 0V, not ground. So perhaps I need to have a transistor switch with pull-down resistor? idkAnyway, I guess the next step would be to build it in real life. Given that there are a few IC's on it, I don't think I can breadboard the whole thing, but perhaps small parts of it like the comparator and logic circuitry?To end on a question, how accurate are these LTSpice simulations? Do people actually rely on them enough to skip straight to ordering PCBs? I did have to lower the settings a few times on the way to getting one that would converge every time.

author: Peabody
author_rank: Super Contributor
timestamp: June 03, 2021, 02:57:11 pm
content: I've just started using LTspice, so I don't know how reliable it is. But I assume it has to make assumptions about typical values (gate threshold voltage, for example), while in reality individual parts will vary. So it may be that to get some comfort with the results, you have to simulate with a variety of settings to make sure you aren't on the edge of something that could trip you up.I haven't really studied the whole circuit, but I'm concerned about mosfets M1 and M2. If the LDO is powered down, and the opamps are powered down, are the mosfet gates left floating? Also, what is the state of the IN input of the magic mosfet if it is floating? Is this possibly related to the issue about the output not switching over to backup when the MCU says it should? Or did I misinterpret what you said? If I understand correctly, you want the MCU, if it chooses, to dictate which batteries are used regardless of their voltage levels.And again I would ask what's powering the MCU.You might post the .asc file if convenient.

author: logancane
author_rank: Regular Contributor
timestamp: June 03, 2021, 03:25:38 pm
content: Thanks for that Peabody! I just added pull down resistors at the output of each opamp and sure enough it has fixed the issue.Powering the MCU? Well that depends how much faith I have in this thing. The way I see it is that I have two options:I could trust the system to keep itself powered and power the MCU off of it, orI could power it using the highest voltage source using blocking diodesI guess option 2 would be the sensible thing to do since the whole point of the MCU is to take over control when it is malfunctioning.I will post the asc file when I get some spare time. I've used the manufacturer's SPICE models so I think you would need those too right?

author: Peabody
author_rank: Super Contributor
timestamp: June 03, 2021, 03:40:28 pm
content: A third option would be to power the MCU from it's own battery. Possibly a coin cell if the voltage is high enough.I'm glad the pulldown resistors worked. Don't bother with the .asc. I was just curious.

author: Peabody
author_rank: Super Contributor
timestamp: June 03, 2021, 04:36:29 pm
content: I wonder if there isn't a way to greatly simplify this. Perhaps you could have only two magic mosfets, which would be directly controlled by boolean outputs. The LDO would stay on, and the boolean inputs for each magic mosfet would be two GPIO lines from the MCU (so you would need four in total), and the output of the opamp.So if GPIO1 is high, the mosfet would be on no matter what. If GPIO2 is high, it would be off no matter what. If both are low, the opamp would decide. If both are high, that could be an illegal state, or the same as both low. I don't have time now to work on this, but you might make up a truth table that reflects what you want, and then find the right logic chip that provides it - a dual something or perhaps a quad something. Anyway, then you wouldn't need the mosfets either.

author: Peabody
author_rank: Super Contributor
timestamp: June 03, 2021, 10:34:15 pm
content: Let's suppose you have only two power switches, one for the primary batteries, and the other for the backups. The LDO stays on. Each switch is powered by an N-channel mosfet or NPN transistor which grounds the IN pin to turn on the switch. The gate/base of the transistor is connected through a resistor to the output of a CD4051 analog multiplexer (available in DIP, SOIC and TSSOP). That chip has three selection inputs, 8 analog inputs, and one analog output. Based on the selection, one of the inputs is connected to the output.The selection inputs are GPIO1, which goes high if GPIO2 is to determine the state of the switch regardless of the opamp outouts, the GPIO2 line itself, and the opamp output. For each possible combination of these selection inputs, you decide what the output should be, and then tie the corresponding input pin to Vcc or ground.So for the entire circuit you would need two CD4051's and four GPIO lines, but only two magic mosfets, and you wouldn't need the NOR gates.