Voltage dividers for microcontroller batt. monitors - Page 1
Forum section: electronics / beginners

author: TreefrogX
author_rank: Newbie
timestamp: October 09, 2017, 11:06:26 pm
content: Hi Folks,This is my first post here, so a brief introduction: I'm well in to my thirties, had a career as a PHP code monkey, and now find myself far more interested in low level activity. It started with arduino, then the ESP8266, then I found EEVblog and videos that I didn't understand but found oddly compelling so persisted to watch anyway, and now I just can't shake the habit. My name is TreefrogX, and I'm an electron dependent.My conundrum on voltage dividers:I have no background in electronics so I'm struggling with the basics. I need to monitor voltage from a 3.7v li-ion bank with a 3.3v ADC (ESP8266 analog input). Taking into account the 4.2v charge voltage, I reckoned a 5v maximum expected voltage would suffice. Divide 5v to 3.3 and convert back in software. Easy. The problem is, I don't know how to divide it on a hardware level. If I go too low on ohms I'm creating a near dead short across my battery. I could solve this with high power resistors, or high value ones (I think?) but how do I find the optimum values? Dumping amps through a 5w resistor probably isn't the best use of my battery, but I can't go too high on the resistance value or there won't be enough current to drive the ADC input, or will there? When? How? What? Ahhh, help!

author: sokoloff
author_rank: Super Contributor
timestamp: October 09, 2017, 11:18:13 pm
content: Use a high value resistor divider. The A/DC works on voltage, not current (to a very strong first-order approximation).Most of all, though, try it on the bench and teach yourself what works. I'd start in the 100s of Kohm to 1 Megaohm range and see what you get from that. Do a power loss calculation from the resistor bridge (E*E/R).

author: ahbushnell
author_rank: Frequent Contributor
timestamp: October 10, 2017, 12:03:43 am
content: I suggest a little Math.Vmax=5voltVin=3.3 voltsR2 connects to Bat and input to micro. R1 connects to input to micro and common.Vin/Vmax=R1/(R1+R2)=kk is the gain which you will need for calibration in your software.Set R2 to 1Megohm=1E6then algrebra gives youR2=1.941Mohms.Can you buy a 1.941 Mohm resistor? Go to digikey and look up the standard resistor values. I suggest a 1% resistor. Digikey has a nice search tool. There is 1.91Mohm. This gives a gain of 0.656. So 5*0.565=3.28 volts.Note a higher resistance has less drain on the battery but if you go too high there could be noise pickup depending on how careful you are with wiring and how long of wires you run. With 1 Mohm that's 1.7 microamps drain. That's low. So you could use maybe 100kohms (100e3) for R2.Andyhttps://www.digikey.com/products/en/resistors/through-hole-resistors/53

author: 0xdeadbeef
author_rank: Super Contributor
timestamp: October 10, 2017, 12:17:29 am
content: I would be careful to recommend very high ohmic serial resistors into an analog input. There is some some current needed to flow into the sample&hold stage each time the multiplexer switches to a new channel. A resistance too high might impact the result in several ways. Firstly, extremely high resistance might now allow to fully charge the capacitor in the sample&hold stage for higher sample frequencies. Secondly, there is a frequency dependency of the voltage drop and it's more visible the higher the serial resistance (i.e. for each conversion cycle, there is current flowing into the input capacitor. The higher the conversion frequency, the more current flows per second and the higher is the average voltage drop per second).Usually, something in the 20k-50k range is a sensible value for the serial resistance. Going much higher should be only done if accuracy isn't important or if all details of the input stage are fully understood.

author: Mr.B
author_rank: Unknown
timestamp: October 10, 2017, 12:30:15 am
content: Welcome to the forum.Quote from: TreefrogX on October 09, 2017, 11:06:26 pmPlease double check your understanding of the ESP8266 ADC.IIRC it is 10 bit (1024) and has a maximum input voltage of 1.06vdc.Nominal range is 0 to 1.024vdc.In previous designs I have used a divider of 10M0 (high side) and 3M3 (low side) with a 0u1 cap across both. (LiPo battery measuring).

author: rstofer
author_rank: Super Contributor
timestamp: October 10, 2017, 01:14:56 am
content: While you are hitting the datasheet, find out what the maximum driving impedance is for the ADC. Don't be surprised if it is down around 10k. Many uCs have such a spec. I don't know anything about your device.The ADC load is in parallel with the bottom resistor and alters the calculation wildly, particularly if you are using high value resistors. So, now you divider varies with load which varies with just about everything.It's ok to use the high value resistors, just run the result through an op amp voltage follower to bring the ADC driving impedance down to near zero.Some folks try to stabilize the divider voltage with capacitors and if their leakage isn't too high, that might work.I will refer you to Chapter 4 of "Op Amps For Everyone" (free, Google for it) because they spend an entire chapter on offset and scale. For example, why do you want to measure down to 0V or 1V or even 2V. The battery has been dead since somewhere up around 3V (I making up the numbers). So, you would really like to represent 3..5V across the entire range of the ADC and you can do this with the same op amp and 4 resistors.We just had a voltage divider thread last week but I can't find it. Here is a similar thread:https://www.eevblog.com/forum/microcontrollers/reading-5v-adc-signal-from-3-3v-mcu/msg1164690/#msg1164690Check you op amp datasheet for maximum + and - outputs and design to stay within these voltages. JFET input rail-to-rail input-output is what you want to find.

author: Mr.B
author_rank: Unknown
timestamp: October 10, 2017, 01:49:02 am
content: Thanks @rstofer, that bit of information will enable me to rethink some of my current designs.Edit: Just downloaded Op Amps for Everyone... More than a little bit of light readingI will start chewing on it tonight.

author: Ian.M
author_rank: Super Contributor
timestamp: October 10, 2017, 04:12:52 am
content: There is another option when it *really* has to be low power - disconnect the divider in between readings. If you turn on the divider and any buffer amp for 60ms once a minute, you can reduce its drain on the battery by a factor of 1000. Also, for applications with soft power switches, you can virtually eliminate the extra power-down consumption of the battery monitor circuit, preventing excessive battery discharge in storage.One way to do this is to use an OPAMP with chip select e.g.MCP6043. Pull /CS high and it turns off, with its output hi-Z.If you power it from the LiPO cell you are monitoring, and connect both the lower end of the input divider and the /CS pin to 0V via a logic level small signal N-channel MOSFET (e.g. BSS123), you can switch it off *AND* disconnect the divider under MCU control. Add a pulldown on the gate and its also going to be off when the MCU is powered down.However if you are careless about the feedback its output could spike to its supply rail during turn-on, so you may need a series resistor between its output and the ADC, and possibly clamping and/or a capacitor to 0V at the ADC pin to provide low pass filtering and to keep the pin voltage from rising excessively during turn-on.A safer way to disconnect the divider is to put a P-channel MOSFET at the top end, with a pullup on its gate and pull the gate down with a logic level N-channel MOSFET driven by the MCU. That lets you run a micropower buffer OPAMP (if required) from the MCU's supply rail as its input wont be above the rail when the divider is disconnected, and also its output cant drive outside the rails so ADC input protection probably wont be needed.