User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Help with external ADC and thermistor

Sun Jun 28, 2015 9:12 pm

Hi all, I'm trying to read a thermistor using an external ADC with 16 bit precision, the ADS1115. Accuracy is important to me so I've also employed an LM4040 to provide a very steady voltage, specifically I used the model that is supposed to take a 3v3 input and give a 2v048 output.

My main issue here is that every document I've ready discussing how to convert the mV analog reading into a Resistance value assumes that the entire circuit is 5V so it cancels out two voltage readings at some point leaving the equation

R = SeriesResistor / ((2^BitOfPrecision - 1) / ADC_Reading - 1)

I.e.

R = 10K / (1023 / (ADC_Reading - 1))

How can I correctly modify this formula to reflect the fact that my Vcc (3v3) is different than my actual analog input (1v526)
Dear forum: Play nice ;-)

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: Help with external ADC and thermistor

Sun Jun 28, 2015 9:37 pm

I think I'm on the right track, I found the following formula

Rt = (Rs)(Vin - Vout)/(Vout)

Where Rt is the Resistance of the thermistor, Rs is a fixed resistor value (10K for me), Vin is the measurement of my analog input, and Vout is the voltage being supplied as my voltage reference.

Can anyone confirm?
Dear forum: Play nice ;-)

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: Help with external ADC and thermistor

Sun Jun 28, 2015 11:29 pm

It is a simple application of Ohm's law.

Please post your schematic.

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: Help with external ADC and thermistor

Mon Jun 29, 2015 4:03 am

It's a voltage divider.
Dear forum: Play nice ;-)

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: Help with external ADC and thermistor

Mon Jun 29, 2015 6:22 pm

Maybe the issue is I'm not understanding how the ADC is actually working so let me try asking three other questions and we can work back to the main issue.

I power the ADS1115 from the 3v3 rail. Also being powered off the 3v3 rail is an LM4040 shunt voltage reference. I give it 3v3, it gives a steady(er) 2v048. Now I would think that this means that I would tell the ADS1115 to use a GAIN 2 on the analog readings, but I see in the data sheet that I should never allow my Analog in value to be greater than my supply voltage +0.3v or 2v348.

So question 1: To take my small range using the 2v048 and make use of the GAIN_TWO settings do I need to supply the ADS1115 with 5v instead?

Let's assume the answer is yes. So now my VDD is 5v, it still goes to the LM4040 and gives me a 2v048 which goes off to my Wheatsone Bridge (parallel voltage divider)

The schematic looks something like this

Code: Select all

                               |---10K Resistor---------------Thermistor--------|
                               |                            ]                   |
+5v ------ LM4040 (+2v048) ------ Thermistor --------------------- 10K resistor ---- GND
  |                                              |          ]
  |                                              |          ]
  |_______ADS1115--------------------------------A0--------A1
I take my differential reading off A0 and A1 and I'm given a value somewhere in the range of 0 - 65535

Question 2: Zero is definitely equal to zero volts (my ground), but what is the 65535 value? Does it equal the 2v048 I'm supply to the voltage dividers or is it the 5v I'm using to supply the ADS1115?

Question 3: How does the gain factor into all of this? Do I need to divide or multiply the Analog input reading by something to properly interpret the results? On the Adafruit site I see they talk about multiplying it by 0.0625 to get the reading in millivolts, but they never explain where they get that number from or what assumptions they're making about my circuit for that number to be accurate.
Dear forum: Play nice ;-)

User avatar
r4049zt
Posts: 113
Joined: Sat Jul 21, 2012 1:36 pm
Contact: Website

Re: Help with external ADC and thermistor

Mon Jun 29, 2015 6:40 pm

16 bit precision?
+-0.5% is 1/256 so you should expect at best 10-bit useful precision, and more probably seven bits of useful followed by noise.
I'd say
i) look at the datasheet tabulations of thermister resistance at various listed temperatures and spreadsheet yourself a chart to look at 16-bit ad values expected given the R in your test circuit.
ii) be empirical and write down ad values resulting from a few known temperatures such as ice&water, warm water with a thermometer in it, etc ++. If you get better than +-1C then you are doing well.

In sensor calibration, there are no shortcuts. If you need to build a million of the things in a factory then sure, you can use theory after your test department have shown you a histogram of how the first hundred units performed. But to build one, you must calibrate.

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: Help with external ADC and thermistor

Mon Jun 29, 2015 7:44 pm

I'm using resistors and thermistors with +/- 0.01% accuracy not +/-0.5%
Dear forum: Play nice ;-)

User avatar
r4049zt
Posts: 113
Joined: Sat Jul 21, 2012 1:36 pm
Contact: Website

Re: Help with external ADC and thermistor

Mon Jun 29, 2015 7:53 pm

Nevertheless, you'll get a theory calibration which says that it is good to +-0.01%, but does not know the temperature dependent mV where a copper wire is touching a nickelplated one somewhere. But first, put an icecube tray in the freezer, as that will be one point in your testing tomorrow.

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: Help with external ADC and thermistor

