voltage divider doesn't add up - Page 1
Forum section: electronics / beginners

author: mclien
author_rank: Contributor
timestamp: November 17, 2024, 08:35:17 pm
content: I started with the idea to measure the voltage of a LiPly battery powering a board (Adafruit Trinket M0), to have some poor mans battery gauge.As I couldn't get the reading of the voltage inside the adruino sketch, I reduced the setting till I ended up with the very basic of a voltage divider.2 resistors in serial between the V+ and the gnd pin of said LiPoly battery.And her comes the strange thing: I expected to measure the exactly half the value of the Voltage of the battery on both side of the mid-point, but what I get is:1.68V to both dies and 3.7V as the complete voltage. (pic hopefully helps understanding).I thought I should get 1.85V each side with 3.7V as the complete voltage?Do I miss something?

author: John B
author_rank: Frequent Contributor
timestamp: November 17, 2024, 08:43:53 pm
content: How exactly are you measuring each voltage?Probably the method in which you are measuring each voltage happens to be loading down that part of the divider when making the measurement. As you say, the voltage across both resistors should be the sum of each individual one.

author: fourfathom
author_rank: Super Contributor
timestamp: November 17, 2024, 08:50:44 pm
content: What is the value of your resistors (in Ohms)? And how are you measuring this voltage? As John said, your measurement method will be an additional load on the points you are monitoring.

author: wraper
author_rank: Unknown
timestamp: November 17, 2024, 08:58:19 pm
content: Cheap multimeters have 1M input resistance. If divider resistors are not of low resistance, connecting multimeter will have a significant impact on resistance and thus on voltage as well.

author: wasedadoc
author_rank: Super Contributor
timestamp: November 17, 2024, 09:15:16 pm
content: Redraw your diagram to include another resistor in parallel with the one you are measuring across. The extra resistor is the resistance of your meter. Now the "mid point" does not have equal resistance to the two ends and the voltage is not half the total.

author: Analog Kid
author_rank: Super Contributor
timestamp: November 17, 2024, 09:38:32 pm
content: Is 1MΩ really low enough to load a circuit that much? Seems like a pretty high impedance to me.

author: wraper
author_rank: Unknown
timestamp: November 17, 2024, 09:49:52 pm
content: Quote from: Analog Kid on November 17, 2024, 09:38:32 pmSay you have 100k+100k divider. With 1M in parallel, you'll have 100k+91k.

author: mclien
author_rank: Contributor
timestamp: November 17, 2024, 10:03:46 pm
content: Here are the missing information:-I select the voltage range to cover the expected voltage and attach clamps on the 2 measuring point for each voltage I measure.The sort of clamps:https://www.welectron.com/media/image/product/10256/lg/hirschmann-kleps-2-bu-miniature-clamp-type-test-probe-pair-red-black.jpg- both resistors are 2MOhms-my multimeter is indeed a cheap one (10MOhm input impedance)--> which sums up to 2M and 1.67M while measuring, which indeed leads to 1.68V ad the mid-point for 3.7V overall voltage. Thanks.But I still get to low voltage values with the divider attached to the µC. regardless which divider I use:800k -- 2000k1000k -- 1000k (used the last one to exclude calculation errors in the sketch.

author: iMo
author_rank: Super Contributor
timestamp: November 17, 2024, 10:08:35 pm
content: 2Meg resistors are usually not the best choice for voltage measurement with a micro-controller.The MCU's input impedance while doing ADC is lower, thus you get a different result.Use smaller resistors (like 20k..100k) and put a 100nF capacitor at the MCU's ADC input pin (against GND)..

author: mclien
author_rank: Contributor
timestamp: November 17, 2024, 10:26:30 pm
content: Quote from: iMo on November 17, 2024, 10:08:35 pmThanks.So I was a bit naive as it seems, thinking what worked and ist recommended for the nRF52https://cdn-learn.adafruit.com/assets/assets/000/052/793/original/microcontrollers_revgsch.png?1523067417https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/measuring-lithium-battery-voltage-with-nrf52Is directly applicable to a samd21 based board like the trinket M0.I'll continue the next days.

