Microchip
直播中

杨靖

7年用户 174经验值
私信 关注
[问答]

16F1782 adc只有2V范围

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 potentiometer 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;
}

回帖(8)

王璨

2018-9-12 14:45:06
当你使用4.096 V参考电压时,你永远都看不到5伏特的电压。这是根本不可能的。第2,有趣的是,你的电位器的标称电阻和“类型”(特性)是什么?3,你到底指的是什么……但我直到2V才得到正确的结果。预告:看我的脚注P.S.:你听说过“日志”吗?电位器“以前”?

以上来自于百度翻译


      以下为原文

    #1 You never could read voltages of 5 V when using a 4.096 V reference. This is simply impossible.
#2 Would be interesting what the nominal resistance and the "type" (characteristic) of your potentiometer are.
#3 What exactly do you mean by "...but I get correct results only until 2V." ?
 
Prejudging: see my footnote  
 
P.S.: Have you ever heard of "log. potentiometers" before ?
举报

tijing忽忽

2018-9-12 14:57:57
请给出一个简短的正确和“不正确”的A/D值和输入电压的列表,可能会使事情变得更清楚一些,但是“直到2V才得到正确的结果。”电位器的锥度不可能导致不正确的A/D值,但是它会改变关系。轴的旋转和由此产生的输出电压(它将是对数与线性)。

以上来自于百度翻译


      以下为原文

    Please post a short example list of correct and "incorrect" A/D values and the input voltages, might make things a little clearer then "but I get correct results only until 2V."
The taper of the potentiometer is unlikely to result in incorrect A/D values however it will change the relationship between the rotation of the shaft and the resultant output voltage (it would be logarithmic vs linear).
 
 
举报

王璨

2018-9-12 15:16:58
“Jack @ Kksoudii在对数电位器上下注:在右边,它几乎不能从线性的第一个30。40%的行程中分辨出来。@ DrimeMARTAL交换你的电位器的5 V和GND连接!我敢打赌,在0到2年内,它将不再是“OK”,在3到4的区域中,它将“稍微好一点”。(你不会得到超过4.096 V的电压,但是-因为你的PIC似乎是5 V型-你不会毁了它。)

以上来自于百度翻译


      以下为原文

    @ jack@kksound
I bet on a logarithmic potentiometer: on the "right side" it will be hardly discernible from the linear one for the first 30..40 % of travel.
 
@ drumanart
Swap the 5 V and GND connections of your potentiometer! I bet it will be no longer "ok" for 0 - 2 V. And it will be somewhat "better" in the 3 - 4 region. (You won't get voltages beyond 4.096 V, but - as your PIC seems to be a 5 V type - you won't ruin it.)
举报

李冬茗

2018-9-12 15:33:13
你好,附件是我的电路图。用PIC(A0)侧的电压表测量,我可以用电位器从0到4V,9V调节电压。我用一个27 K来分离电位器的音频信号。在我的代码中电压基准是4.096V,我得到的结果是1MV的步骤,对于12位ADC和4.096V Reee来说是正确的。在2V以上(或Maby稍高),结果开始下降,但电压表测量电压上升。因此,如果在A0上测量3.3V,则结果为1600和3.7V,结果是下降,A0引脚上的0V也给出了-6的否定结果。我试图将VDD作为电压参考,并且我或多或少相同。以前的电路与10bit ADC(18F422)一起使用,而我没有。问题。我不能仅仅倒GND和5V,因为电位器是用来调节音频信号的,谢谢马丁。

以上来自于百度翻译


      以下为原文

    Hello.
Attached is a drawing with my circuit. Measuring with a voltmeter on the PIC (A0) side I can adjust the voltage with the potentiometer from 0 up to 4,9V.
I use a 27k to seperate the audio-signal from the potentiometer.
 
In my code the voltage reference is 4.096V and I get results in 1mV steps what is correct for a 12bit ADC and 4.096V reference configuration.
Above 2V (or maby a little higher) the result starts to drop but the voltmeter measures the voltage going up. So if I measure 3.3V at A0 the result is 1600 and 3.7V the result is 1400, so the result drops.
Also 0V on the A0 pin gives a negative result of -6.
I tried to hock up VDD as voltage refence and I get more or less the same.
 
The same circuit I used before with a 10bit ADC (18F442) and I did'nt have the problem.
I can't just invert GND and 5V as the potentiometer is to regulate an audio signal
 
Thanks Martin
 
 
 
 
 
 
 
 
   Attached Image(s)

举报

更多回帖

发帖
×
20
完善资料,
赚取积分