help figuring out voltage divider for adc input - Page 1
Forum section: electronics / beginners

author: jordan_me160
author_rank: Contributor
timestamp: December 11, 2021, 06:30:37 am
content: I seem to be having some trouble wrapping my head around making a voltage divider for an adc. bit of back story i am making a few temperature/humidity sensors using esp01's and i am using a 3.6v lithium battery (3.6v er14505 lithium battery, max i got on a volt meter across the 6 i have was 3.7v) and a 3.3Vvoltage reg to power it, but i would also like to monitor the battery voltage and report (via mqtt in home assistant but ive got that portion figured out) the voltage/percent of the battery so i can make an alert when it gets low and needs to be changed. After some reading i found the esp01 does have an adc but ill have to carefully solder a wire to the pin on the chip as it does not have a breakout pin (datasheet calls it TOUT and is either a voltage reference output or adc input depending on the code used). I have also found the adc has an input range of 0-1v, it apparently has a 50nA leakage current and they say a 20mOhm input impedance. Now i am having trouble wrapping my head around the formula for a voltage divider given this because it tells me i need something like a 40kohm at 0.0001W and a 20k ohm at 0W, witch does not seem correct to me....if someone could give some guidance on how i should be going about this or if my math is correct, or if i am totally wrong please point me in the right direction

author: ataradov
author_rank: Super Contributor
timestamp: December 11, 2021, 06:46:51 am
content: You can ignore the wattage, it does not matter. But 40k/20k divider would divide 3.7 V to ~1.2 V, which is still higher than your ADC input range.

author: radiolistener
author_rank: Super Contributor
timestamp: December 11, 2021, 06:52:44 am
content: you can try to put 80 kΩ between the battery and ADC input. And 20 kΩ between ADC input and ground. So the divider will be 20kΩ/(20kΩ+80kΩ)=1/5.In such case 3.7 V will be measured as 3.7/5 = 0.74 V. And you will have some margin in case if the battery voltage will be more than 3.7 V. For exampel Li-Ion 3.7 V battery can have up to 4.25 V and even more, in such case you will get 4.25/5 = 0.85 V on the ADC.

author: jordan_me160
author_rank: Contributor
timestamp: December 11, 2021, 03:51:10 pm
content: awesome thanks for the help ill give that a go! just for future though, what's the math to figure out those resistances?

author: ledtester
author_rank: Super Contributor
timestamp: December 11, 2021, 04:16:31 pm
content: Quote from: jordan_me160 on December 11, 2021, 06:30:37 amWhat formula are you following - can you provide a web link?Your references to "0.0001W" and "0W" are raising a red flag for me.

author: rstofer
author_rank: Super Contributor
timestamp: December 11, 2021, 04:29:37 pm
content: Someplace in the datasheet there should be a reference to the maximum driving impedance. In the bad old days it was very low, perhaps 2k Ohms or so.What that means is not only does the ratio of the resistor values have to divide the voltage, the parallel combination of the resistors must be lower than the specified driving impedance.I know less than nothing about the ESP32 but here is a recommendation that the driving impedance be 10K ohms or less. Using 80k/20k you only have 16k so maybe 48k/12k. And that assumes that the real source has near zero impedance and, for a battery, this is true.These ADCs have 6% variance between chips - their accuracy prior to calibration is lousy.This is the only reference to impedance that I have found. I couldn't find the value in the datasheethttps://electronics.stackexchange.com/questions/107741/required-output-impedance-for-adc-input.https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdfhttps://electronics.stackexchange.com/questions/243277/output-impedance-of-voltage-divider

author: rstofer
author_rank: Super Contributor
timestamp: December 11, 2021, 04:35:26 pm
content: To get the power dissipation, take the worst case voltage drop across a resistor (call it V), square it and divide by the resistanceP = V2/Rhttps://www.electronics-tutorials.ws/dccircuits/dcp_2.html

author: jordan_me160
author_rank: Contributor
timestamp: December 11, 2021, 04:40:34 pm
content: here is the link to the forum where i found the impedance and leakage current mentionedhttps://www.esp8266.com/viewtopic.php?f=160&t=13435and the formula for the voltage divider, i am using a voltage drop calculator to drop 3.7v to 1v and then again from 1v to 0.0001v as the calculator doesn't like to have a 0 in the output voltage but here is the link to it anywayhttps://elecurls.tripod.com/drop-res.htmi found this site for a formula and examples for a voltage divider but i think my brain just shut down when i started reading because none of this makes any sense to mehttps://www.electronics-tutorials.ws/dccircuits/voltage-divider.html

author: rstofer
author_rank: Super Contributor
timestamp: December 11, 2021, 04:56:38 pm
content: Figuring the output voltage of a divider is easy.Vout = Vin * R2 / (R1 + R2)https://www.seeedstudio.com/blog/2019/10/09/voltage-dividers-everything-you-need-to-know/Intuitively, for the case of 48K/12K you will have 4 times the voltage drop across the 48K resistor as you will have across the 12K. But the sum is still 60K so we are dividing by 5. That makes sense; 4 times across the top resistor + 1 times across the bottom resistor - total is divide by 5.. 5V in, 4V across the top resistor and 1V across the bottom resistor where the ADC measures the voltage.To find the driving impedance that the ADC sees, just use the parallel resistance formula: Reqiv = (R1 * R2) / (R1 + R2) - this form only works for two resistors. More generally, you can add any number of parallel resistors using:1/Rparallel = 1/R1 + 1/R2https://www.khanacademy.org/science/electrical-engineering/ee-circuit-analysis-topic/ee-resistor-circuits/a/ee-parallel-resistors#:~:text=Resistors%20are%20in%20parallel%20if,than%20the%20smallest%20parallel%20resistor.

