|
裸奔的测试程序中自带ADC是用AIN2的,我修改成AIN0为什么测试不到电压??程序修改如下
int ReadAdc(int ch)
{
int i;
static int prevCh=-1;
rADCCON = (1<<14)|(preScaler<<6)|(ch<<3);
if(prevCh!=ch)
{
rADCCON = (1<<14)|(preScaler<<6)|(ch<<3);
for(i=0;i<LOOP;i++);
prevCh=ch;
}
rADCCON|=0x1; //start ADC
while(rADCCON & 0x1); //check if Enable_start is low
while(!(rADCCON & 0x8000)); //check if EC(End of Conversion) flag is high
return ( (int)rADCDAT0 & 0x3ff );
}
void pickshownum(int no,int x0,int y0,int h, int l)
{
switch(no)
{
case 0:
Paint_Bmp(x0, y0, h, l, shu0);
break;
case 1:
Paint_Bmp(x0, y0, h, l, shu1);
break;
case 2:
Paint_Bmp(x0, y0, h, l, shu2);
break;
case 3:
Paint_Bmp(x0, y0, h, l, shu3);
break;
case 4:
Paint_Bmp(x0, y0, h, l, shu4);
break;
case 5:
Paint_Bmp(x0, y0, h, l, shu5);
break;
case 6:
Paint_Bmp(x0, y0, h, l, shu6);
break;
case 7:
Paint_Bmp(x0, y0, h, l, shu7);
break;
case 8:
Paint_Bmp(x0, y0, h, l, shu8);
break;
case 9:
Paint_Bmp(x0, y0, h, l, shu9);
break;
default:
break;
}
}
void Test_Adc(void)
{
static int t=1;
unsigned int voltage=0; //Initialize variables
unsigned int no1,no2,no3;
preScaler = 50000000/ADC_FREQ -1; //ADC_FREQ=2500000,即最大转换频率
if(t){ // 此处做了个液晶显示,显示采样得到的数值0--3.3V
Lcd_ClearScr( (0x00<<11) | (0x00<<5) | (0x00) );
Paint_Bmp(0, 0, 480, 272, vsamp); // PS 做的一个界面
t=0;
}
voltage=(unsigned int)ReadAdc(2)*330/(0x3ff);
no1=voltage%10;
no2=voltage/10%10;
no3=voltage/100;
pickshownum(no3,120,61,25,40);
Paint_Bmp(145, 61, 10, 40, dian);
pickshownum(no2,155,61,25,40);
pickshownum(no1,180,61,25,40); // 液晶屏显示的数值 如 2.11
Delay( 500 ) ;
}
以上是ADC.C中主要部分,在main中调用。用默认的2通道测试可实现数据采集和显示!!
根据TQ2440底板原理图,我将GPIO上AIN0和AIN2相连,voltage=(unsigned int)ReadAdc(2)*330/(0x3ff)改成voltage=(unsigned int)ReadAdc(0)*330/(0x3ff),换成通道0一直显示0V,也就是没采集到电压,
请问这是什么问题?? 看了论坛一些帖子,提到ADC驱动,和这有关系吗?? |
|