slackjack
Posts: 7
Joined: Sat Apr 20, 2013 2:29 am
Location: Avoca Beach, NSW, Australia

ADC with voltage divider problem

Sat Apr 20, 2013 2:52 am

Hello all. I am new here, but I have not been able to find an explanation in any of the posts or elsewhere on web for my problem.
I want to use a thermistor on the ADC. I am trying to set it up using a voltage divider. I am getting readings, but they are not as expected.
In order to test if the program I am using (based on Alex test programs) is returning proper readings, I set up a test circuit composed of a voltage divider with two equal (120k) resistors. The centre tap connected to ADC.
I believe this should result in a reading of 1023/2 = 512.5, but it gives 427 +- 3 over 10000 readings.
As an aside I was originally trying without the J7 jumper on (fixed now due to reading this forum) and while this did not work either, the readings were not too different, giving 418 but with greater variability (+- 20). Thanks in advance.

User avatar
alexeames
Forum Moderator
Forum Moderator
Posts: 2869
Joined: Sat Mar 03, 2012 11:57 am
Location: UK
Contact: Website

Re: ADC with voltage divider problem

Sat Apr 20, 2013 7:44 am

A few quick suggested diagnostics...

What happens if you swap the resistors round? Do you still get the same value. (quick and dirty test to see if they really are the same).

What is the ADC chip on your Gertboard? It occurred to me that if they varied the chip, it might break the code. Code was written for an MCP3002.

What is the voltage measurement at the centre tap?

Hopefully one of those will throw some light on it. :D
Alex Eames RasPi.TV, RasP.iO

slackjack
Posts: 7
Joined: Sat Apr 20, 2013 2:29 am
Location: Avoca Beach, NSW, Australia

Re: ADC with voltage divider problem

Sat Apr 20, 2013 9:41 am

Same result when switched.

Voltage on both branches is just over 1.5 v (very cheap Multimeter) but total Supply voltage is less than 3.3 too.

With the Thermistor, total voltage of branches is close to 3.2 v (.95V over 60k ohm and 2.2V on thermistor).

User avatar
alexeames
Forum Moderator
Forum Moderator
Posts: 2869
Joined: Sat Mar 03, 2012 11:57 am
Location: UK
Contact: Website

Re: ADC with voltage divider problem

Sat Apr 20, 2013 9:54 am

OK. Not sure what to suggest now. What ADC have you got? It should be the 8 pin chip next to the AD and DA pins. (The larger of the two, not the teeny SMT one) It should have a code like MCP3xxx on it.
If it's not MCP3002, that could be the problem. (although I suspect something in the circuit)
Alex Eames RasPi.TV, RasP.iO

slackjack
Posts: 7
Joined: Sat Apr 20, 2013 2:29 am
Location: Avoca Beach, NSW, Australia

Re: ADC with voltage divider problem

Sat Apr 20, 2013 10:35 am

Yes it is the MCP3200.
Not sure how it can be anything in the external circuit. The voltages add up, but the ADC is not reporting an appropriate reading. It could be the Gertboard itself, but I have no idea how I could confirm that,

User avatar
Burngate
Posts: 6196
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: ADC with voltage divider problem

Sat Apr 20, 2013 10:54 am

Can you give us a diagram of how you're connecting it up? Also a data sheet for the thermistor?

User avatar
alexeames
Forum Moderator
Forum Moderator
Posts: 2869
Joined: Sat Mar 03, 2012 11:57 am
Location: UK
Contact: Website

Re: ADC with voltage divider problem

Sat Apr 20, 2013 11:12 am

slackjack wrote:Yes it is the MCP3200.
I'm not familiar with the 3200? That's not 3002

There is a 3202 which is 12 bit and might require different code.

Was that a typo or is yours really 3200?
Alex Eames RasPi.TV, RasP.iO

slackjack
Posts: 7
Joined: Sat Apr 20, 2013 2:29 am
Location: Avoca Beach, NSW, Australia

Re: ADC with voltage divider problem

Sun Apr 21, 2013 7:10 am