Mon Jun 29, 2015 10:00 pm

Okay, that's fine and all, but once i get a reading I'll have the exact same problems. Can you answer any of the three questions i posed a couple posts back?
Dear forum: Play nice ;-)

danjperron
Posts: 3411
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Help with external ADC and thermistor

Tue Jun 30, 2015 12:11 am

Question 2: Zero is definitely equal to zero volts (my ground), but what is the 65535 value? Does it equal the 2v048 I'm supply to the voltage dividers or is it the 5v I'm using to supply the ADS1115?
I did check the specification of the ADS115. It is 16 bits but one bit is the sign. (second complement format) In C this correspond to signed short.


so if A0-A1 = 0 the digital value will be 0
= 2.5V the digital value will be 32767
= -2.5V the digital value will be -32767

This assuming that you set your gain to 2. The gain is the reference value to set your range.


There is one question I do with your settings. Your schematic, which was really messing with my tablet but fine with my MacBook, contains 2 thermistors inside a bridge. Is the two thermistors will be on the same probe or you want to read a differential between them. If it is a differential I don't think it will work since the curve between voltage versus temperature is not linear. (This is a assumption since we don't have any clue about the thermistor curve you are using).

If both probe will measure the same temperature you increase the signal to noise but I.M.O. one sensor is enough.

It make all the calculation more difficult since you don't have a direct reading of the RT resistance, unless you read them individually I will just use one thermistor. Why 2 ?

What is the reason of so much accuracy. You know that passing a simple current on a thermistor will warm the device!

Also what is the range you want to use? This is important because that change the constant resistor value. 10K resistor is ok but if the thermistor range is between 1 and 10 ohm, it doesn't work.

So

1- What is the thermistor specification?
2- What is the range in temperature you are looking for? And this also will tell you what is the Rt range.
3- A normal bridge for thermistor contains only one Thermistor. What is the advantage of using two? How to get rid of none linearity if your are using them in differential. Or is the way the thermistor parts is specify (contains two thermistors).

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: Help with external ADC and thermistor

Tue Jun 30, 2015 1:57 am

danjperron wrote:
Question 2: Zero is definitely equal to zero volts (my ground), but what is the 65535 value? Does it equal the 2v048 I'm supply to the voltage dividers or is it the 5v I'm using to supply the ADS1115?
I did check the specification of the ADS115. It is 16 bits but one bit is the sign. (second complement format) In C this correspond to signed short.


so if A0-A1 = 0 the digital value will be 0
= 2.5V the digital value will be 32767
= -2.5V the digital value will be -32767

This assuming that you set your gain to 2. The gain is the reference value to set your range.
hmmm... so the point of setting the gain is just to let it know what the voltage reference should be? In which case it wouldn't actually amplify the signal prior to running it through the ADC so it doesn't matter if my supply voltage is 5v or 3v3?
There is one question I do with your settings. Your schematic, which was really messing with my tablet but fine with my MacBook, contains 2 thermistors inside a bridge. Is the two thermistors will be on the same probe or you want to read a differential between them. If it is a differential I don't think it will work since the curve between voltage versus temperature is not linear. (This is a assumption since we don't have any clue about the thermistor curve you are using).

If both probe will measure the same temperature you increase the signal to noise but I.M.O. one sensor is enough.

It make all the calculation more difficult since you don't have a direct reading of the RT resistance, unless you read them individually I will just use one thermistor. Why 2 ?
Yeah, getting the schematic to display the way I wanted it to in a code block took a curious amount of finagling. The use of two thermistors was something that came up in a concurrent thread over on the adafruit customer service forum. Here's how it was explained to me.

Code: Select all

Let's say the thermistor changes 5% per degree C and lets assume we're 1 degree from the nominal temperature.  The resistance of both thermistors will be 95% of 10k, or 9500 ohms. The voltage at the middle of the divider on the left will be slightly over 2.1v. The voltage at the middle of the divider on the right will be slightly less than 2v. That means the ADC will see a difference of 0.1v, which it can then translate into a temperature. No matter how the temperature changes, the voltages on the left and right will move in opposite directions.
It's okay that the resistance in a thermistor is not linear, I'm using the Steinhart-Hart equation to translate the resistance to temperature. For starters I've used the factory provided data for resistance at specific values and this web tool to calculate my A, B, and C coefficients on a range from about 50 F to 104 F. Although I could tighten that in even more if I wanted the range that actually matters is about 70F to 85F including some margins of error.
What is the reason of so much accuracy. You know that passing a simple current on a thermistor will warm the device!

Also what is the range you want to use? This is important because that change the constant resistor value. 10K resistor is ok but if the thermistor range is between 1 and 10 ohm, it doesn't work.
The reason for so much accuracy is because my target accuracy is +/- 0.25 C so I'm using a higher degree of accuracy then I need because I know there will be plenty of factors that will drop that back down. Yes a current will warm the thermistor, but the whole point of higher accuracy thermistors is that they *should* be less affected by it. Also I've chosen resistors with a low temperature coefficient so they will cause less variation.
So
1- What is the thermistor specification?
2- What is the range in temperature you are looking for? And this also will tell you what is the Rt range.
3- A normal bridge for thermistor contains only one Thermistor. What is the advantage of using two? How to get rid of none linearity if your are using them in differential. Or is the way the thermistor parts is specify (contains two thermistors).
[/quote]

