Hello, my problem is a simple one, the soloution may or may not be.
Basically to convert the resistance of a thermistor directly into a temprature the following equation is used.
T =1/ [A + B*Ln(Rt) + c*(Ln(Rt)^3))]
T is temp in kelvin Rt is thermistor resistance
For my 100k thermister A = 0.001279138 B = 0.000146393 C = 2.55E-7
When i read my ADC values into excel and do all the calculations i get a very accurate temprature reading to within about .2 deg
When i do all the math internal in the micro there is (at room temp anyway) 1 deg of error. nearest i can see it is bacause the log() function is truncating the decimal places it puts out. I need 9 places after the decimal and i only get 5.
Is there any workaround for this or an option in the math header that needs to be set, maybe a better log() function?
Thanks, Tom
You don't have access to double-precision numbers - just single precision floats.
So you must then look at the options.
You can create a piecewise table of lookup values to convert from resistance to temperature. The step size of the table depends on the linearity of the curve. Where the curvature is large, you need smaller step sizes.
Then just do a subdivision of the table into smaller and smaller pieces until you find the span the resistance is within. Compute percentage into the sub-range for resistance and use same percentagee into the corresponding temperature range. You can also compute piecewise third-order curves.
Or, if you can afford the flash size, tabulate the temperature for all possible ADC values.
OK, so I did a quick test in the simulator. The results agree with Excel calculations perfectly (better than 0.0001 deg.) Apparently, you are doing something wrong. Can you post your code?
You could use a lookup table with a sufficient number of points and a suitable interpolation function instead of burdening the 8051 with floating-point calculations.
i will post code i have to strip it down some and type it manually as i can not transfer any data onto my networked pcs at work.
thank you
That is what I usually do.
i will post code
Meanwhile, here is the code I used for the test:
#include <stdio.h> #include <math.h> #define A 0.001279138f #define B 0.000146393f #define C 2.55E-7f float temp(float r) { float l; l = log(r); return 1.0f / (A + B*l + C*l*l*l); } char volatile buf[16]; void main(void) { sprintf(buf, "%f", temp(100000.0f)); for (;;) ; }
The error was actually just a stupid mistake in my "on PC" calculations. The uPs math is fine.
I had used a value of 2.4V for my ADC calculations in VB and excel, 2.44 on the uP.
Thanks for the help.