My typo sorry. MCP3002
---/\/\/\/\/\------/\/\/\/\/\---
| R1 | R2 | My circuit, but I do not think this is a problem.
| | |
GND AD0 3.3V
Now I have found something else I did not expect, but which may help someone to put me straight.
I have run the dad.py program and it does not do what I expect either, but does do what is shown in another tutorial (http://www.tech-fruits.com/all-tutorial ... onverters/).
The output from a digital input of 255 is analog 634. I expected the 255 to corespond to 3.3 V and therefore to return analogue 1023.
Please tell me what I am missing here.

slackjack
Posts: 7
Joined: Sat Apr 20, 2013 2:29 am
Location: Avoca Beach, NSW, Australia

Re: ADC with voltage divider problem

Sun Apr 21, 2013 7:11 am

Circuit a bit messed by html stripping spaces, but I hope you get the idea, 2 equal resistors, centre point connected to AD0.

User avatar
PeterO
Posts: 5468
Joined: Sun Jul 22, 2012 4:14 pm

Re: ADC with voltage divider problem

Sun Apr 21, 2013 7:42 am

See section 4.2 of the MCP 3002 manual....

"Ideally, the impedance of the signal source should be near zero"

Your potential divider has source impedance of 60kΩ (which is far from zero !).

Try reducing the values of the resistors (if the voltage source can stand the extra load, or add a buffer between the divider output and the ADC input, or better still use a buffer stage with gain of 0.5 as that will reduce the load on your voltage source even further.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

slackjack
Posts: 7
Joined: Sat Apr 20, 2013 2:29 am
Location: Avoca Beach, NSW, Australia

Re: ADC with voltage divider problem

Sun Apr 21, 2013 8:36 am

Thanks Peter.
My electronics knowledge is fairly limited, so I will have to go and study up to see why that is necessary and what I can do about it. I am using a Thermistor that has a resistance of 100K at 25C and my temps (in an Aquaponics tank) will be from 15C to about 25C. Resistance at 15C is around 160K. To give the Voltage divider the greatest sensitivity I need to combine the Thermistor with a resistor of value R = square root of (Rmin × Rmax) = sqr (100000 x 160000) = 125K (aprox), which is higher. If I choose the resistor to give best sensitivity over a wider range of temps (0C to 100C) then I could use a resistor of 40K. But I don't think that is significantly lower.

Well off to do some reading and some thinking.

User avatar
PeterO
Posts: 5468
Joined: Sun Jul 22, 2012 4:14 pm

Re: ADC with voltage divider problem

Sun Apr 21, 2013 10:01 am

OK,

First thing I would try is a simple unity gain buffer stage between the divider and the ADC.

Just google for "unity gain buffer op amp" and you'll get the idea.....

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

btidey
Posts: 1635
Joined: Sun Feb 17, 2013 6:51 pm

Re: ADC with voltage divider problem

Sun Apr 21, 2013 11:05 am

As everybody else has said here the issue is one of source resistance. This type of ADC is a successive approximation type which starts by sampling the input voltage by connecting the input pin to a hold capacitor. This is only for about 1.5 clocks (1.5uSec) so if the input resistance is high then the capacitor won't have time to charge up properly to the input voltage and the reading will be low.

The hold capacitance is about 20pF so the source resistance needs to be about 10KOhm or less to avoid having an effect at the LSB level. This is based on a (200nS RC time constant) period which allows the capacitor to closely approach the input voltage during sampling. With a 60KOhm value the time constant is 1.2uSec which means the capacitor is only reaching about 70% of final voltage.

Normal remedies are as already mentioned, either use lower resistances or buffer beforehand.

I think also if the clock rate is based just on SPI clock then one could also lower the clock rate to give a longer sampling time. E.g. a 100KHz clock would allow 15uSec sampling and source resistances up to 100KOhm. Check out spidev to see how to do that.

User avatar
Burngate
Posts: 6196
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: ADC with voltage divider problem

Sun Apr 21, 2013 11:46 am

I'm sorry, I misunderstood - I thought you had already connected your thermistor, and couldn't work out where you had it connected.
I've taken the liberty of drawing it out
GertboardA-D.gif
GertboardA-D.gif (2.5 KiB) Viewed 5344 times
Since I doubt your thermistor is a precision device, I think you may find experimenting to calibrate it will be better than trying to calculate what it should do.
If so, then the fact that the results you get aren't what theory says you should won't be a problem!

User avatar
Gert van Loo
Posts: 2487
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: ADC with voltage divider problem

Sun Apr 21, 2013 11:47 am

I solution which I suggested in the past and which seems to work for slow changing signals,
is to add a capacitor to the input. The idea is that the external R's charge the external capacitor.
That is slow and gives you an RC delay. But then when the ADC converter opens the port,
the external capacitor acts as 'buffer' and you do not get so much voltage drop.
e.g. a external 2nF capacitor would be 100x bigger then the internal 20pF so you're voltage
drop effect would be 100x smaller.
But now you have RC of e.g. 100K to 2nF which gives you a delay of about 1 millisecond to charge the capacitor from 0 to 99%.
[ Vt = V0(1-exp(t/RC)) Solve for Vt/V0=0.99 gives 4.6*R*C=0.00092 Unless I made a mistake ]
As you have a temperature sensor it is unlike that your value changes fast so you could even go for 20nF.

User avatar
PeterO
Posts: 5468
Joined: Sun Jul 22, 2012 4:14 pm

Re: ADC with voltage divider problem

Sun Apr 21, 2013 11:56 am

Gert van Loo wrote:I solution which I suggested in the past and which seems to work for slow changing signals,
is to add a capacitor to the input.
That's sounds like a simple,practical solution :-)
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: ADC with voltage divider problem

Sun Apr 21, 2013 7:09 pm

slackjack wrote:My typo sorry. MCP3002
---/\/\/\/\/\------/\/\/\/\/\---
| R1 | R2 | My circuit, but I do not think this is a problem.
| | |
GND AD0 3.3V
Now I have found something else I did not expect, but which may help someone to put me straight.
I have run the dad.py program and it does not do what I expect either, but does do what is shown in another tutorial (http://www.tech-fruits.com/all-tutorial ... onverters/).
The output from a digital input of 255 is analog 634. I expected the 255 to corespond to 3.3 V and therefore to return analogue 1023.
Please tell me what I am missing here.
The maximum output voltage is 2.047 volts.

If you install wiringPi, then the GPIO program has some easy to use commands to help from the command-line - e.g.

gpio gbr 0

will read analog channel 0, and

gpio gbw 1 128

will write 128 to DAC channel 1.

-Gordon
--
Gordons projects: https://projects.drogon.net/

slackjack
Posts: 7
Joined: Sat Apr 20, 2013 2:29 am
Location: Avoca Beach, NSW, Australia

Re: ADC with voltage divider problem

Sun Apr 21, 2013 10:47 pm

Thanks for all those suggestions. The circuit Burngate has posted is the way I had my test circuit configured. I will experiment with smaller resistors now to see the result and hopefully learn a bit more about the limitations.

It is amazing how quickly you find out how much you do not know when you talk to someone who understands.

I will digest these suggestions and try to work out the simplest for my setup (with the stuff I have around). I was also thinking I would try to reduce the total impedance of my source by adding a parallel resistor with the thermistor. I know that this will reduce the sensitivity, but if I choose it correctly, maybe not too much in the range I am most interested in.

Return to “HATs and other add-ons”