请问,我使用的是PIC18F14K50,使用了RC0/RC1/RC2三路AD,使用了内部4.096V的基准电压,VDD供电是5V,发现检测的电压不准确。同时做了个实验,将RB6与RC2接到同一个电压上,在程序中分别设置为AD检测,发现检测出来的电压值不一致,求指教!
AD初始化程序如下:
void ADInit()
{
/////////VSOLAR_SNS-AD4
TRISC |= 0X01;
ANSEL &= ~0X10;
//////////I_SNS-AD5
TRISC |= 0X02;
ANSEL &= ~0X20;
////////VBAT_SNS-AD6
TRISC |= 0X04;
ANSEL &= ~0X40;
ADCON1 = 0X08;
ADCON2 = 0X82;
ADCON0 |= 0X01;
REFCON0 = 0XB0;
REFCON1 &= ~0X80;
ADCON0 &= ~0X3C;
ADCON0 |= 0X10;
ADCON0 &= ~0X02;
while((REFCON0 & 0X40) == 0X00);
}
AD检测程序如下:
uint ADData = 0;
ADCON0 &= ~0X3C;//VSOLAR_SNS
ADCON0 |= 0X10;
ADCON0 |= 0X02;
while(ADCON0 & 0X02);
ADData = (((uint)ADRESH << 8) + ADRESL);
SolarVol = (ADData * 20);//乘以20为每个计数值为4个mV,并且电路分压为5
ADCON0 &= ~0X3C;//I_SNS
ADCON0 |= 0X14;
ADCON0 |= 0X02;
while(ADCON0 & 0X02);
ADData = (((uint)ADRESH << 8) + ADRESL);
OutI = (ADData * 11);
ADCON0 &= ~0X3C;//VBAT_SNS
ADCON0 |= 0X18;
ADCON0 |= 0X02;
while(ADCON0 & 0X02);
ADData = (((uint)ADRESH << 8) + ADRESL);
BatVol = (ADData * 12); |