Tips for designing a USB & battery powered MCU project with built-in charging - Page 1
Forum section: electronics / beginners

author: JoeN
author_rank: Frequent Contributor
timestamp: November 09, 2015, 09:18:20 pm
content: I am sure this has been discussed before but I don't see exactly what I need and thought I would run it by you. Simple requirements () - small portable device built on a low-power ARM MCU that uses battery power when disconnected from USB and uses USB power when connected and also charges a built-in LiPO cell. USB D+/D- should still be available to MCU. I intend to use 3.7V 150 mAh Li-po cells that I have sourced cheaply from China on eBay. I would prefer to use the Microchip MCP73831T-2AC charging circuit because it is cheap and I have 8 of them sitting here. I already used 2 to build simple chargers and they work great. Can anyone suggest a circuit? There are lots of battery charger circuits out there but I can't find one that does something quite like this and I would appreciate some expert advice. I will be using an external 3.3V regulator.LiPo Charger IC:https://www.sparkfun.com/datasheets/Prototyping/Batteries/MCP73831T.pdfThank you.

author: KL27x
author_rank: Super Contributor
timestamp: November 09, 2015, 10:18:51 pm
content: QuoteDiode rectifiers? This is pretty basic stuff.If your circuit can run off of 3V, this would be a lot easier than 3.3V. All you would need, potentially, is a diode.USB 5+/battery charger IC input/3V regulator input = node1. Battery and charger IC output = node2Node 2 >diode rectifier (+-switch)> node1. Current only flows through the diode when Vnode2 > Vnode1, which only happens when you unplug the USB cable. But this only works if the charger IC will not drain current when Vin is less than Vbat. Otherwise, the battery will drain current trying to charge itself. I'm pretty sure mcp7831 won't do that, but I haven't tested it.The load voltage of the LiPo minus the diode FVD will cut things too close to get a full 3.3V out of an LDO, I think.More properly, I think you need a minimum of 3 diodes?Node1 = USB5+Node2 = 3V regulator inputNode3 = Charger IC inputNode4 = battery/charger IC outputNode1 >diode> Node2Node1 >diode> Node3Node4 >diode> (+- switch)> node2Maybe I'm totally off base with what you're asking. I dunno, maybe Maxim makes a chip with all this stuff onboard, already, lol.

author: KL27x
author_rank: Super Contributor
timestamp: November 09, 2015, 11:59:42 pm
content: Actually only two diodesNode 1 = USB 5+ and charger inputNode 2 = 3V regulator inputNode 3 = battery and charger outputNode1 >> Node2Node3 >> Node2

author: sq5rix
author_rank: Newbie
timestamp: November 11, 2015, 02:05:44 pm
content: Look at this post:http://blog.zakkemble.co.uk/a-lithium-battery-charger-with-load-sharing/

author: JoeN
author_rank: Frequent Contributor
timestamp: November 12, 2015, 04:49:01 am
content: Quote from: sq5rix on November 11, 2015, 02:05:44 pmWow, that is a super useful first post. What's up with that? Most first time posters are asking questions like me.I searched for exactly that article but somehow I missed it. I should have looked for application notes for that part but it didn't occur to me.I have a diode and a p-ch MOSFET that will substitute for those parts very well so I am going to breadboard this and see what happens. I am expecting it to work great. Thank you.Thanks to everyone for their replies.

author: sq5rix
author_rank: Newbie
timestamp: November 12, 2015, 02:51:31 pm
content: It is great I could helpGreetings from Warsaw, Poland!Tom

