对于DSP是12位的ADC采样模块,其采样公式为:( ADResult >> 4 )= (VoltInput - ADCLO) / 3.0 * 65520 ; ADResult是结果寄存器中的数字量,VoltInput是模拟电压输入值,ADCLO是ADC转换的参考电平,一般接到地,所以为0值。
根据NTC规格书的NTC热敏电阻R-T表,以及上面的公式。做一个数组,这个数组是从0度到100度时对应的结果寄存器ADResult所采样到的数值,而且是从0度到100度顺序排列的,采样精度为1度。
const int TABLE_TMP[101]=
{241,251,261,272,284,295,307,320,333,346,360,374,388,403,419,435,451,468,485,503,521,540,560,579,600,621,642,664,
686,710,733,757,782,807,833,860,886,914,942,971,1000,1030,1060,1091,1123,1155,1187,1220,1254,1288,1323,1358,1394,
1430,1467,1504,1542,1580,1619,1658,1698,1738,1778,1819,1860,1902,1944,1986,2028,2071,2115,2158,2202,2246,2290,
2334,2379,2423,2468,2513,2558,2604,2649,2694,2740,2785,2831,2876,2921,2967,3012,3057,3103,3148,3193,3237,3282,3327,
3371,3415,3459
};
程序设计如下:
int main()
{
void TMPSCH()
{
int16 TMPCDATA;
int TMPCun=0,TMPCun1,TMPCun2;
TMPCDATA=Inst_Sample[sm_TEMP];
TMPCun1=0;
TMPCun2=100;
if(TMPCDATA<=TABLE_TMP[TMPCun1])
TMPCun=TMPCun1;
else if(TMPCDATA>=TABLE_TMP[TMPCun2])
TMPCun=TMPCun2;
else
{
while(TMPCun11)
{
TMPCun=(TMPCun1+TMPCun2)/2;
if(TMPCDATAelse
TMPCun1=TMPCun;
}
}
TEMP=TMPCun;
}
return 0;
}
最后说一句,这个程序只能测量到0度到100度的值,如果要测量负温度的话,需要在程序上做些修改。