其中有一个测温部分,通过A/D转换计算出电阻值查表得到温度值(查表用的是二分法),可是当检测温度是30度时,再升高就直接跳到34度,在升高就是38度,使我设置的温度为32度,33度35度,36度......时总跟实际温度有误差不能调节相等,但是设置温度为30度34度38度,或者小于30度时还算准确,为何啊?为什么温度在30度之上就直接跨越3度,难道是查表的问题吗?以下是查表部分的程序!求赐教!谢谢您
//定义热敏电阻值对应温度
code float res_temp[111]=
{
28.0170,26.8255,25.6972,24.6290,23.6176,22.6597,21.7522,20.8916,20.0749,19.2988,
18.5600,18.4818,18.1489,17.6316,16.9917,16.2797,15.5350,14.7867,14.0551,13.3536,
12.6900,12.0684,11.4900,10.9539,10.4582,10.0000,9.5762, 9.1835, 8.8186,
8.4784, 8.1600, 7.8608, 7.5785, 7.3109, 7.0564, 6.8133, 6.5806, 6.3570, 6.1418,
5.9343, 5.7340, 5.5405, 5.3534, 5.1725, 4.9976, 4.8286, 4.6652, 4.5073, 4.3548,
4.2075, 4.0650, 3.9271, 3.7936, 3.6639, 3.5377, 3.4146, 3.2939, 3.1752, 3.0579,
2.9414, 2.8250, 2.7762, 2.7179, 2.6523, 2.5817, 2.5076, 2.4319, 2.3557, 2.2803,
2.2065, 2.1350, 2.0661, 2.0004, 1.9378, 1.8785, 1.8225, 1.7696, 1.7197, 1.6727,
1.6282, 1.5860, 1.5458, 1.5075, 1.4707, 1.4352, 1.4006, 1.3669, 1.3337, 1.3009,
1.2684, 1.2360, 1.2037, 1.1714, 1.1390, 1.1067, 1.0744, 1.0422, 1.0104, 0.9789,
0.9481, 0.9180, 0.8889, 0.8346, 0.8099, 0.7870, 0.7665, 0.7485, 0.7334, 0.7214,
0.7130
};
/////////////温度查表/////////////////////////////
unsigned char chabiao()
{
unsigned char iiii=9,temp;
float wdjsl=0,wdjsh=110,wdjs=55;
while(iiii)
{
if(resistance>res_temp[(unsigned char)wdjs]) //大 温度过低
{
wdjsh=wdjs;
wdjs=(wdjs-wdjsl)/2+wdjsl;
iiii--;
}
else if(resistance<res_temp[(unsigned char)wdjs]) //小 温度过高
{
wdjsl=wdjs;
wdjs=(wdjsh-wdjsl)/2+wdjsl;
iiii--;
}
else
{
iiii=0;
}
}
temp=(unsigned char)wdjs;
return temp;
}
|