author: KL27x
author_rank: Super Contributor
timestamp: November 12, 2015, 07:59:24 pm
content: FYI, I have looked at the MCP73831 datasheet, and it indeed has automatic shutdown if Vin < Vbat.So if you can stand the voltage drop of a Schottky on Vbat you could, indeed, use a simple single diode solution.The FET circuit in the link has the advantage of not having that bit of voltage drop. That's all it does, and it's a pretty long way to go for that. If you're feeding the battery into a linear regulator, anyway, this doesn't effect efficiency. Like I said, if you can stand to use a regulated 3V rather than 3.3V, then it would work just fine. One diode. Done.All in all, the circuit in the link is very specific to purpose to the point of being borderline Rube Goldberg. If the load can operate at unregulated Vbat or 5V minus a Schottky, it will probably also run on unregulated Vbat minus a Schottky. Most any digital circuitry will operate just the same. Any DC converter or analog load would suffer only a small penalty from the small voltage drop of the Shottky. So overall, the circuit is pretty dumb, unless under specific circumstances where the voltage drop of a schottky really matters regarding efficiency/voltage of your battery output (max theoretical improvement of maybe 10% run time for certain loads and if attributing zero voltage drop in the FET; no real change in digitally controlled standby/low current modes), and where your pcb is already big enough where the multiple extra components don't matter to overall cost of components and assembly.*Hold the phone.The linked circuit is completely nonsensical to begin with. It provides a direct path of current from USB rail to the battery. If USB rail minus shottky minus reverse FET diode junction > Vbat (which will be the usual case, barring a USB rail on the lower end of spec and a fully charged battery to begin with), the battery will be flooded by current from the USB rail (with the only limit being the output impedance of the rail, ESR of the battery, and ohm's law). If USB > ~4.8V, the battery will be killed, for sure --- Well, unless the charger IC can sink all that current, pulling down the entire USB power rail in the process. Depending on SoC on the battery, you could get up to a 1.5V potential, so obviously the USB port would automatically shutdown under typical circumstances (best case), even if the IC could do that. I could be wrong, and I often am, but I give this circuittwothumbs down. If you add a rectifier on the battery output (highly recommended), the FET and associated circuitry arecompletely redundant. Rube would be so proud.Now, remove the redundant FET and gate circuitry, and you end up with my 2 diode solution. If you remove the unnecessary diode between USB 5+ and Vcc (because MCP78731 doesn't need it), you get my original single diode solution. Now, you may want to leave in the second diode, just in case your USB port/hub malfunctions or gets unplugged, and the rail drops below Vbat.If you can't handle the voltage drop of the schottky, you may wish to use a variation of the circuit in the link. But take out the FET and put in an NC relay.

author: FrankT
author_rank: Regular Contributor
timestamp: November 12, 2015, 08:03:42 pm
content: Sparkfun sell a lipo charger/power module that you can use as your power source...https://www.sparkfun.com/products/11231If that works for you, schematics there so you can incorporate it into a final board.

author: JoeN
author_rank: Frequent Contributor
timestamp: November 13, 2015, 12:47:08 am
content: Quote from: KL27x on November 12, 2015, 07:59:24 pmIt does? That is a P-ch MOSFET. If the USB is energized then the gate is energized and the MOSFET is open and there is no path for the USB current to go back. The battery charger charges the battery, but both the battery charger and battery are disconnected from the load. The USB is directly connected to the load. If USB is not energized, the MOSFET is closed and the battery is connected to the load. It is also connected to the charger which, but apparently that is OK. That is how I read that circuit.

author: KL27x
author_rank: Super Contributor
timestamp: November 13, 2015, 12:50:23 am
content: QuoteNo. If the PFET gate is pulled above threshold, it is non-conducting in the source to drain direction. (And to be completely accurate, it's not "open" in this direction, either. It's more accurate to describe this as an extremely high resistance).From drain to source, it freely conducts with about a 0.3V drop, similar to a shottky diode.Look closely at the schematic symbol for a FET. You will see the diode! You have your FET and breadboard. Give it a try. Or just set your DMM to diode check and put the red probe on the drain, black probe on the source, and watch 0.xxx volts pop up. Congrats, you have just figured out why relays still exist.

author: JoeN
author_rank: Frequent Contributor
timestamp: November 13, 2015, 01:41:06 am
content: Microchip gives almost exactly this circuit in AN1149, with the similar MCP73837 IC (just a few additional features). The article adapts the circuit for the MCP73831, but doesn't really change it. Did Microchip screw up this AN?http://ww1.microchip.com/downloads/en/AppNotes/01149c.pdf

author: KL27x
author_rank: Super Contributor
timestamp: November 13, 2015, 01:48:36 am
content: Ok, I made a mistake. I stopped to actually look at the symbol, and that little diode I was talking about in the schematic symbol was not oriented the way I expected.What I do not see is how this achieves anything, in the first link. Whether full on, full off, or somewhere between, there is no point where current should flow from VUSB to Vbat...[ok, skip to the *** at the bottom for the short version]Oh, ok. It looks like if you balance the FET gate just right, you can trickle some current off of the USB rail to directly charge the battery, thus bypassing the overhead on the battery charger? Either way, you're sucking current from USB rail to feed the battery, but this path is more direct, using the FET as a variable resistor? I actually thought these IC's were pretty darn efficient, as is, dropping some linear voltage either method seems like half a dozen of one, 6 of the other.So if this is your intent, then yeah. Looks simple enough for what (little?) it does. If you don't need it, then use two diodes. I see the Microchip schematic shows a VAC pin. I wonder if there's more going on there than in a simple USB charging IC. Cuz this looks about as screwy as a perpetual motion energy generator. It looks like it would potentially increase the total charge rate/output capability of the charging IC (by reducing heat load on the IC), rather than limit the amount of current available for charging - which is what the app notes suggest.Ok, ok. there IS more to it. In the Microchip app, you can see the device is plugged into USB power AND an external charger. The external charger and USB rail are both fed into the charger IC, separately. But the charger IC appears (I would presume, for this to make sense) to be supplied by the external charger, alone. (Or the Vusb, alone?).*** Then both external charger 5V and USB rail 5V are rectified together into a new 5V rail. So sucking off this combined 5V rail to feed the battery, directly, reduces the load on the USB chips single input from the USB (or the charger?). And even at that, it's a total hack job.So this has nothing to do with your initial question. And the first schematic is woefully incomplete to make any sense. By not showing dual supplies, it makes no sense, whatsoever. Just a perpetual motion generator. My guess is the author of the webpage has simply goofed.QuoteOk, now I know he goofed. This statement (and the red on black schematic) are why I incorrently ASSumed the FET was oriented with the drain on VCC and source on Vbat. (And this is why I don't use FET symbols, because I'm FET-dyslexic). The author has also made the same error. The FET is not being used as a switch between Vbat and Vcc; it's being used as a variable resistor between Vusb and Vbat. There is no way for the FET to "disconnect" the battery from supplying the load. This is achieved automatically by virtue of the Vusb being higher than Vbat. No matter which way you point the FET, the load will always be supplied by USB when available... AND he doesn't see why this circuit is completely stupid, useless, (or dangerous) in this context, no matter which way you point it. Without the need to balance two 5V rails while using a charging IC with dual supply inputs, it looks to be about as useful as a box of rocks.***Ok, on second thought, I change my mind. Here is my explanation for this. What if perhaps the chip runs off of both the external charger AND USB rail. But they must be fed into the chip separately, to avoid any voltage drop from rectification. So whichever rail is higher is going to be tapped harder. But the higher rail will sag, and once the rails sag to match, they will match on the input end of things. Hence, the chip would ordinarily draw about 50/50 from either source, under high load condition. Now I suppose if the charger is the lower impedance output source, this means that even though the rails match, the charger is supplying most of the current to the combined rail. The more that is tapped on the back end, most of that backend current is coming off the charger. (Inputs are isolated, so same voltage = 50/50. Backend is combined, so lower impedance source delivers more current there) So this means less current that the USB rail (and charger) will deliver to the chip input side. So yeah, this actually works! For a dual supply charging IC where the charger gives more current output than the USB rail, this will reduce the load on the USB rail.This has nothing to do with charging a li ion battery and running off USB at the same time with a single supply chip. This has nothing to do with reducing available charging current when load is too high. It doesn't limit charging current. It can't. It only reduces the portion supplied by the USB line IF there is also an external charger to draw from. And only if the chip has two isolated supply pins. And only if the external charger has a lower output impedance than the USB rail.

author: JoeN
author_rank: Frequent Contributor
timestamp: November 13, 2015, 03:25:21 am
content: Quote from: KL27x on November 13, 2015, 01:48:36 amThere are two different ICs. Microchip based their circuit on the more complex one that is "dual source" (MCP73837) - low voltage AC or 5V USB. The article suggested by sq5rix adapts this for the simpler chip (MCP73831) that is 5V USB only and is the IC I actualy have in my lab, so that is the one I want to use. But in principle the ICs work the same way, just fewer bells and whistles.

author: KL27x
author_rank: Super Contributor
timestamp: November 13, 2015, 03:29:06 am
content: I highly addended my previous post. I figured out the circuit and why it's not what you, nor the author of that webpage, think it is. I suggest you skim it. I got the orientation of the FET wrong. Twice.QuoteIn case you don't understand it, the simplified version is that it only "works" on the "more complex one," and it doesn't do what you think it does. The author of that page woke up on the wrong side of the bed and/or is sniffing bus fumes. This why nothing on that page makes any sense. It's just vague technical speak, loosely copied from the misunderstood app note, leaving a bunch of dots that don't connect.The circuit can't do anything useful on a single supply, USB powered charging IC, beyond what two diodes would do better. In fact, after finally figuring out the orientation, the Vbat suffers from the voltage drop of the reverse diode junction in the FET AND the shottky, before it gets to Vcc. Crap!And if you still think it does anything, please note the correct orientation of the FET. The drain is on Vbat. The source is on Vusb. The gate is on Vcc. The FET is only there to leak current from Vusb to Vbat (and to allow Vbat to supply Vcc through two diode drops). Doing it the wrong way will fry your battery.All that said, I'm sure there are 100 people who are copying this circuit as we speak, and who will be 100% satisfied with the most excellent results.

author: KL27x
author_rank: Super Contributor
timestamp: November 13, 2015, 06:00:13 am
content: QuoteSo.... app note, load sharing is describing Vusb vs VAC.This guy is trying to solve the problem of supplying Vcc with the battery charger output. This is a problem that nobody has. Why on earth would anyone do that?QuoteObviously he has the FET oriented incorrectly in his head.QuoteNo, there is indeed nothing stopping Vbat from going back through the FET to the IC input in this circuit. Again, FET-dyslexia.But FET dyslexia aside, what would the circuit actually be doing, if it WAS placed how he thinks? As I hope you can see, the entire circuit would be doing essentially nothing that one diode wouldn't do better, or two diodes safer, and it would fry the battery.

author: Svuppe
author_rank: Regular Contributor
timestamp: November 13, 2015, 07:35:13 am
content: I'm terribly sorry, but I don't see any problems with that p-channel fet or its orientation, and I expect the circuit behaves exactly as described.

author: KL27x
author_rank: Super Contributor
timestamp: November 13, 2015, 10:00:23 am
content: Ok, I read further down the app notes. And you are correct. Your apology is accepted.Yeah, I am wrong all the way around. Drain on Vbat, Source on Vcc, right? Thanks for giving me more rope to hang on instead of just whacking me over the head with an explanation.The webpage explanation didn't help, at all.QuoteI finally get it. The load will use power from USB, because the USB rail is a higher voltage than Vbat. The FET switches off when USB is plugged in to prevent current from flowing from Vcc to Vbat, not to prevent Vbat from supplying the load. With the FET off, the body diode prevents this reverse flow. It switches on when the USB is unplugged in order to bypass the body diode, reducing the loss from FVD to next to nothing. This doesn't seem to match the explanation on the webpage.I'm go crawl under a rock for awhile. See you guys again, after I open a new account.

author: Svuppe
author_rank: Regular Contributor
timestamp: November 13, 2015, 12:15:20 pm
content: Quote from: KL27x on November 13, 2015, 10:00:23 amI wanted to give a proper explanation, but I am currently on my phone and that isn't the best for typing lengthy arguments.However I agree with you that the text about what the turned off fet did, didn't help the understanding.

author: KL27x
author_rank: Super Contributor
timestamp: November 13, 2015, 01:12:50 pm
content: No, really thank you. Sincerely.Between the 20 different ways to draw a FET symbol and the webpage explanation, I would have never caught on. Your post was so ... benign. I knew I had to go back and figure out what you knew.Spent 10 minutes looking up FET symbols. Ok, got it right. Worked my way through the circuit. And the only difference between using the FET and a schottky was.... about 0.3V of drop?I have never used a FET in reverse. So I spent another 2 minutes probing a PFET. Used the diode check to turn the gate on/off and to test the drain-source and source-drain. Body diode drop gone. I think my jaw hit the floor. I don't even know how I could not know... I mean I have read AoE cover to cover, and I understand most of it.Ok, back to my rock. This is so amazing. I have some pcb's to upgrade.

author: Zak
author_rank: Newbie
timestamp: November 13, 2015, 03:17:08 pm
content: Hah, glad you get how it works now KL27xI had a hard time trying to figure out how it worked in Microchips app note, pretty sure I've got FET-dyslexia too.I shall have to read through your walls of text to see what areas in the article need to be changed to make it easier to understand.Though there is a slight issue with the current design, when disconnecting USB power Q1 takes a while to turn on as C1 slowly discharges through R2, so you end up with a diode drop through Q1 for a few 10s of milliseconds. I would think it can be fixed with a comparator.

author: KL27x
author_rank: Super Contributor
timestamp: November 13, 2015, 08:07:44 pm
content: QuoteAhem, hi. Small world. Cough.Really not necessary for you to read my previous posts. The part that threw me off is what I quoted on this page, and I am hoping the rest of my posts will be erased in a server accident.I'm sorry, Zak, in advance.Anyhow, I suppose this could be a matter of semantics. You obviously know how this circuit works, because after the light bulb came on, I scanned the message board on your page to see if anyone else had the same problem as I. There were a couple, but your posts clearly demonstrate you know what is happening. In my world (of AoE home learning and making a fool of myself on the internet), Q1 turns off to prevent current from flowing from Vcc rail to the battery. I suppose if you are following the actual flow of electrons rather than the (American? Universal?) standard of describing current/flow from from positive to negative, then your explanation is perfectly peachy. It turns off to prevent the flow of electrons from the battery to the load (rail)?And also maybe include the little gem, that the whole point of the circuit is to bypass the voltage drop from the rectifier diode. I found this in your comments, but it would have helped me out 1000% to have that in the webpage explanation text.QuoteI think it's perfect as it is. I have a whole lot of applications where even 2-3 seconds wouldn't make any difference on the turn on time. As long as the FET turns off fast enough to not damage the battery and/or to burn itself, the turn on time is just gravy. A few tenths of a volt of drop is what I have been suffering ALL the time.Further scanning the app notes, I learned that this circuit is so awesome, some PFETS are manufactured with a shottky diode between gate and source added to the die. So one franken-FET could replace two diodes (or one dual type C). I tried to do a Mouser search, but I can't seem to find out how to source these guys. I hope they make these in a SOT 23.

author: JoeN
author_rank: Frequent Contributor
timestamp: November 14, 2015, 03:41:04 am
content: For what it is worth, I built the circuit. It's using a 100mAh battery and I would think the load is probably only about 30-40mA so it will take a little while to test. MOSFET is PMN48XP,115 and diode isPMEG6010ER,115. Red LED is status and two green LEDs are the load.

author: Zak
author_rank: Newbie
timestamp: November 14, 2015, 09:45:09 pm
content: Heh alrightI always use 'conventional current', from positive to negative. Actual electron flow is more physics/sciencey stuff. "It turns off to prevent the flow of electrons from the battery to the load (rail)?" mmm that sounds about right.Quote from: KL27x on November 13, 2015, 08:07:44 pmI've not come across a MOSFET with a schottky between the gate and source, only with zeners for ESD protection. There are some MOSFETs that come with a separate schottky in the same package likethis one, but they seem to be few and far between. I think an N or P channel with its gate and source tied together so it's always off might work, that would allow you to use it as a normal diode. There are a lot more dual P+P and P+N MOSFETs to choose from.Also checkout "ideal diode".

author: KL27x
author_rank: Super Contributor
timestamp: November 15, 2015, 06:55:10 am
content: QuoteI may be mistaken.Reason I thought this is because I searched for PFET + shottky, and I found a mosfet symbol with an extra diode between gate and source. It might have been a piece of a schematic rather than a symbol... or I might have have another case of dyslexia. I can't find it anymore.QuoteI'm confused, now. If you're on the same page with conventional current, then I think your page needs to be updated?Q1 can't stop flow of current from battery to load. The internal body diode is always available to that path.In all your responses and even your post, here, you know this.QuoteAs you just stated, even with the FET off, current flows from battery to load with only the penalty of the diode drop.What stops Vbat from powering the load is the presence of Vusb at a higher potential. This has nothing to do with the FET being on or off.The FET must turn off to prevent Vusb from having a path to Vbat, and this destroying the battery.Saying that Q1 switches off to prevent the battery from powering the load is so wrong, the only way it could possibly do that is if it were oriented with the source on the battery and the drain on the load. This is why some of the question/confusion exists in the comments on your page.One of the comments suggests you replace the FET with a diode. And maybe that would be another step you could add on your page to show how the FET works.If you replace the FET with a diode (simply erase the gate connection and the pulldown), the circuit works exactly the same as before, except you suffer the FVD of the diode on Vbat.If you want to have the ability to actually switch Vbat from supplying the load, when the USB is disconnected, you could, say, add ANOTHER FET and end up with essentially an SSR.