This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Log() function not accurate enough. How can i fix it?

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

Parents
  • 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.

Reply
  • 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.

Children
No data