author: iMo
author_rank: Super Contributor
timestamp: November 17, 2024, 10:42:13 pm
content: You have to look into the datasheet of the mcu you are using.Typically 10k max impedance of the source is recommended when doing ADC with max speed the mcu allows (unless the mcu has got a special ADC inside).You may use a higher source impedance (it is the parallel combination of the divider resistors) when you put a capacitor there (but you limit the sampling rate). It is because the capacitor works as a low impedance source of charge during the conversion process. It takes longer to charge it back again, therefore the sampling rate is limited then.People want to have a divider with zero current when not measuring, therefore tend to put large resistors there into the divider (not good). There is a trick with a divider with a mosfet called "zero current divider" or something like that, I had a post about it long time back.PS: here it ishttps://www.eevblog.com/forum/projects/strange-adc-behavior-at-lower-voltages-using-an-msp430/msg2837088/#msg2837088https://www.eevblog.com/forum/microcontrollers/adc-input-impedance/msg2969488/#msg2969488

author: wraper
author_rank: Unknown
timestamp: November 17, 2024, 10:52:16 pm
content: There is a trick how to use lower resistance but not drain too much power. If measured voltage is the same or lower than VDD, you can use GPIO (or external MOSFET for wider voltage range, more accuracy) as a switch on low or high side of the divider and pass current only when measurement is needed.

