最近在做N76E003的ADC,参考电压是VDD,采用电阻分压,ADC脚直接测量,用万用表显示是4.2V,在串口助手里显示如下:
Voltage:00004.29
Voltage:00004.14
Voltage:00004.25
Voltage:00004.29
Voltage:00004.14
Voltage:00004.29
Voltage:00004.16
Voltage:00004.18
Voltage:00004.29
Voltage:00004.14
Voltage:00004.29
Voltage:00004.27
Voltage:00004.14
Voltage:00004.29
Voltage:00004.14
Voltage:00004.23
显示不稳定,同样的电路用ST的003,显示的是固定数值,不跳变。
程序是根据官方例子改的,
官方例子如下:
void main (void)
{
InitialUART0_Timer1(115200);
Enable_ADC_AIN0; // Enable AIN0 P1.7 as ADC input, Find in "Function_define.h" - "ADC INIT"
while(1)
{
clr_ADCF;
set_ADCS; // ADC start trig signal
while(ADCF == 0);
printf ("\n Value = 0x%bx",ADCRH);
printf ("\n Value = 0x%bx",ADCRL);
Timer0_Delay1ms(1000);
}
}
我改的读取结果函数:
unsigned long GetResult(void)
{
clr_ADCF;
set_ADCS;
while(ADCF == 0);
temp_H=ADCRH;
temp_L=ADCRL;
ADCtemp=((temp_H<<4)|(temp_L&0x0F));
return ADCtemp;
}
用的AIN7
Enable_ADC_AIN7; //PIN14
Timer0_Delay1ms(100);
data1 = GetResult(); //Read the 14th Pin's voltage
Timer0_Delay1ms(100);
data1 = GetResult(); //Read the 14th Pin's voltage
串口显示.....
各位知道结果跳变的原因吗?感谢。
|