5
\$\begingroup\$

Possible Duplicate: How do I measure a negative voltage with a ADC? How do I sample a -2 V to +2 V analog signal with a PIC microcontroller?

I want to measure the negative and positive DC voltage with a microcontroller.

If the voltage is not in the range 0..5 V then I will need some divider circuit or the scaling circuit to measure the voltage. In measuring positive voltage, the voltage divider circuit is useful, but for measuring the negative voltage I need some circuit.

What would be a scaling circuit which will scale -15..55 V to 0..5 V.

\$\endgroup\$
10

2 Answers 2

9
\$\begingroup\$

You can translate and scale with just three resistors. This is a clever method to calculate them, which you almost can do without calculator.

Use a pull-up to \$+5V\$ and and a pull-down to \$GND\$. Then we have

enter image description here

(Olin, I borrowed your schematic. I hope you don't mind!)

We'll consider two situations: one with \$V_{IN}\$ = \$-15V\$ and one with \$V_{IN}\$ = \$+55V\$. We'll have a set of two equations, so we can choose 1 resistor value. Let's take \$30k\$ for \$R2\$.

First. \$V_{IN}\$ = \$-15V\$. The ADC should then be at \$0V\$. That means that there won't be any current through \$R3\$, since there's no voltage difference. Then \$R2\$ and \$R1\$ form a voltage divider with

\$ \dfrac{0V - (-15V)}{R2} = \dfrac{5V - 0V}{R1} \$

or

\$ R1 = \dfrac{5V}{15V} \cdot 30k\Omega = 10k\Omega \$

Found our first value.

Then the second situation. \$V_{IN}\$ = \$+55V\$. The ADC should then be at \$+5V\$. That means there won't be any current through \$R1\$, since there's no voltage difference. Then \$R2\$ and \$R3\$ form a voltage divider with

\$ \dfrac{55V - 5V}{R2} = \dfrac{5V - 0V}{R3} \$

or

\$ R3 = \dfrac{5V}{50V} \cdot 30k\Omega = 3k\Omega \$

Found our second value. So

\$R1\$ = 10k\$\Omega\$,
\$R2\$ = 30k\$\Omega\$,
\$R3\$ = 3k\$\Omega\$.

edit
Olin suggests something about the impedance the ADC expects. Let's look at a random microcontroller's datasheet and see what it says:

"The ADC is optimized for analog signals with an output impedance of approximately 10 kΩ, or less. With such sources, the sampling time will be negligible." (p.90)

The output impedance of the network is the parallel of \$R1\$, \$R2\$ and \$R3\$, so we can immediately see that it fulfills the requirement. If it wouldn't have, we'd have to scale the resistors down, keeping their ratios equal until

\$ \dfrac{1}{R1} + \dfrac{1}{R2} + \dfrac{1}{R3} > \dfrac{1}{10k\Omega} \$

The only thing remaining is check for tolerances. The divider will give exactly us \$0V\$ for \$-15V\$ in if the resistor values are exact. You can buy 0.1% resistors (still affordable) or even 0.01% (more expensive) and you'll be fine.
But you can also use standard 1% resistors. Increasing \$R2\$ a bit means that the input voltage won't pull as hard up or down, and you'll stay away from the ADC's limits. If you choose 31k\$\Omega\$ instead of 30k\$\Omega\$ the ADC range will change to 0.03V to 4.88V, that's <1% and 2.5% Full Scale. Even with worst case tolerances you'll remain in the ADC's measurement range.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Nice way to get the solution, simpler and more intuitive than my method. For completeness, you should now show how to adjust these values for a particular output impedance, since that is a real issue in most cases. \$\endgroup\$ Commented May 21, 2012 at 20:55
  • 1
    \$\begingroup\$ @Olin - Yes, I like it too. But it only works if both min and max are outside of the rails, so you can pull-up to \$V_{REF+}\$ and pull-down to \$V_{REF-}\$. I had the idea while shaving. Maybe you should get rid of that beard. ;-) \$\endgroup\$
    – stevenvh
    Commented May 22, 2012 at 5:40
  • \$\begingroup\$ Is there some common name for this circuit arrangement? As in, if you remove R1, you'd call it a voltage divider, but what about with R1 included? \$\endgroup\$ Commented Dec 15, 2015 at 22:09
2
\$\begingroup\$

What you want to do can be done with three resistors. However, it is easier to see how this is solved if you first think about the circuit like this:

You have three choices, the values of R1 and R2 and the voltage source. You want to scale -15 to 50 V to the range of 0-5 V. That's a 65 V range scaled to a 5 V range, for a attenuation of 13x. That means R1 must be 12x R2 from the dynamic range scaling alone. That's nails down one degree of freedom out of three. So far we have:

Now we can easily determine the voltage source value. At 50 V in, this must produce 5 V out. That means R1 has 45 V accross it. R1 then obviously has 1/12 of that accross it, or 3.75 V. Since the output is at 5.00 V, the voltage source is therefore at 5.00 - 3.75 V = 1.25 V. So now we have:

This would work, but there are two issues. First, unless you happen to have a 1.25 V source available, this isn't useful. Second, we have one more choice to make. This circuit is only one of many possible solutions. Note that we only determined the ratio of R1 and R2, not their absolute value. R1 and R2 can both be scaled by the same factor to yield other equally valid circuits. There are several ways to look at what this choice means. One way is to decide the maximum current this circuit draws from your input voltage. With a A/D however, the most relevant choice is probably that the output have some minimum impedance. Let's say the A/D requires its input signal to be 10 kΩ or less. That means the parallel combination of R1 and R2 would need to be 10 kΩ. That comes out to R1 = 130 kΩ and R2 = 10.8 kΩ.

Now we have the circuit basically solved, except that it requires a inconvenient voltage source. Note that the voltage source and R2 together can be thought of as a Thevenin source. We can make a equivalent Thevenin source from a voltage divider between 5 V and ground. The 1.25 V output is 1/4 of the range, so the top resistor needs to be 3x the bottom one. From above, we know that the Thevenin source impedance needs to be 10.8 kΩ, so that is what the parallel combination of the two divider resistors needs to be. That means the bottom resistor is 14.4 kΩ and the top 43.3 kΩ.

Putting this all together, the mathematical solution is:

In practise it's a good idea to add a little slop. The resistors are going to have some inaccuracy, and stuff happens. You'd probably pick reasonable available values for R2 and R3, see what voltage and impedance that comes out to, then pick R1 so that there is a little room at each end of the range.

\$\endgroup\$
2
  • \$\begingroup\$ Hm, in my second answer I also use a pull-up to +5V and pull-down to ground, so I should have come up with the same resistor ratios. Then I noticed OP made an error in the question. In the title he says 50V, in the question 55V. \$\endgroup\$
    – stevenvh
    Commented May 21, 2012 at 15:04
  • \$\begingroup\$ Maybe add two clamping diodes to +5V and GND as protection? \$\endgroup\$
    – jippie
    Commented May 21, 2012 at 18:51

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