On 19 April 2016 at 23:16, Nick Hill <n...@nickhill.co.uk> wrote:
> #define THERMISTOR_BETA 3380
> #define THERMISTOR_R0 10000
> #define THERMISTOR_T0 (298.15)
> #define Rinf (THERMISTOR_R0*pow(2.718,(-1*(THERMISTOR_BETA/THERMISTOR_T0))))
>
> With Cosmic compiler, any reference to Rinf pulls a large chunk of
> math library into the executable.

Incidentally, this can't be taken as a usage scenario where floating
point libraries can otherwise be excluded completely from the runtime
since the Rinf variable is used in conjunction with a runtime variable
in a natural logarithm expression in order to derive temperature.

The working function looks like this.Taking ADC output then providing
temperature in centigrade. RES_GND defines whether the potential
divider resistor (COMP_RESISTOR) is connected to Vcc or GND. I have
tested this in circuit with an actual thermistor and I find the output
is a close match to measured temperature.

float calculate_temp(short ADC_reading){
    short R1;
    float temperature;
    #if(RES_GND)
        
R1=((float)(COMP_RESISTOR/(float)(ADC_reading/(float)ADC_MAX_SCALE))-(float)COMP_RESISTOR);
    #else
        
R1=((float)COMP_RESISTOR/((float)(ADC_MAX_SCALE-(float)ADC_reading)/(float)ADC_MAX_SCALE))-(float)COMP_RESISTOR;
    #endif
    temperature=(float)THERMISTOR_BETA/log((float)R1/(float)Rinf);
    return (temperature-273.15);
}

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to