利用16位AD做数字滤波,取20个AD的平均值。在中断里面取AD值。滤波次数太多的话,大于10次,AD就会出现下跌情况。例如采样值计算后为60.00,有时候会突然变为58.xx.请高手研究下这个程序。。
oid get_Padc_count()
{
unsigned char i;
CONA=1;CONB=0;
delay(2);
PPP=0;
fit=fit-1;
switch(fit)
{
case 19:{filter1[19]=ADConv();};break;
case 18:{filter1[18]=ADConv();};break;
case 17:{filter1[17]=ADConv();};break;
case 16:{filter1[16]=ADConv();};break;
case 15:{filter1[15]=ADConv();};break;
case 14:{filter1[14]=ADConv();};break;
case 13:{filter1[13]=ADConv();};break;
case 12:{filter1[12]=ADConv();};break;
case 11:{filter1[11]=ADConv();};break;
case 10:{filter1[10]=ADConv();};break;
case 9:{filter1[9]=ADConv();};break;
case 8:{filter1[8]=ADConv();};break;
case 7:{filter1[7]=ADConv();};break;
case 6:{filter1[6]=ADConv();};break;
case 5:{filter1[5]=ADConv();};break;
case 4:{filter1[4]=ADConv();};break;
case 3:{filter1[3]=ADConv();};break;
case 2:{filter1[2]=ADConv();};break;
case 1:{filter1[1]=ADConv();};break;
case 0:{filter1[0]=ADConv();fit=fit3;};break;
default:break;
}
for(i=0;i<fit3;i++)
{PPP=PPP+filter1[i]; }
PPP=PPP/fit3;
} |