Entire Forum This board This topic Members Entire Site
 Pages: [1]
 Author Topic: Resistor divider error  (Read 1921 times) 0 Members and 1 Guest are viewing this topic.
Wizpic
Global Moderator
Hero Member

Offline

Posts: 1114

Thank You
-Given: 371

 « on: December 20, 2013, 08:41:07 20:41 »

I've been playing around with a pic18F45K80 as a meter 12bit resolution 4.096 V Ref  0-40 volts , It's all working but there is a small issue but it's with the resistor divider in real time. My resistor divider consists of (R1) 43K & (R2) 4K7 and if you enter the voltage EG 13.43V input then the output from the resistor divider  you get 1.323 not quite 1:1 but close enough.  This reads close enough on both meters as the real meter reads 13.43V pic meter reads 13.42V A/D raw 1328 and input on RA0 is 1.320 volts. I have got a little calibration routine to correct this. If I measure 12.31V on a battery both meters read the same even when I apply a small load(4 x 12V fans). The trouble starts when I try to read higher voltages as follows
RA0     R/M     P/M    Raw value   (RA0 pic input, R/M real meter, P/M pic meter, Raw value)
.102V   1.04V   1.09V   108
.645V   6.57           6.59      996
1.007V   10.05   10.06      (Forgot to write down)
1.320V   13.43V   13.41v     1328
?          18.51    17.39   1722
1.911   21.91   19.38V      1918 (this where the trouble starts)
2.411V   31.09   24.48 2438 (this it gets worse)
If you enter the 31.09V on resistor divider calculator you get 3.063V out but in real time you can see that it reads 2.411 on RA0 but the raw value is 2438 and pic meter reads 24.48 the raw value is close enough but compared to the real meter it's nearly 6 volts out. My gut feeling is that this is caused by the current draw on 4K7, I've tried 6K8(R2) and 10K(R2) along with the corrected values of R1 with each change but get much of the same results the higher you go the worse the readings get. I thought I would of got pretty much the same reading 31.09 input output should be 3.063 (+/- littler for error) but not 2.411V  as to me that's a 65% error ??
Is there a better way of doing it or where I'm going wrong ?
 Logged

When you think, "I can't do anymore. I need a break," that is the time to challenge yourself to keep going another five minutes. Those who persevere for even an extra five minutes will win in life..
optikon
Cracking Team
Hero Member

Offline

Posts: 749

Thank You
-Given: 866

 « Reply #1 on: December 21, 2013, 01:46:33 01:46 »

I am not looking into the PIC datasheet but here are some things to consider.

1) Consider the input bias current to the pin as well as the max input voltage it can tolerate before turning on a diode and ruining your whole linear divider. If you dont know what these are, that should be a red flag right there.

2) For the resistor loading effect if the pic is drawing current, consider an opamp buffer to isolate.

 Logged

I can explain this to you. I can't comprehend it for you.
solutions
Hero Member

Offline

Posts: 1788

Thank You
-Given: 623

 « Reply #2 on: December 21, 2013, 03:46:35 03:46 »

Not familiar with the part, too lazy to look at the datasheet, but it sounds like you have a pulldown resistor on the port  being activated by the higher input currents. Check your port bit settings. I'm assuming you are using the internal Vref?

If that doesn't do anything, try a 430k/47k divider first. Maybe a voltage follower as a buffer off the divider, or an op amp 10:1 attenuator, second?
 Logged
Wizpic
Global Moderator
Hero Member

Offline

Posts: 1114

Thank You
-Given: 371

 « Reply #3 on: December 21, 2013, 07:20:57 07:20 »

I am not looking into the PIC datasheet but here are some things to consider.

1) Consider the input bias current to the pin as well as the max input voltage it can tolerate before turning on a diode and ruining your whole linear divider. If you don't know what these are, that should be a red flag right there.

2) For the resistor loading effect if the pic is drawing current, consider an op-amp buffer to isolate.
That I will look into and have already considered using an op-amp for buffering,