author: ledtester
author_rank: Super Contributor
timestamp: December 11, 2021, 05:01:07 pm
content: Quote from: jordan_me160 on December 11, 2021, 04:40:34 pmThat page is for computing a voltagedrop resistorfor an LED.QuoteWhat's your background in electronics? Do you know about Ohm's Law?Here's a voltage divider calculator that's pretty easy to use.For "Resistor Sequence" select "E24" and for "Resistor Scale" select 10000.https://www.ti.com/download/kbase/volt/volt_div3.htmFor an input voltage of 3.7 and an output voltage of 1.0 the calculator gives 27K and 10K. Of course, the voltage on a fully charged lithium ion battery can be 4.2V, so I'd probably recalculate using an input voltage of 5V.

author: rstofer
author_rank: Super Contributor
timestamp: December 11, 2021, 05:06:41 pm
content: I certainly wouldn't be using 1 MOhm and probably not 100K either. The input current needs to charge the measuring capacitors in a reasonable amount of time and the driving impedance controls that. If it can drive some current, the capacitor gets charged faster. If it's wimpy, it takes longer. But it has to get done in time for the ADC to get the right answer.Considering I remember 2K as a maximum driving impedance, 10K is pretty nice. Without some detail specs, I surely wouldn't be thinking in terms of 100K.OTOH, it's just resistors. Try it and see how it comes out. Remember, the voltage divider is wasting energy and it wastes a lot more at 10K than it does at 100K. You can always change the resistors if there is a problem.Leakage current has absolutely nothing to do with ADC operation. It might be a factor, somehow, but it's tiny compared to charging the capacitors.https://www.ti.com.cn/cn/lit/an/slyt176/slyt176.pdf

author: jordan_me160
author_rank: Contributor
timestamp: December 11, 2021, 05:30:38 pm
content: thanks for the help and those links. as for my experience, id say i am pretty good at simple electronics, usually using premade things and cobbling them together to do what i want with a bit of a ballistic approach to it. i by no means know everything but usually the only reason i cant understand something is because im half asleep after a long day at work, i don't get a lot of time to figure everything out on my own and sometimes its faster to ask for help instead of grinding away till i get time to figure it out.edit: would there be a way that i could save power on the voltage reading? this is a wireless temp/humidity reader so having long battery life would be nice or would it be negligible compared to the draw of the rest of the esp01 and dht22 im using?

author: rstofer
author_rank: Super Contributor
timestamp: December 11, 2021, 05:59:57 pm
content: Reducing the wasted energy is a numbers game. We REALLY need to know the intended driving impedance. Then we can look at low power op amps to do the buffering of a much higher impedance divider. The op amp will have essentially 0 Ohms of output impedance - clearly a great ADC driver. Many designs do exactly this.First 'Rule of Thumb' for driving ADCs is to use a low output impedance buffer. The problem is, selecting an op amp is a course unto itself. We probably need to get close to the rails (or not) and we need to drive a capacitive load and do it from a low impedance output. And we don't want to waste a lot of power on the op amp.https://e2e.ti.com/blogs_/archives/b/precisionhub/posts/first-rule-of-thumb-when-driving-adc-inputsFirst look for 'MicroPower' Op Amps, then see that the signal is well within the voltage rails (and it seems like it is), there will be a spec on how close the input can get to the rails as a function of output current. At high current, the voltage can't get as close to the rails.You need to spend time at Ti searching for papers on driving SAR ADCs. Here's a TI video on the topic that I haven't had time to watch.https://youtu.be/8lxCo1U07Bs

author: jordan_me160
author_rank: Contributor
timestamp: December 11, 2021, 09:02:22 pm
content: sound like its going to be more work than its worth to lower power draw, i am already using a large battery (2400mah, non-rechargeable) and the esp01 draws something like 170ma max when sending/receiving on wifi, and when its not its deep sleep draw is around 20uA, so seeing as it will be more work to raise the efficiency of the adc circuit i think ill stick with the voltage divider path and risk having to change battery's slightly faster

author: ledtester
author_rank: Super Contributor
timestamp: December 12, 2021, 08:01:50 am
content: Here is another forum thread on measuring battery voltage with an ESP:https://www.eevblog.com/forum/projects/battery-monitoring-voltage-divider/Seems like you get away using large resistors by placing a small cap at the ADC input. You will have to reduce your sampling frequency, but for monitoring battery voltage you probably don't need a fast sample rate anyway.

author: Peabody
author_rank: Super Contributor
timestamp: December 12, 2021, 04:19:38 pm
content: I posted about this in another thread, but it seems relevant here too. If you have to divide down to below 1V, it seems the circuit shown below would let you switch on the divider to take a reading, but it would be off at all other times. That would pretty much eliminate the divider current draw as an issue to deal with. If your Vcc is 3.3V and the midpoint of the divider is below 1V, the mosfet should have no trouble turning on, but to be safe you might want to use a mosfet with a lower Vgs threshold voltage than the 2N7000. And this method would let you use lower value resistors if you need to reduce impedance, but not pay any material penalty for doing that.