What I am working with: I am running my self-made Arduino board (in the sense that I use the Arduino bootloader and code editor) at 3.3V, and powered from a Lithium ion battery, which is USB-charged by a corresponding Microchip charger IC.

What I am trying to achieve: I want to measure battery capacity once every minute or so. I have an LCD attached, so the idea is that the overall setup lets me know how the battery is doing at a given moment. The datasheet of the battery has a voltage versus discharge-level curve, and so by measuring the voltage of the battery, I can estimate the remaining capacity (very roughly but enough for me!).

What I did:

  • (EDIT: Resistor values updated and P-MOSFET switch added based on @stevenvh and @Jonny's suggestions).

  • I connected a voltage divider from the battery V_plus, with the larger "portion" going to an analog-read-pin (i.e., ADC) on the Arduino/Atmega chip.

  • The divider is 33 KOhm-to-10 KOhm, thus allowing measurement up to 4.1 Volts maximum of the Li-ion battery from my 3.3V level microcontroller.

  • Also, using one of the I/O pins connected to an n-channel MOSFET, I can switch the current through the divider only when I need the measurement.

  • Here is a rough schematic (updated for a 2nd time based on suggestions of @stevenvh and @Nick):

enter image description here

My question:

  • How is my current setup?

  • My only constraints are: (1) I would like to make a rough measurement of the battery capacity based on the voltage reading, as described above. (2) I would like to prevent the voltage divider from interfering with my charging IC's reading of battery presence (in my original setup, the divider sometimes caused the IC to misread presence even when the battery was absent).

  • 1
    \$\begingroup\$ "I used large resistor values". The input pin may have a leakage current, a typical worst case value is 1 uA. With low current through the divider this may distort the reading. \$\endgroup\$ – stevenvh Sep 3 '12 at 16:02
  • \$\begingroup\$ So I want low current through the divider but high enough that it's at least an order of magnitude above the maximum leakage current. \$\endgroup\$ – boardbite Sep 3 '12 at 16:09
  • \$\begingroup\$ Or use a FET to switch on and off the divider, like I suggested in this answer to a similar question. \$\endgroup\$ – stevenvh Sep 3 '12 at 16:14
  • \$\begingroup\$ With the FET in place, in the off "state" of the divider, do you think this might also solve the problem of the charger IC's mis-reading of battery presence? (BTW, what a coincidence that that person posted the question today as well!) \$\endgroup\$ – boardbite Sep 3 '12 at 16:21
  • 1
    \$\begingroup\$ You've got the wrong FET on the wrong side. If you switch this one off the full voltage will be on the input pin, since R1 won't draw current. You need a P-MOSFET on the high side, so that switching it off pulls the I/O pin to ground. \$\endgroup\$ – stevenvh Sep 3 '12 at 17:29

enter image description here

This seems to be very similar to Nick's schematic, was probably busy drawing it when he posted :-).

First why you can't use the N-FET on the high side: it needs a gate voltage a few volts higher than the source, and the 4.2 V is all you have, nothing higher, so that won't work.

I have a higher value for the pull-up, though a value of 100 kΩ also will do. 10 kΩ will cause an unnecessary extra current of 400 µA when you're measuring. Not the end of the world, but it's 1 resistor in both cases, so why not use a higher value.

For the MOSFETs, there are a variety of parts to choose from given the requirements are not so strict; you can consider inexpensive ones such as, e.g., Si2303 for the P-channel and BSS138 for the N-channel.

| improve this answer | |
  • \$\begingroup\$ Thanks for the formal answer! I think I could think of several uses for this particular combination. I've updated my schematic in the Question, based on this. And appreciate the explanation of the N-FET. \$\endgroup\$ – boardbite Sep 4 '12 at 9:09
  • \$\begingroup\$ What would you recommend as an example of a fitting N-Channel MOSFET (ideally SMD type) to use here? IRF530 appears to be large and not too cheap either. (For the P-Channel, I see the Si2303 comes in SMD, so that one is already taken care of.) \$\endgroup\$ – boardbite Sep 5 '12 at 13:32
  • 1
    \$\begingroup\$ @Inga - You don't need current, so the on-resistance is not that important. Just look at the gate's threshold voltage: it should be on at 3.3 V, but even then it doesn't have to sink any current, and then there's plenty of choice. The BSS138 is one of the cheapest I could find, and will do nicely. \$\endgroup\$ – stevenvh Sep 5 '12 at 13:45

@Inga. This is more of a comment than an answer. But I’d like to post a picture, so I’m posting it as an answer.

Your microcontroller (uC) is powered with +3.3V. Drain of the proposed P-MOSFET can be as high as +4.1V. As it's currently drawn, a +3.3V logic signal will not be able to turn off the P-MOSFET fully. Q6 in the schematic below forms an open drain output, which is tolerant to +4.1V.

C14 lowers the impedance, which your A/D will see.

enter image description here

[...] battery voltage (thus remaining capacity)

You might find that sensing battery voltage is not an accurate way of sensing the remaining capacity. In portable equipment(cell phones, laptops), battery capacity is estimated by measuring current in and out of the battery. There are dozens of specialized battery fuel gauge ICs (bq27200, for example), which help with this task.

Why not a single N-channel MOSFET on the low side and the two resistor divider on the upper side?
[from a comment below]

A low-side switch has problems when the battery voltage (Vbat) is greater than the microcontroller's supply voltage (Vcc). When the low side switch is off, the ground end of the voltage divider floats, the divider no longer divides, the full battery voltage appears on the microcontroller's ADC pin. This can damage the uC. It will also create a leakage path through which the battery would discharge.
A high-side switch is called for when Vbat > Vcc.

1 I'll use Vcc for short, but this discussion applies to Vdd, AVcc, AVdd as well. If in doubt, look-up in a datasheet, of course.

| improve this answer | |
  • \$\begingroup\$ Thanks Nick! That makes sense, and I've updated the schematic (The fuel gauge is an option, but I am also trying to learn some basic electronics and experimenting, hence the voltage divider idea) \$\endgroup\$ – boardbite Sep 4 '12 at 9:05
  • \$\begingroup\$ Why not a single N Mosfet on the low side and the two resistor divider on the upper side? Can't see why is necessary to use a N Mosfet to drive the P Mosfet \$\endgroup\$ – Luis Carlos Jun 17 '18 at 0:19
  • 1
    \$\begingroup\$ @Luis I've edited the answer and added the response to your comment. \$\endgroup\$ – Nick Alexeev Jun 17 '18 at 1:13

Ad.A: I think it's fair enough to use a simple voltage divider to detect the battery voltage. Although, you should carefully choose the resistance. The internal impedance of your ADC inputs is 100kΩ, according to the ATmega328 datasheet. See "Figure 23-8. Analog Input Circuitry". If your divider has a comparable impedance to the ADC input, the ADC input circuitry will basically behave like another node in the divider. It might give you offsets in ADC readings.

Using a divider with up to 10kΩ across the rails would be low enough to ignore the ADC input impedance, while using up only 410µA. If that's too much for your application, you can of course pick larger resistances, but keep in mind that the ADC is there and is connected to Vcc/2.

| improve this answer | |
  • \$\begingroup\$ That explanation makes sense. For sure 0.4 mA is not that much! I was just trying to be as idealistic as possible :) Do you have any guesses on why having this divider there might be affecting my charger IC's reading of whether there is a battery? \$\endgroup\$ – boardbite Sep 3 '12 at 16:18
  • \$\begingroup\$ My guess would be that there is still a connection between the positive battery pin where the divider is, and the +5V from the usb. I don't know your particular circuit, but I'm sure that you can deduce what goes where if you take a look at the Arduino schematic. \$\endgroup\$ – Christoph B Sep 3 '12 at 16:26
  • \$\begingroup\$ I'm sure that if you follow stephenh's idea of using a FET to connect/disconnect the divider when necessary, everything will be hunky dory. MOSFETs have resistances that are completely negligible for your divider. You'd perhaps need another ADC to monitor whether the USB is attached or not. \$\endgroup\$ – Christoph B Sep 3 '12 at 16:29
  • \$\begingroup\$ Thank you; I've updated the question based on two of the suggestions, and added a schematic. As far as the USB-supply-monitoring, the charging IC already has a status output for this too! \$\endgroup\$ – boardbite Sep 3 '12 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.