solutions I have thought about that and will check the Dev board in case that port as other loads on it (so will try another port)and no I'm using and external Vref of 4.096 but have also tried it with VDD as Vref but get the same results. I have a few things/thoughts to check now but you know how it goes the harder you think about things the worse it gets and you can think to deep plus you really want it to be perfect and accurate might be a bit to much to ask of a PIC but the ICL7106 is 10bit same as pic, I know 7106 is designed for it and PIC is really not. I've not really has this issue before as I got them working by just reading a set voltage say like 12V or 24V and altered the values to suit but this is for a friend who wants to measure different levels of voltage/current and needs it to be fairly accurate. The trouble is I like perfection and settle for nothing less
 Logged

When you think, "I can't do anymore. I need a break," that is the time to challenge yourself to keep going another five minutes. Those who persevere for even an extra five minutes will win in life..
PaulC
Active Member

Offline

Posts: 171

Thank You
-Given: 3935

 « Reply #4 on: December 21, 2013, 07:11:40 19:11 »

is there a thermal resistance causing the differential between the "real time" and software readings, maybe location or loading, temperature near resistors under load..
just to throw a spanner in the works..
 Logged

find it , read it , share it .
ptr
Newbie

Offline

Posts: 15

Thank You
-Given: 17

 « Reply #5 on: December 21, 2013, 08:21:51 20:21 »

Your problem has to do with recommended impedance of analog voltage source.

Check parameter A30 in the datasheet: A30 ZAIN Recommended Impedance of Analog Voltage Source 2.5 kohm.

Maybe it helps a bit if you put a 100 nF cap from the analog input RA0 to GND also consider lowering your voltage divider.

 « Last Edit: December 21, 2013, 08:24:21 20:24 by ptr » Logged
Wizpic
Global Moderator
Hero Member

Offline

Posts: 1114

Thank You
-Given: 371

 « Reply #6 on: December 21, 2013, 09:03:01 21:03 »

I have done a bit of playing and used the op-amp to buffer the signal and the voltage out of the resistor divider as now stabilized and using the median filter method the voltage is now stable and no jumping up and down which you can is the raw value is jumping up and down 3 or 4 counts but reading stable. Still working in the precision though as I still think it could with been better. will let you know how it goes

wizpic
 Logged

When you think, "I can't do anymore. I need a break," that is the time to challenge yourself to keep going another five minutes. Those who persevere for even an extra five minutes will win in life..
Vineyards
Active Member

Offline

Posts: 149

Thank You
-Given: 52

 « Reply #7 on: December 21, 2013, 10:28:11 22:28 »

How much current can you withdraw from resistors with such high values and what happens when some or all of the current available is consumed? I wouldn't take any measurements unless I use some sort of a buffer stage because otherwise you can't expect stability. The current available would not be enough to drive the ADC. What you will get will be wild fluctuations.

The rules of Physics are iron clad. (I hope I am not totally at loss)
 « Last Edit: December 22, 2013, 10:05:10 10:05 by Vineyards » Logged
bigtoy
Active Member

Offline

Posts: 220

Thank You
-Given: 245

 « Reply #8 on: December 22, 2013, 12:47:29 00:47 »

Good move on switching to the op-amp. Just keep in mind that everything has a tolerance - the resistors are only accurate to a certain percentage, and the op-amp will have a finite non-zero offset error (small, but measurable with a decent A/D converter). Improving precision or accuracy by choosing "better" components is extremely expensive - look at the price of 0.01% resistors on digikey as an example. A far cheaper way to achieve improved accuracy is simply to calibrate your circuit. A 2-point calibration (where one point can be ground, ie zero volts) and the other point would be a known voltage (measure it with a borrowed high-quality multimeter for example) allows you to determine both offset and gain accuracy for your overall circuit (y = mx + b).
 Logged
Wizpic
Global Moderator
Hero Member

Offline

Posts: 1114

Thank You
-Given: 371