author: mclien
author_rank: Contributor
timestamp: November 18, 2024, 03:48:30 pm
content: Thanks for the great explanations.Naturally you were absolutely right with the assumption why the large resistors and my not reading the the specs of the µC (partly out of to little knowledge of the topic).As I understand it the suggested methods of "no current draw dividers" need an additional enable pin.At least in the current project I'm out of pins for that method, but that might be no issue anyways. Some background: the project itself is a portable watch (maybe I get it to wristwatch size with a few iterations). So I was already thinking to have a low power RTC module for time keeping and a power-latching circuit to power up the µC only when showing time (LEDs in this case). Since that will sum up to a few min power-on time per day of the µC anyways, adding a few sec for measuring and showing the battery level shouldn't change the overall power consumption that much.(Or even won't any extra time when using the color of the time display as a battery meter)I'll start my new testings with a 10k --- 10k divider

author: Doctorandus_P
author_rank: Super Contributor
timestamp: November 18, 2024, 04:47:36 pm
content: With two 10k resistors, you have a 3V6/20k = 165uA load on your battery, and that is significant. Normally quite high value (Mega Ohm) resistors are used for such dividers, and then errors are calibrated out. ADC inputs of uC's are generally mostly capacitive. You can "overwhelm" the (small) capacitance of the ADC input by adding a bigger capacitor parallel to it.An educational experiment and fun test:1. Put a capacitor between an ADC input and GND of your uC.2. Put a resistor (1Meg or so) with one end to the ADC input too.3. Write some software that samples the ADC (Always sampling the same channel) and puts the value on a display or serial monitor program.4. Touch GND with one finger, and the other 1Meg resistor end with another finger (ADC values will go to zero).5. Touch Vcc with one finger (keep the other on the resistor). ADC values will now go to the maximum.6. With this method, modify the capacitor voltage to some intermediate value, then remove your fingers. (ADC value will be nearly constant, but also drift a bit.6. Modify your uC firmware, so it samples two different ADC channels.7. Connect the other channel to either GND, or to Vcc. And then observe the difference this makes on the ADC value sampled from the capacitor.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: November 18, 2024, 04:51:58 pm
content: Also, for a battery gauge, why are you using a voltage divider?One trick sometimes used is:1. Power the uC directly from the battery.2. Use the power supply as the ADC reference voltage input.3. Measure the voltage of the (internal) ADC reference voltage.4. Calculate battery voltage from that.With this method, you have no external hardware at all.

author: mclien
author_rank: Contributor
timestamp: November 18, 2024, 05:31:10 pm
content: Did some (very simple) testing:Battery is at 3.60V (according to my multimeter)divider tests (serial output):10k --- 10k : 3.60 to 3.62V100k --- 100k: 3.60 to 3.62V220k --- 220k: 3.60 to 3.62V330k --- 330k: 3.54 to 3.56VFrom material I have at hand makes the double 220k the best Option, it seems. Load for the battery is 8uA

author: mclien
author_rank: Contributor
timestamp: November 18, 2024, 05:40:16 pm
content: Quote from: Doctorandus_P on November 18, 2024, 04:51:58 pmThe final goal is to have the device powered only by battery in general and be able to get the battery voltage. If I understand your method correctly, It depends on the powersupply as a reference.

author: Siwastaja
author_rank: Super Contributor
timestamp: November 18, 2024, 06:21:09 pm
content: MCU ADC is similar to the multimeter in that it "loads" the signal. Just that the load is a capacitance, not a resistor. Meaning, it consumes a current peak when it samples. ADC basically connects a tiny sampling capacitor into the input for a short time when triggered to do so.With 2Mohm resistors, charging the ADC sampling capacitor is slow, but the ADC sampling time is limited (maybe fixed, maybe configurable, but limited anyway), thus it does not fully charge to the real voltage, causing wrong result.If you don't have to sample all the time, but e.g. once a second suffices, then simple solution is a capacitor between the ADC input pin and GND. The ADC pulls its required charge from this capacitor and gets it quickly. Then, between the samplings, there is plenty of time to slowly charge that larger capacitor through your 2M resistors. This capacitor should be e.g. at least 1000 times bigger than the sampling capacitor. 1uF ceramic is a good idea.Now if you have to run continuous sampling you have no other options than to provide continuously low impedance for the ADC and you can do it by significantly reducing the divider values, or by buffering the divider output by an opamp circuit.But for your use case, capacitor will do fine, it's not like battery voltage changes quickly anyway. Just don't enable automagic continuous sampling from the MCU, instead trigger sampling by software or a timer.It's still a good idea to reduce the resistor values somewhat if accuracy is important. There can be leakage currents in ADC pins, the capacitor can leak a bit, surface contamination on the PCB traces, especially flux residues from soldering. These would be in the gigaohm range but still measurable effect when paralleled with 2M if you are aiming for better than 1% accuracy or so.But generally the idea of using large resistor values especially when permanently connected to the li-ion cell is good one. This way you minimize current consumption during off-state and prevent overdischarging and killing the li-ion cell even during long period of non-use (sitting on the shelf).

author: Doctorandus_P
author_rank: Super Contributor
timestamp: November 18, 2024, 06:22:19 pm
content: Quote from: mclien on November 18, 2024, 05:40:16 pmThis is a variant of a "radiometric measurement".Assume you want to measure temperature, and your sensor is a PTC with a resistor in a voltage divider configuration. In that case, the reference voltage does not matter. because you are measuring the ratio between the resistance of the PTC and the fixed resistor. Regardless of whether your reference voltage is 1V or 5V. As long as your sensor is connected to the same reference voltage as the ADC. Even when your reference changes (slow enough) such as a raw battery voltage, the only detrimental effect will be tiny bit of extra noise.Now consider using the raw battery voltage as the reference for your ADC (Assume 3V6), and you are measuring a fixed 1V. Your ADC value will then be 1/3.6 of the maximum that your ADC can measure. If your battery gets depleted to 3V2, then you will measure 1/3.2 (which is a bigger number). So by measuring a known value, you can calculate the reference voltage by inverting the calculation.It is not always possible to route the ADC reference voltage internally to an ADC channel. Sometimes you output the reference voltage to an external pin, and then you route it back to an ADC input to measure it.

author: fourfathom
author_rank: Super Contributor
timestamp: November 18, 2024, 07:07:03 pm
content: Depending on your accuracy and stability requirements you can tolerate the loading effect on a high-value resistive divider, just calibrate in software to compensate. Also (as mentioned) adding a capacitor at the divider output can greatly reduce the effects of divider resistance as the sampling takes very little time, and you typically have a long recharge interval between samples.

author: mclien
author_rank: Contributor
timestamp: November 18, 2024, 08:36:16 pm
content: Quote from: Siwastaja on November 18, 2024, 06:21:09 pmThanks for the explanations. Quite educating (I'm the copy&past guy with this topicQuoteThat is why I most likely need not concern about lower value resistors.The setup in the end will be:the LiPoly permanently connected to the RTC modul -- a power latching circuit -- the µC, which is powered only for about 5-10 sec to read the time and light up the LEDs displaying the time and battery gauge,After that the µC disconnects from power via the latching circuit. (MOSFet disconnecting the mC from battery power)Which also disconnects the divider from the battery.

author: BennoG
author_rank: Frequent Contributor
timestamp: November 18, 2024, 08:37:47 pm
content: if you want best power efficiency then use only 1 resistor and the the MCU internal resistance of the ADC as the other divider. This will not be repeatable for if you make multiple units (they will differ from one to the other) but then there is the least load on the power.Benno

author: mclien
author_rank: Contributor
timestamp: November 18, 2024, 08:52:23 pm
content: Nice minimal approach, I like that.But I have at least the hope, that the outcome of this project might lead to several devices, So i guess since the µC should be only powered the amount of time of a day you usually look at you watch, the "lower values resistors" might be the best choice

author: Siwastaja
author_rank: Super Contributor
timestamp: November 19, 2024, 07:04:11 am
content: Quote from: BennoG on November 18, 2024, 08:37:47 pmWhat do you mean by "MCU internal resistance of the ADC"? Internal pulldown resistor which would have like +100/-50% tolerance? I'm aware in some rare cases actual configurable resistors are available, e.g. in nRF52 series ADCs have those, but I doubt ATSAM21E18 has anything like that?

author: BennoG
author_rank: Frequent Contributor
timestamp: November 19, 2024, 07:20:31 am
content: Quote from: Siwastaja on November 19, 2024, 07:04:11 amI know that is why I stated that tis is not repeatable (because you probably need to tinker the resistance per installation) and only when you need absolutely minimal power consumption.

author: Siwastaja
author_rank: Super Contributor
timestamp: November 19, 2024, 11:37:03 am
content: Quote from: BennoG on November 19, 2024, 07:20:31 amI'm afraid internal pulldown is so heavily temperature-dependent that tuning for unit-to-unit variance is not enough, you would need to add temperature compensation. I don't believe this would be a viable solution, unless it's a really crude indication like "now it's closer to 4 than 2 volts".There are other better solutions involving switching off the divider: simply connecting the bottom leg to GPIO pin instead of GND leg allows easy switch-off of the divider, but when Vbat > Vcc then some current will still flow through the upper resistor, through pin protection diodes into Vcc, but at least this would contribute to Vcc (and reduce the regulator current by same amount); just need to make sure that under no circumstances (worst case minimum low sleep current) it leaks more than the MCU consumes, raising the Vcc rail.EDIT: now that I think about it, your solution will consume more current, because it forces one to select lower value upper resistor (because the lower one is fixed in design, like 50k). Thus the current from input, through your single resistor, through IO protection diode, to Vcc, would be also higher. And probably high enough preventing usage of sleep modes (or, causing the MCU to blow up, unless you add a clamp on Vcc net)

author: mclien
author_rank: Contributor
timestamp: November 20, 2024, 11:12:30 am
content: Thanks for all the background information.For my specific project with limited space and GPIOs and the fact that the MCU is only powered up for about 10 time a day for 15sec max., I think for me the simplest solution is the 2 resistor divider with the largest values that give me an accurate enough reading. (that would be 10 steps of 0.1V, which cover the voltage range from 4.2 to 3.2V (which are the values covered by the LiPoly protection circuit).From my testing that would be a sum of ~ 440k (2x220k).Thanks a lot to all of you