LiPo charging circuit advice

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
pneumatic
 
Posts: 186
Joined: Sun Jul 26, 2009 3:59 pm

LiPo charging circuit advice

Post by pneumatic »

I'm planning on making a raspberry pi wearable including a small screen that requires 6-15v to power it. Since a single LiPoly cell won't produce enough voltage for either the Pi or the dipslay, I'm going to go with 2 in series, but have a circuit (schematic below) to allow me to run the device and charge the batteries at the same time, based on this circuit.

Here's the schematic:
charger.png
charger.png (18.66 KiB) Viewed 647 times
V+5 is for the Pi, and Vcc is for the display. The basic premise is the same, but I'm using two UBECs (represented by 7805s in this schematic because I didn't have a component for it). One to regulate either the batteries or the external power down to 5V for the pi, and one to regulate the 12V down to 5V for the LiPo chargers. There are two diodes... D1 to prevent the batteries from powering the charger while it's not plugged in, and D2 to prevent the external power source from flowing back into the batteries before I flip the switch to charge mode.

The question is, what kind of diodes should I use? I was thinking just a standard 1N4001, but the forward voltage drop on that is 1V, and while that's okay for D1, it's a lot to lose for D2. Can anybody recommend diode that can handle 1-2A forward current with a lower drop?

Thanks in advance,
-- Mitch

User avatar
pneumatic
 
Posts: 186
Joined: Sun Jul 26, 2009 3:59 pm

Re: LiPo charging circuit advice

Post by pneumatic »

Doing a little research it seems the schottky diodes typically have lower Vf, but most of the ones I can find seem to only be able to handle 1A continuous, and I'm expecting to draw 1.5A to 2A. Can I put 2 or 3 in parallel and just increase the current capacity that way? (I know that doesn't work well with some transistors, but am unsure about diodes.)

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: LiPo charging circuit advice

Post by adafruit_support_mike »

I'd suggest using a couple of P-mosfets and a supply-protection circuit stolen from the Arduino:
charge.jpg
charge.jpg (22.29 KiB) Viewed 615 times
It looks like a mess, but the pieces aren't too bad.

For starters, ignore everything on the left, assume the 12v supply is disconnected but the 7v supply is connected. The resistors to GND will pull the P-mosfet's gate low and allow power to flow from the 7v supply to U1, which then passes power on to the RasPi.

Still ignoring the left side, assume we connect the 12v supply. That will pull the P-mosfet's gate higher than the 7v line, shutting that off. Power will then flow from the 12v supply to U1. Assume the capacitor is large enough to absorb any dip in the supply as the P-mosfet shuts off.

Now moving to the left, assume the resistors in the voltage divider are equal, so the voltage at the center will be 6v. The comparator/op-amp is hooked up so its output will be HIGH if the 7v input is higher than the voltage divider input. That will shut off the second P-mosfet and keep U2 (which supplies charger power) disconnected. It doesn't matter whether the 12v supply is connected or not, if the 7v input is connected, U2 remains isolated.

If the 12v supply is connected and the 7v supply is disconnected, the comparator/op-amp's output will drop LOW. That opens the P-mosfet and allows power to flow from the 12v supply to U2.

You do lose some current through the voltage divider as long as the 12v supply is connected, but the resistors can be huge.. 100k to 1M each would be fine. They only have two purposes: create a path to GND so the 7v->U1 mosfet can open when the 12v supply is disconnected, and create a reference voltage for the comparator/op-amp.

I didn't draw the comparator/op-amp's power connections, but you'd want to take its Vcc from the point where U1 and the capacitor meet. That way its output voltage will match the voltage at the 12v->U2 mosfet's right side, whether that voltage is 7v or 12v.

(EDIT: looking back over the circuit, I forgot to draw a resistor from the 7v input to GND. You need that to pull the op-amp input low when the 7v supply is disconnected. It can also be 100k-1M)

User avatar
pneumatic
 
Posts: 186
Joined: Sun Jul 26, 2009 3:59 pm

Re: LiPo charging circuit advice

Post by pneumatic »

Wow, that's a lot more than I asked for, but it's great information. Thanks!

For the comparator/op-amp should I use the TS922 from your site?

User avatar
pneumatic
 
Posts: 186
Joined: Sun Jul 26, 2009 3:59 pm

Re: LiPo charging circuit advice

Post by pneumatic »

I'm also assuming that I want something moderately large for the cap, like 1uF or so? Electrolytic?

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: LiPo charging circuit advice

Post by adafruit_support_mike »

