Heloi正在读取一个电位器上的电压,从一个电位计到VDD,5V。我的代码是为4.096V基准和12bit ADC建立的。结果是正确的只有2V。如果电位计在0V,ADC读数6,那么高达2V,这是非常准确的。可能要读取5V,我必须配置TH。我尝试过VDREVDD,但是直到2V才得到正确的结果。我在其他项目上使用了10位ADC,并且我总是可以读取到5V的紧张,没有问题。我的代码是:
以上来自于百度翻译
以下为原文
Hello
I'm reading the voltage on A0 from a poten
tiometer hocked up to VDD, 5V.
My code is set-up for 4.096V reference and 12bit ADC.
The results are correct up to only 2V. If the potentiometer is at 0V the ADC reads -6, then up to 2V it is very accurate.
Probably to read 5V I would have to configure the VREF to VDD what I tried, but I get correct results only until 2V.
I used on other projects 10bit ADC and I always could read tensions up to 5V without problems.
My code is:
void main(void) {
init();
while (1) {
ADCON0 = 0b00000001; // AN_0,
GO_nDONE = 1; // Initializes A/D conversion
__delay_us(50);
while(GO_nDONE); // Waiting for conversion to complete
int result = ((ADRESH<<8)+ADRESL);
}
}
void init() {
TRISC = 0b00000000; // all out
TRISA = 0b00000001; // RA0 analog in, rest out.
ANSELA = 0b00000001; // Select A0.
FVRCON = 0b10000011; // FVR enabled, FVR 4.096V
ADCON0 = 0b01111101; // 12-bit result, FVR Buffer1, ADC enabled.
ADCON1 = 0b11110011; // 2's format, FRC int. Clk, VREF = VDD, VREF- to GND.
ADCON2 = 0b00001111; // Negative VRef sel. by ADRREF.
WPUA = 0X00;
INTCON_GIE; // GIE global interrupt enabled.
PW_LED = true;
}