/* Therm_1.C (Flashlite V25) ** ** Routine to calculate a and b constants (2-point model) for an ** NTC thermistor where; ** ** T_K = 1/(a + b*ln(R_therm)) ** ** Prompts user for two sets of temperature - resistor points and ** solves equations for a and b. ** ** a + b * ln(r_therm1) = 1/T_K1 ** a + b * ln(r_therm2) = 1/T_K2 ** ** Writes results to text file "therm.dta". This may later be read ** when performing a temperature measurement. ** ** To test, you might use; ** ** T_C1 = 27.9 r_therm_1 = 8.87e3 ** T_C2 = -1.0 r_therm_2 = 29.1e3 ** ** The result is a=0.000623, b=0.000297 ** ** copyright, Peter H. Anderson, Baltimore, MD, Sept, '00 */ #include <stdio.h> #include <math.h> void calibrate(void); void main(void) { calibrate(); } void calibrate(void) { FILE *f; float R_therm1, R_therm2, T_C1, T_C2, T_K1, T_K2, denom, num; float a, b; printf("Enter T_C and RTherm at one point: "); scanf("%f %f", &T_C1, &R_therm1); printf("Enter T_C and RTherm at second point: "); scanf("%f %f", &T_C2, &R_therm2); T_K1 = T_C1 + 273.15; T_K2 = T_C2 + 273.15; /* solve the two simultaneous equations */ denom = log(R_therm2) - log(R_therm1); num = 1.0/T_K1 * log(R_therm2) - 1.0/T_K2 * log(R_therm1); a = num / denom; num = 1.0/T_K2 - 1.0/T_K1; b = num / denom; f = fopen("therm.dta", "wt"); printf("%f %f\n", a, b); /* print to console and file */ fprintf(f, "%f %f\n", a, b); fclose(f); }