Pneumatic wrote:Wow, that's a lot more than I asked for
Nerd-sniping.. pure and simple (http://xkcd.com/356/). ;-)
Pneumatic wrote:For the comparator/op-amp should I use the TS922 from your site?
Having slept on it, I thought of something better.. an N-mosfet:
charge2.jpg
charge2.jpg (25.73 KiB) Viewed 593 times
Using a comparator/op-amp was overkill because the circuit doesn't care about the conditions where one voltage is within a few millivolts of the other. We're talking about large differences, so we can use simpler/rougher tools.

Everything from the voltage divider right is the same as described above. The 2M resistance to GND controls P1's gate, letting power flow from the 7v supply to U1 if the 12v supply isn't there, and disconnecting the 7v supply when the 12v supply is present.

On the left, N1 acts as a rough comparator between the voltage at the center of the 1M-1M divider and the 7v supply.

- If both supplies are connected, N1's gate voltage will be 6v and its source voltage will be 7v. That will shut N1 off.

- If the 7v supply is connected but the 12v supply isn't, N1's gate voltage will be at GND. Again, N1 will be shut off.

- If the 12v supply is connected and the 7v supply isn't, N1's gate voltage will be 6v and its source will be connected to GND through the 100k resistor. That will turn N1 on.

- If N1 is off, P1's gate is basically shorted to its source by the 1M resistor. Regardless of the voltage on the 7v/12 line, P2 will remain off.

- When N1 is on, its channel resistance will be very low.. a few ohms at most. That basically shorts the 1M and 100k resistors together, pulling P2's gate voltage about 11v lower than its source. That will turn P2 on hard. With a power mosfet, that much difference between gate and source will reduce P2's channel resistance to a few milliohms.

N1 can be a small-signal mosfet like the n27000. You could even replace it with an NPN transistor if you wanted to.

I set the value of the smoothing capacitor at 100uF, which should hit a balance between good smoothing and small size. An electrolytic would be fine, though you'll probably need to test things to see how much current the RasPi draws during a supply changeover, and what (if any) ripple makes it through the Ubec.

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: LiPo charging circuit advice

Post by adafruit_support_mike »

UPDATE: I just noticed a problem: I had P1's drain shorted to its gate. The 2M resistance doesn't connect P1's gate to GND once P1 opens, so my reasoning there was flawed.

I'll have to think a bit to find a solution to that..

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: LiPo charging circuit advice

Post by adafruit_support_mike »

Okay.. got it. It needed another rough comparator:
charge3.jpg
charge3.jpg (26.18 KiB) Viewed 584 times
To work through the reasoning, the basic power control module looks like this:
control-1.jpg
control-1.jpg (13.81 KiB) Viewed 584 times
If V1 is higher than V2, the comparator turns the P-mosfet on and the output voltage equals V1. Replacing the comparator with a mosfet looks like this:
control-2.jpg
control-2.jpg (12.26 KiB) Viewed 584 times
It does roughly the same thing, but now there's a DC offset between V1 and V2.

The basic rule for mosfets is that when the voltage between gate and source rises above a certain level (called Vth), the channel becomes conductive. The more Vgs exceeds Vth, the more conductive the channel becomes. For the circuit above, both the P-mosfet and N-mosfet are controlled by the difference between V1 and V2, so the circuit will work best when V1-V2 is significantly higher than Vth for both mosfets.

I drew the resistor above the N-mosfet connected to a general 'high' voltage because it doesn't specifically need to be connected to either V1 or V2. It just needs to be high enough to keep the P-mosfet shut off when the N-mosfet is closed.

Taking those ideas back to the circuit above, it's easier to see the 'comparator' connections.

N1 compares the 7v supply connection to a 6v reference voltage derived from the 12v rail. The 1M-1M voltage divider pulls the 12v input line to GND when the 12v supply isn't connected, so in that condition N1 will be shut off no matter what's happening on the 7v rail. If both the 12v and 7v supplies are connected, N1 compares the 7v input to a 6v reference voltage. That still keeps N1 shut off, so P2 also remains shut off. If the 12v supply is connected and the 7v supply isn't, N1 comes on, putting N1's 1M drain resistor in series with the 100k source resistor. That pulls the gate of P2 about 11v lower than its source, which connects the 12v supply to U2.

N2 compares the 12v input to GND. If the 12v supply isn't connected, N2 will be shut off, and so will P3. Shutting off P3 is important because we want to keep P1 from pulling its own gate high when it turns on (the problem in the previous versions). I connected the N2's drain resistor to the input of U1, because that node carries the highest voltage connected to the circuit at any given moment.

With N2/P3 isolating P1's drain from its gate, P1 turns on when the 7v supply is connected but the 12v supply isn't, and shuts off when the 12v supply is connected.. what I wanted before but didn't guarantee.

I took the time to do a proper circuit analysis this time, and think I found most of the gotchas. There will be some minor misbehavior during the rising and falling edges when you connect/disconnect one of the power supplies becase there's a range of voltages where both P1 and P3 are open at the same time. That would be a problem if you planned to keep both supply voltages in that range for a long time, but in practice the circuit should blast through that range in a few microseconds. The 100uF cap should be able to absorb any spikes caused along the way.

User avatar
pneumatic
 
Posts: 186
Joined: Sun Jul 26, 2009 3:59 pm

Re: LiPo charging circuit advice

Post by pneumatic »

Wow, I almost think I understand it.

I've done my best to replicate your work in my schematic:
mosfet-schem-v3.png
mosfet-schem-v3.png (34.77 KiB) Viewed 574 times
I want to make sure I've got my source and drain right on all the mosfets.

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: LiPo charging circuit advice

Post by adafruit_support_mike »

Looks good.

You want the source of each P-mosfet connected to the 7v/12v inputs. The N-mosfets want to have their source connected to GND. It looks to me like you've done that.

User avatar
pneumatic
 
Posts: 186
Joined: Sun Jul 26, 2009 3:59 pm

Re: LiPo charging circuit advice

Post by pneumatic »

Just to follow up. I think I've got it laid out on a half-size breadboard in Fritzing. A few parts are missing (like the UBEC for the chargers) or substituted (like the ubec for the Pi). I also included a ADC for the Pi to monitor the battery voltages, and let me know when they're getting low. I can connect the Pi through a plate, but I don't have room on a half-size for the cobbler. I also won't actually connect the power through the GPIO, because there have been reports that doing so can't provide much current to the USB ports because the traces on the board are too thin, and I need to power a wifi dongle.
fritzing_breadboard.png
fritzing_breadboard.png (111.36 KiB) Viewed 546 times

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: LiPo charging circuit advice

Post by adafruit_support_mike »

Looking good.

FWIW, the N-mosfets carry much less current than the P-mosfets, so you can get away with using a small-signal device like the 2n7000: http://www.mouser.com/ProductDetail/Fai ... zocIwUs%3d

It wouldn't make any difference functionally, but the 2n7000 comes in a TO-92 package that's smaller than a power mosfet's TO-220.

User avatar
pneumatic
 
Posts: 186
Joined: Sun Jul 26, 2009 3:59 pm

Re: LiPo charging circuit advice

Post by pneumatic »

Hi Mike,

Hmm... well I finally got around to wiring this up, but it's not working the way I expected.

The batteries by themselves are 7.6V. If only the batteries are hooked up, then I get 7.0V out on Vcc (which is lower than I would expect. I don't know what's causing the 0.6V drop), and with only the +12V hooked up I get 12.3V on Vcc, which is pretty much as I expected.

What's not working is that when I have both hooked up, I get 5A current flowing back into the batteries, which is okay for the 5 seconds I had it hooked up (they're 6600mAh batteries, so it was less than 1C), but will fry them if I leave it hooked up.

So, is P1 not shutting off, or does it only prevent current flowing one way? How do I debug this without blowing up my LiPos? (I guess I could put a 1Kohm resistor in series with the 12V for debugging.. that will limit the current to a few mA, which the LiPos should be able to handle).

Thanks for your help,

-- Mitch

User avatar
pneumatic
 
Posts: 186
Joined: Sun Jul 26, 2009 3:59 pm

Re: LiPo charging circuit advice

Post by pneumatic »

So I did a little poking around with only the 12V hooked up, and Vds on P1 is less than 0.5V.

My guess as to the problem is that if both P1 and P3 are "on", then there is a path from +12 to that 100K resistor, which means that Vgs is effectively 0, which means that P1 stays "on".

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: LiPo charging circuit advice

Post by adafruit_support_mike »

Hmm.. double-check the part number on P1 to make sure you didn't accidentally get an N-mosfet in that position.

A P-mosfet shouldn't turn on unless the voltage at its gate is below the voltage at its source. The 12v supply should be the highest voltage in the system, so it shouldn't be possible for that to happen.

If checking confirms that you do have a P-mosfet in that position, what voltages do you get for drain, source, and gate?

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”