thermistor calculation question/s
grasshopper
Posts: 438
I am running a thermistor through a 16 bit A to D and all is working well except...
I wish to convert the A to D number to a real value that I can use to display the correct temperature on my 2x20 display. I have the values for A, B, and C but not sure how to implement the rest of the formula. I have read the other thread regarding this topic but i am still stumped.
question 1. What is (R) or must I solve for it?
question 2. If I solve for (R) then how do I implement a Log (ln)? Do i have to put in a log table?
Any help is very much appreciated.
I wish to convert the A to D number to a real value that I can use to display the correct temperature on my 2x20 display. I have the values for A, B, and C but not sure how to implement the rest of the formula. I have read the other thread regarding this topic but i am still stumped.
question 1. What is (R) or must I solve for it?
question 2. If I solve for (R) then how do I implement a Log (ln)? Do i have to put in a log table?
a := 0.001514618 b := 0.000230606 c := 0.000000137 Kelvin = B / (ln(R)-A) - C
Any help is very much appreciated.
Comments
I just finished working on a thermistor myself. I pumped it into an op-amp, then into an ADC. I found that my thermister (GM Air Temp Sensor) was easier to work with if I limited my temp range. Aka, the ranges were 10k-1k for 0deg-130deg, and 1k-50ohm for 130deg-300deg. If I chose to use the whole range, you will need to use natural log. In the specific ranges I mentioned, you can use polynomials (ax^2 + by + c) pretty accurately, and avoid dealing with "ln".
With that said. I have done it using "ln" also. You need to convert it to a base2 log in order to use the prop, which I have a sample calculation found here:
http://forums.parallax.com/showthread.php?p=643713
That will get you going. Unfortunately, my files to do a complete conversion are at home, and you'll have to wait until tonight for me to get them. But, you should be able to figure it out yourself.
Keep in mind that the multiply and divide routines (found in the "Propeller Guts" document) have limitations to accuracy, and you need to keep you math within those limits. AKA, divide will use a 32 bit value divided only by a 16 bit value, with the result being a "long" containing the 16bit value in the lower 16bits, and a 16bit remainder in the upper 16bits. (confused?)
So, you can only divide 2^32 (4294967296) (I limit it to 2^31 (2147483648) cause bit 32 is the negative bit) by 2^16 (65536), and your result will be 2^16, no larger.
The multiply is similar, but you you only multiply 2^16 by 2^16 max, with the result being 2^32max.
I would recommend setting up an excel spreadsheet so you can tweak all you values and make sure you're within limits. Plus, you will learn how the routines work.
Keep in mind, I have written this whole post assuming you want to do it in assembly... sorry if I missed that requirement. But, it's faster than spin. Otherwise, you would do the same with spin, but the math is easier. The main point is that you need to convert your ln(r) to base2, which you can ascertain from the wiki:
en.wikipedia.org/wiki/Natural_logarithm
and
en.wikipedia.org/wiki/Logarithm
The math behind it all:
Ln(x) is loge(x)
to convert to log2
logb(x) = logk(x) / logk(b)
log2(16) = log(16) / log(2)
WHAT YOU NEED TO KNOW:
Ln(ADCvalue) = log2(ADCvalue) * [noparse][[/noparse]log10(2) / log10(e)]
Ln(ADCvalue) = log2(ADCvalue) * 0.693147 (This is the end formula!!!)
the log2(ADCvalue) value can be found using the example I provided in the link earlier...
The rest of the math in the equation is pretty straightforward.
That should get you started....
Success!
-Parsko
ps - I've been knee deep in this recently, so it's fresh.
Post Edited (parsko) : 3/18/2008 6:19:34 PM GMT
I guess i am mostly confused with this ln(r) is the equal the Log of (r) ?
help is wanted
Ln(r) = loge(r)
To go from:
Ln(r) to log2(r)
The math is:
Ln(r) = loge(r) = log2(r) / log2(e)
log2(e) = log10(2) / log10(e) = 0.693147 (This is what the "LOG" button on your calculator will execute, base 10 logs!)
Ln(r) = log2(r) * [noparse][[/noparse]log10(2) / log10(e)]
Ln(r) = log2(r) * 0.693147 (This is the end formula!!!)
log2(r) can be found using the "on-board" log tables in ROM. Cite my example how to use the LOG table in ROM.
Clear it up?
I did explain it in the previous post, but maybe too much depth for the first read. Go over it again with a pad, paper, and calculator.
-Parsko
Hint: You will need to multiply the 0.693147 value by some multiplier for it to be usable (fractions suck to work with, I find), so I used 10000 to get 6931, which you can use in your calculations, but need to divide your answer by 10,000 (notice that this is within the 2^16 limit of the divide routine in ASSY!)
Hint hint: If you use the float object, you can avoid multipliers, and just use the fractions...
Post Edited (parsko) : 3/18/2008 6:17:22 PM GMT
how about using a silicium-temperature-sensor like KTY20 or something similar ?
They are near to linear.
Another idea would be to use XY-Diagrams in Excel. These diagrams have an option to calculate a math-function
fitting close to the single values.
You would have to measure 5-10 points over your temperature-range. Measuring the AD-Values and the real temperature.
Create a Excel-XY-Diagram from these datapairs and let excel calculate the estimate-function. Excel will draw the estimate-function
into the diagram and then you can take a look on how good it is fitting. You can choose between linear, exponential, polynomic and logarithmic functions
to get the best fitting. Maybe there is an eaysier solution than logarithms.
Or you just switch over to a digitical temperature-sensor like LM75 which is an I2C-device
best regards
Stefan
>>question 1. What is (R) or must I solve for it?
If you have the thermistor in a voltage divider circuit to the 16 bit ADC, yes, you will have to solve for R. Say the thermistor is in a divider with a fixed resistor of value Ro ohms, then R will be calculated as a function of that and the excitation voltage Vx and the ADC reading Vadc:
R = Vadc * Ro / (Vx - Vadc) ' calculate resistance of thermistor
It would be different if, say, your thermistor is driven by a current source.
Grasshopper, are you working in Spin or assembly?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com