#define T_MAX 300.0 //温度上限
#define T_MIN -40.0 //温度下限
uint16_t adcValueR100;//接100Ω电阻时AD值
uint16_t adcValueR200;//接200Ω电阻时AD值
const static float PT100TAB[]=//-50`C~299`C
{
80.31, 80.70, 81.10, 81.50, 81.89, 82.29, 82.69, 83.08, 83.48, 83.87,
84.27, 84.67, 85.06, 85.46, 85.85, 86.25, 86.64, 87.04, 87.43, 87.83,
88.22, 88.62, 89.01, 89.40, 89.80, 90.19, 90.59, 90.98, 91.37, 91.77,
92.16, 92.55, 92.95, 93.34, 93.73, 94.12, 94.52, 94.91, 95.30, 95.69,
96.09, 96.48, 96.87, 97.26, 97.65, 98.04, 98.44, 98.83, 99.22, 99.61,
100.00,100.39,100.78,101.17,101.56,101.95,102.34,102.73,103.12,103.51,
103.90,104.29,104.68,105.07,105.46,105.85,106.24,106.63,107.02,107.40,
107.79,108.18,108.57,108.96,109.35,109.73,110.12,110.51,110.90,111.29,
111.67,112.06,112.45,112.83,113.22,113.61,114.00,114.38,114.77,115.15,
115.54,115.93,116.31,116.70,117.08,117.47,117.86,118.24,118.63,119.01,
119.40,119.78,120.17,120.55,120.94,121.32,121.71,122.09,122.47,122.86,
123.24,123.63,124.01,124.39,124.78,125.16,125.54,125.93,126.31,126.69,
127.08,127.46,127.84,128.22,128.61,128.99,129.37,129.75,130.13,130.52,
130.90,131.28,131.66,132.04,132.42,132.80,133.18,133.57,133.95,134.33,
134.71,135.09,135.47,135.85,136.23,136.61,136.99,137.37,137.75,138.13,
138.51,138.88,139.26,139.64,140.02,140.40,140.78,141.16,141.54,141.91,
142.29,142.67,143.05,143.43,143.80,144.18,144.56,144.94,145.31,145.69,
146.07,146.44,146.82,147.20,147.57,147.95,148.33,148.70,149.08,149.46,
149.83,150.21,150.58,150.96,151.33,151.71,152.08,152.46,152.83,153.21,
153.58,153.96,154.33,154.71,155.08,155.46,155.83,156.20,156.58,156.95,
157.33,157.70,158.07,158.45,158.82,159.19,159.56,159.94,160.31,160.68,
161.05,161.43,161.80,162.17,162.54,162.91,163.29,163.66,164.03,164.40,
164.77,165.14,165.51,165.89,166.26,166.63,167.00,167.37,167.74,168.11,
168.48,168.85,169.22,169.59,169.96,170.33,170.70,171.07,171.43,171.80,
172.17,172.54,172.91,173.28,173.65,174.02,174.38,174.75,175.12,175.49,
175.86,176.22,176.59,176.96,177.33,177.69,178.06,178.43,178.79,179.16,
179.53,179.89,180.26,180.63,180.99,181.36,181.72,182.09,182.46,182.82,
183.19,183.55,183.92,184.28,184.65,185.01,185.38,185.74,186.11,186.47,
186.84,187.20,187.56,187.93,188.29,188.66,189.02,189.38,189.75,190.11,
190.47,190.84,191.20,191.56,191.92,192.29,192.65,193.01,193.37,193.74,
194.10,194.46,194.82,195.18,195.55,195.91,196.27,196.63,196.99,197.35,
197.71,198.07,198.43,198.79,199.15,199.51,199.87,200.23,200.59,200.95,
201.31,201.67,202.03,202.39,202.75,203.11,203.47,203.83,204.19,204.55,
204.90,205.26,205.62,205.98,206.34,206.70,207.05,207.41,207.77,208.13,
208.48,208.84,209.20,209.56,209.91,210.27,210.63,210.98,211.34,211.70,
};
float calculate_temperature(uint16_t adcValuePT100)//通过计算求得温度
{
float Kt,Bt,T;
Kt=266.5/((float)adcValueR200-(float)adcValueR100);
Bt=(float)adcValueR100*Kt;
T=Kt*(float)adcValuePT100-Bt;
if(T>T_MAX)T=T_MAX;
if(T<T_MIN)T=T_MIN;
return T;
}
float find_temperature(uint16_t adcValuePT100)//通过查表求得温度
{
uint16_t i;
float R,T=T_MAX;
R=(float)adcValuePT100*100.00/(float)adcValueR100;
for(i=0;i<sizeof(PT100TAB)/sizeof(float)-1;i++)
{
if(R>=PT100TAB[i] && R<PT100TAB[i+1])
{
T=(float)i-50.0+(R-PT100TAB[i])/(PT100TAB[i+1]-PT100TAB[i]);
break;
}
}
if(T>T_MAX)T=T_MAX;
if(R<PT100TAB[0])T=T_MIN;
return T;
}