1. The short answer is a 10K resistor, 25C nominal temperature, B=3892K here is the specific data sheet on it
2. I've chosen a scale of 50F to 104F (because that's a bit wider than my target range and falls of nice even degrees C :lol: )
3. The advantage to using two thermistors, as I understand it, is it helps tighten any margin of error inherent to one of them... although at the end of the day it's mainly because it was describe to me as "a good idea" ;-)
Dear forum: Play nice ;-)

danjperron
Posts: 3411
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Help with external ADC and thermistor

Tue Jun 30, 2015 2:14 am

I did chat on a post about Steinhart-Hart equation.

viewtopic.php?p=491411#p491411

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: Help with external ADC and thermistor

Tue Jun 30, 2015 2:44 am

danjperron wrote:I did chat on a post about Steinhart-Hart equation.

viewtopic.php?p=491411#p491411
I have to beg forgiveness on this one, but I've been working on this for several days and my eyes are going cross looking at a giant wall of text :oops:

TL;DR, what was the equation you ended up using to find resistance? I've simplified my circuit to be a single voltage divider and have even changed it so I have a fixed 10K resistors on both sides of the divider just so I can work out how to get an accurate measure of resistance off the crazy thing.
Dear forum: Play nice ;-)

danjperron
Posts: 3411
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Help with external ADC and thermistor

Tue Jun 30, 2015 3:04 am

Well then the equation is quite simple.

RT = R ( Vo + Vi) / ( Vi - Vo)

where

Vo is the differential voltage between the two side of the Bridge. Where Vo Increase when temperature increase.
Vi is the Voltage reference = 2.048V
R is the resistor value = 10K ohm

And from the A/D converter the Voltage will be calculated

Vo = 2.048V * (A/D_value / 32767.0)

N.B. The A/D value is a signed short value.

Maybe I made an error but I double check and it is OK.

The equation came from the simple resistor divider function Assuming the same resistor and same thermistor on the bridge

V1 = Vi * R / (R + RT)
V2 = Vi * RT / ( R+RT)
Vo = V2 - V1 then => Vo = Vi * (RT -R) / (R+RT)
...
..
finally
RT = R ( Vo + Vi) / ( Vi - Vo)

RT = 10K * ( Vo + 2.048V) / (2.048V -Vo)

Updated! Reference is 2.048V and not 2.5V
Last edited by danjperron on Tue Jun 30, 2015 11:03 am, edited 1 time in total.

User avatar
abishur
Posts: 4477
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
Contact: Website

Re: Help with external ADC and thermistor

Tue Jun 30, 2015 5:29 am

Aha! That did the trick... mostly in the end for some reason I had to take my Wheatstone Bridge apart and reassemble it (on a breadboard so not a whole lot of time to do so :lol: ) before I started getting a reading of almost exactly 10K off my resistors, then I swapped it out for my thermistor and it gave me good readings, swapped it out for the second thermistor and it gave me even better readings. Finally, just for a lark, I added a resistor from my 2v048 output into the third point of my ADS115 and am using it as a definitive reference point for my Vin.

So here's the long and short of these ADS1115 chips from what I've learned so far. The gain is only to provide a reference point for the signal coming in. If I'm only providing it with a 0.5v signal I can set the gain to 8 so it will make better use of the full 15 bits of precision (with 1 bit left over for a sign bit) The strange 0.0625 number I couldn't figure out was the result from taking my gain and dividing it by 2^15 - 1 so with a gain of 2 it's taking 2.048 / 32767 and multiplying by 1000 to display the ADC reading as a value in mV.

So the end formula is this:

Vin = Voltage going to the sensor
Multiplier = Based off gain setting, choose a gain setting that matches the Vin being provided i.e. TWO_GAIN = 2.048, EIGHT_GAIN = 0.5, see this page for the rest of the values. Take the selected gain setting / 32767 * 1000 (i.e. TWO_GAIN = 2.048 / 32767 *1000 = 0.0625)
Rs = Fixed value of a resistor in series
Vo = voltage taken from middle of a voltage divider
R = Resistance value of Thermistor

So

Vo = ADC_READING * Multiplier

R = Rs * (Vo + Vin) / (Vin-Vo)
Dear forum: Play nice ;-)

danjperron
Posts: 3411
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Help with external ADC and thermistor

Tue Jun 30, 2015 10:56 am

Very good!

I will correct my previous post and put 2.048V instead of 2.5V. It just slip on my mind that I was using an invalid reference when I described it!

Anyway you did figure it out! so good luck with your project.

If Vout is in mV. Vin will be also in mV in the equation.

N.B. On your final setup you should use a multimeter and try to find two 10K resistors which give you the same resistance.
(No fingers on the probe please !)

This will reduce the offset.

Return to “Automation, sensing and robotics”