hi Al,
That is what I mean, we must know his source impedance if we are to post a circuit showing divider values.
E
Hi Eric,
Oh yes, very good
[Circuit shown far below]
Here is a formula for calculating Vout, which can be solved for R2, which after selecting R1 and R3 allows calculating the last resistor R2.
R1 is the input resistance plus any addition resistance you add to that which goes from the input to the center node of the voltage divider, R2 is the resistor from the center of the voltage divider to +Vcc, and R3 is the lower resistor of the voltage divider. So it is just a two source voltage divider.
Vout=((Vin*R2+Vcc*R1)*R3)/(R2*R3+R1*R3+R1*R2)
[Latex]Vout=\frac{\left( Vin\,R2+Vcc\,R1\right) \,R3}{R2\,R3+R1\,R3+R1\,R2}[/Latex]
Design example:
Suppose we have Vcc=15 volts, and we want to measure +5v to -5v as input. The center of that input range is 0v and the center of Vout we need to be 2.5v (half the uC supply voltage of 5v) so by taking advantage of the linearity principle we set Vin=0 and Vout=2.5 and we get:
2.5=(Vcc*R1*R3)/(R2*R3+R1*R3+R1*R2)
and say the total input resistance is 10000 ohms (R1), then we try R3=10000 ohms also and so we get:
2.5=75000/(R2+5000)
and solving this for R2 we get:
R2=25000 ohms.
This is the value of R2, which when used with the other chosen resistor values and power supply voltage of 15v, gives us 2.5v output for a 0v input.
Going back to the original formula we plug in all the values and we get the transfer equation:
Vout=Vin*5/12+5/2
and we must check this for an input of +5, 0, and -5 volts.
For +5 we get: 55/12 or about 4.583 volts, and
for 0v input we get: 5/2 or 2.5 volts, and
for -5v we get: 5/12 or about 0.416 volts.
We also note that 4.583 volts is 0.417 volts down from 5.00 volts, so we are about 0.416 volts off from both rails for either end of the input range.
We also note from the transfer function:
Vout=Vin*5/12+5/2
the offset is:
Vos=5/2
and the gain is:
G=5/12
and since the input range is +5 to -5 an input of +5 must show up as 5 and an input of 0 must show up as 0 and an input of -5 must show up as -5, so we have:
V=(Vadc-2.5)/G
where Vadc is first calculated from the ADC bit count.
Note however that by using a passive voltage divider although we achieve the goal of being able to measure plus and minus voltages we do loose part of the range of the ADC. Here we lost about 0.4 volts on the top and bottom of the range, so that's about 16 percent of the available range lost, or a count of about 164 in a 1024 bit ADC system.
We could also discuss optimization. If R1 was 10k, and we made R3=1.5*R1 which comes out to 15k of course, then if we make R2=30k (calculated from the formula above) we would then have 5v out for 5v in, and 0v out for -5v in, and 2.5v out for 0v in, which is optimum for a 5v microcontroller. This means we can get the optimum range using just a passive network.
In fact, optimizing the calculations for R2 and R3 we end up with these two:
R2=(Vcc*VoutH*R1-Vcc*VoutL*R1)/(VinH*VoutL-
VinL*VoutH)
[Latex]R2=\frac{Vcc*VoutH*R1-Vcc*VoutL*R1}{VinH*VoutL-VinL*VoutH}[/Latex]
and
R3=((Vcc*VoutL-Vcc*VoutH)*R1)/((VinH-Vcc)*VoutL+(Vcc-VinL)*VoutH+Vcc*VinL-Vcc*VinH)
[Latex]R3=\frac{\left( Vcc*VoutL-Vcc*VoutH\right) *R1}{\left( VinH-Vcc\right) *VoutL+\left( Vcc-VinL\right) *VoutH+Vcc*VinL-Vcc*VinH}[/Latex]
These two equations lead directly to the optimum values for R2 and R3.
For these formulas, we have the following:
VinH is the highest input voltage to measure (like +5v),
VinL is the lowest input to measure (like -5v),
VoutH is the highest output voltage allowable (like +5v),
VoutL is the lowest output voltage allowable (like 0v), and
Vcc is the power supply voltage which should be well regulated.
For example, and input of -4 to 4v with Vcc=15 and total input resistance of 10k requires that R2=37.5k and R3=30k.
Some combinations of input/output may not work with the simple passive voltage divider if the source voltage Vcc is too low. If any resistor comes out to a negative value, that means Vcc is too low, and this probably means an active amplifier will be necessary.
Code:
Vcc o----R2----+
|
Vin o----R1----+---ADC input
|
R3
|
GND