I am a mechanical engineering student (with basic programming knowledge) building a code to convert emf produced by a thermocouple to temperature. For this I am using the polynomial equations and constants provided by NIST:
Temp= c0 + c1*E + d2*E^2 + ... + cn*E^n,
The issue is that I am receiving incorrect values of temperatures. At 12mv of input the code is supposed to return 1662 deg c. However the code is returning very large numbers. To verify the polynomial equation I tried it out in excel and it returned correct temperatures. Hence I am assuming that the polynomial equation is being written correct.
I know that float has some inaccuracy, but I do not expect it to throw off the temperature by thousands (4185264128.0000) ..
Here is a glimpse of the code, I also tried it in different ways to eliminate pow();
float mv_sns = 12.0; // input voltage // polynomial coefficients: float c0 = 213.150712; float c1 = 285.10504*mv_sns; float c2 = -52.742887*mv_sns; float c3 = 9.9160804*mv_sns; float c4 = -1.2965303*mv_sns; float c5 = 0.11195870*mv_sns; float c6 = -0.0060625199*mv_sns; float c7 = 0.00018661696*mv_sns; float c8 = -0.0000024878585*mv_sns; float temp = (c0 + c1 + (c2*c2)+ (c3*c3*c3)+(c4*c4*c4*c4)+(c5*c5*c5*c5*c5)+(c6*c6*c6*c6*c6*c6)+(c7*c7*c7*c7*c7*c7*c7)+(c8*c8*c8*c8*c8*c8*c8*c8)); //float temp2 = ( c0 + (c1*mv_sns) + pow(c2*mv_sns,2) + pow(c3*mv_sns,3) + pow(c4*mv_sns,4) + pow(c5*mv_sns,5) + pow(c6*mv_sns,6) + pow(c7*mv_sns,7) + pow(c8*mv_sns,8)); Serial.println(temp,4); delay(600);
I also tried this way which returned same results:
float temp2 = ( c0 + (c1*mv_sns) + pow(c2*mv_sns,2) + pow(c3*mv_sns,3) + pow(c4*mv_sns,4) + pow(c5*mv_sns,5) + pow(c6*mv_sns,6) + pow(c7*mv_sns,7) + pow(c8*mv_sns,8));
Your help would be highly appreciated!