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 Reply Children
  • 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 (;;) ;
    }