Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

negative values using adc

Status
Not open for further replies.
I built the same one as the one posted!!! I didn't connect pic!! I connected to an MCP3002 then to the pic.. I was quite surprised with the result!!

Lets see what you find tomorrow, still not convinced that what you have works, however I will keep an open mind.:rolleyes:
 
Last edited:
I'll see if I can do a little vid..

I have to hook up both bench supplies to get the +15 -15... The first one I tried was with the PC power supply bench thingy I have... +12, -12 and +5.. But the resistor values were out...
 
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
 
Last edited:
Hello again,

The criteria for finding out if Vcc is high enough for a given application (in order to use a passive network) we have (assuming VoutH=5 and VoutL=0 which is most typical for microcontrollers running at 5v):

-(Vcc*R1)/VinL>=0

which simply means that VinL must be negative unless R1=0, and


Vcc>=(5*VinL)/(VinL-VinH+5)

So for VinL=-4 and VinH=+4 the minimum Vcc is:
Vcc=+6.67 volts.

However, for VinL=-5 and VinH=+5 the minimum Vcc is only 5 volts, and for
VinL=-10 and VinH=+10, the min Vcc is only 3.33 volts.
 
Lets see what you find tomorrow, still not convinced that what you have works, however I will keep an open mind.:rolleyes:

I think he's had a 'senior' moment :D

As I see it from his circuit it will read 0V up t0 +15 volts, but 0V down to -15V will all read as zero as it's positive only.

Classic solution is an opamp, biased to half supply voltage, so 0V gives 511/512, +15V gives 1023, and -15V gives 0 (assuming ten bit of course).
 
I think he's had a 'senior' moment :D

I think so too.:rolleyes:

OT:
Good to see you back on the 'mat' after your R and R break.;)
 
Hi,

Yes, a voltage divider without a positive bias will mean anything 0 or under will read as zero, provided the input impedance is high enough not to blow the PIC internal ESD diode because then the chip would blow.

But i think Ian modified his circuit to have a positive bias, right Ian? That would provide a scaled reading to the ADC which should fall between 0 and 5v for anything in the expected range of inputs, included minus voltages if designed right.
 
Sorry!!!! I have just gone back to my post!!!!

I have uploaded the wrong circuit!!!! The one I'm testing is this one..

upload_2015-6-17_14-27-32.png
 
Hi there Ian,

That looks like it has the optimum values for an input of plus and minus 15 volts and power supply reference of 5 volts, and ADC input range of 0 to 5v. Looks very good to me :)

I look at that as the best solution for the given input impedance and power supply voltage because it is the simplest. For some systems an amplifier might be necessary unless we are willing to give up some ADC input range.
 
Hi there Ian,

That looks like it has the optimum values for an input of plus and minus 15 volts and power supply reference of 5 volts, and ADC input range of 0 to 5v. Looks very good to me :)

I look at that as the best solution for the given input impedance and power supply voltage because it is the simplest. For some systems an amplifier might be necessary unless we are willing to give up some ADC input range.

I was starting to doubt myself.... I was getting the right results but everyone was saying no!!! I just checked the circuit to make sure... I got the circuit from the web.. I must have copied the wrong one!!!

I can understand everyone's concern now!!
 
That makes much more sense! :D
That's why I didn't get what Eric was on about!!! I even tested the circuit directly on a pic and it worked fine...

All I can do is apologize for the misunderstanding ( I'm sure it's an AGE thing!! )
 
Hi,

Just to check my own results i went over the resistor values using the formulations i presented earlier, and they spewed out the same resistor values so they must be optimum for the given input values, if we swap R2 and R3 (no big deal as they are just numbered opposite to the formula's numbering in that new schematic).
 
Thank you all for all the help. There is one mistake from my end the external supply is 24v instead of 5v which i came to know today only.
I used the equations suggested, but i could not fit it in as i was getting the negative values for resistor. I have drawn a voltage divider schematic by fitting the lowest range of -4 to 0v but the upper limit of 4v goes to some 7V (another existing resistor divider circuit in the board reduces this 7v to around 4.5V). Sorry for the mistake but could you please provide a new circuit or can I go ahead with the attached one. I am planning to test with the actual hardware an expensive one, so requesting your inputs to avoid damage to hardware.
SchematicNew.png
 
The problem with all of these passive resistive networks is that the ADC reading is ratiometric with the power supplies; any noise or drift in said powersupplies contaminates the ADC reading. Why not do it properly with an opamp which has a power supply rejection ratio of 100+db?
 
Hi,

Mike:
An op amp wont help the power supply variance situation, it's a voltage reference that will help that issue. The op amp rejects power supply variations but any input that is referenced back to the power supply will still cause the same variation problem, and we do need a voltage reference for generating the needed offset voltage. The only way is to use a voltage reference, like a voltage reference diode. A zener is probably not stable enough.

elecLear:
For an input of -4v to +4v with a power supply of 24v exactly, the resistor values come out to:
R2=6*R1
R3=R1*30/13

but note that your schematic has no "R3". You need to add R3 to make this work right. R3 goes from the ADC input node to ground.

The shortened equations for optimum R2 and R3 are:

R2=-(Vcc*R1)/VinL
R3=(5*Vcc*R1)/(5*VinL+Vcc*VinH-Vcc*VinL-5*Vcc)

These two are ONLY when the input range to the ADC is 0 to +5v.

They also simplify a little when the input range is symmetrical about zero, like plus and minus 4v, or plus and minus 10v, etc., to:
R2=R1*Vcc/VinH
R3=R1*5*Vcc/(2*Vcc*VinH-5*VinH-5*Vcc)

For your example here Vcc would be made equal to 24, and VinH would be made equal to 4. R1, as always, is the total input resistance.

For this example the power supply variation will still affect the measurement, but it is reduced by a factor of about 3 because R2 is about 3 times higher than R3. A voltage reference diode is always the best though.
 
Last edited:
Here is a way to do it with a passive network. I show what happens if the 24V supply varies from 22V to 26V. Green is 22V, Blue is 24V and Red is 26V.

The second network eliminates the variation from the 24V supply. All three traces land right on top of each other.

78.gif
 
Thankyou very much the circuit. I simulated the circuit and it is working fine. But few concerns raised by my colleagues before inserting the actual hardware.
a. you cannot simulate a sensor using power source. is it correct?
b. we cannot connect external power source across a sensor. we should only read voltage from sensor.
c. any current going inside the sensor will damage the sensor. since some current is flowing inside sensor it will damage. please help.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top