0
\$\begingroup\$

I know (or may be think) that I can scale the measurement of a 0 to -3.1V external battery to a analog pin ADC range of 0 to 3.3V, but I'm unable to calculate the resistors. I've been trying how to do this by thevenin, but with no luck...

The schema (I think) would be the following:

schematic

simulate this circuit – Schematic created using CircuitLab

I just want to know the resistor values to measure V1 (V2 have no effect here) but I'm unable of calculating resistor values... Any help?

\$\endgroup\$
  • 2
    \$\begingroup\$ The site has a built in schematic editor. \$\endgroup\$ – JRE Jul 3 '19 at 13:09
  • \$\begingroup\$ I'm kind of fond of good ASCII art, though, JRE! However, avelo, it's not quite clear how the differenc contacts of your battery packs are supposed to be connected. So, I'm afraid JRE is right in asking you do draw a "proper" schematic. \$\endgroup\$ – Marcus Müller Jul 3 '19 at 13:13
  • 1
    \$\begingroup\$ @JRE, sorry, didn't knew about the schematic editor! \$\endgroup\$ – avelo Jul 3 '19 at 14:48
  • 1
    \$\begingroup\$ @DanielK, as other said, I cannot swap inputs \$\endgroup\$ – avelo Jul 3 '19 at 14:49
  • 1
    \$\begingroup\$ @avelo OK, I just wanted to make that clear because it wasn't mentioned in your question. Then an inverting OpAmp would be advisable. \$\endgroup\$ – Daniel K Jul 3 '19 at 15:08
2
\$\begingroup\$

As Elliot correctly said, you can't do this passively and expect the whole 0 to 3.3V range on the output.

However, if you can survive with a reduced voltage range (and thus lower resolution, if you can't affect VREF), you can use a simple two-resistor divider out of the R1 and R2 as pictured in the question. Omit R3.

Another annoying thing of this method is that it'll be referenced to the 3.3V rail, not ground. Anyway, to get to the values:


Mark \$R_1\$ as a resistor between \$V_{cc}\$ and \$V_{out}\$, and \$R_2\$ as the one between \$V_{out}\$ and \$V_{in}\$.

Let \$I\$ be the current passing through the resistor divider: \$I = \frac{V_{cc}-V_{in}}{R_1 + R_2}\$.

These should be quite obvious now:

\$V_{R_2} = I\cdot R_2\$

\$V_{R_1} + V_{R_2} = V_{cc} - V_{in}\$

\$V_{out} = V_{in} + V_{R_2} = V_{in} + R_2 \cdot \frac{V_{cc}-V_{in}}{R_1 + R_2} = V_{in} + \frac{R_2}{R_1+R_2}\cdot (V_{cc} - V_{in})\$


Anyway, plugging your numbers in for a bit, you first look at the case when \$V_{out}\$ is \$0 \mathrm V\$ and \$V_{in}\$ is the most negative, that is \$-3.1 \mathrm V\$.

From \$V_{out} = V_{in} + \frac{R_2}{R_1+R_2}\cdot (V_{cc} - V_{in})\$ you get:

\$ 0 \mathrm V = -3.1 \mathrm V + \frac{R_2}{R_1+R_2} \cdot (+6.4 \mathrm V)\$, that is

\$ \frac{3.1}{6.4} = \frac{R_2}{R_1+R_2}\$, which is your resistor ratio for your divider.

You can now take R1 = 3.3k, and make R2 = 3.1k, for a quick experiment or simulation.


To find out what your maximum output voltage would be, just plug in more numbers, now knowing what the resistor ratio is, and plug in \$V_{in} = 0\$.

Plugging in the numbers into \$V_{out} = V_{in} + \frac{R_2}{R_1+R_2}\cdot (V_{cc} - V_{in})\$ again you get:

\$V_{out} = 0 \mathrm V + \frac{3.1}{6.4} \cdot (+3.3 \mathrm V)\$, which turns out to be about \$ 1.6 \mathrm V\$, as my quick simulation also confirms.


Practical considerations:

  • You'd also want to protect the microcontroller/ADC against too much negative voltage coming to its input in case the 3.3V rail is off – attaching a diode clamp going between the ground and the input should be sufficient for short periods.

  • Do add in some margin considering the highest voltage the battery can get to. 3.1V sounds odd, could be fine for a lithium primary? Point is, you don't want the ADC input pin going negative, which it would with higher-than-designed-for voltage here. Do your research on the maximum voltage the battery can get, no load, absolutely fresh/fully charged, and then add 5-10% in for a good measure.


I encourage anyone with more math/TeX skillage to edit my answer, it is fairly naive in places and it likely could be shown much clearer.

\$\endgroup\$
  • \$\begingroup\$ Thanks for your answer, I'll try to fully understand this, but seems to match what I'm looking for. I don't really need good resolution, just know a bit about battery drain. 3.1V comes from 2 AA pack actually, and 3.3V from the power regulator of the arduino mkr mcu, so I think this should suffice, I'll try to add a diode. Thanks a lot \$\endgroup\$ – avelo Jul 3 '19 at 14:58
  • \$\begingroup\$ Glad to help. Sorry for accidentally making it look like there's more is to it than there actually is though. :D \$\endgroup\$ – Richard the Spacecat Jul 3 '19 at 15:05
  • \$\begingroup\$ Thanks for your very nicely explained answer, it have helped me a lot to advance. So finally I'll probably go with 10kohm and 4.7kohm resistor (as I've some of them here). They doesn't match exactly the calculated ratio by you, but the divider will output on the positive range of 1.25-2.45V, so I can translate that to the actual V of battery. I'm digging how to add a diode or something to avoid having high negative currents if MCU power is disconnected from power. I've tried a 1N4007 before first (10kohm) resistor, but it keeps having high negative voltage. I'll post another question. \$\endgroup\$ – avelo Jul 5 '19 at 10:00
  • \$\begingroup\$ Perhaps you could add a transistor near the Vin you'd only turn on when you'd be taking a measurement \$\endgroup\$ – Richard the Spacecat Jul 5 '19 at 13:55
3
\$\begingroup\$

So when the battery pack input is 0V you want the ADC input to be 3.3V? That is not possible for any non-zero value of R1.

You either need to change your specifications or perhaps use an inverting op-amp to get the full voltage range you want.

\$\endgroup\$
  • \$\begingroup\$ Yes, that was what I got when trying to solve the calculations \$\endgroup\$ – avelo Jul 3 '19 at 14:49

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.