完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
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个回答
|
|
当你使用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 ? |
|
|
|
请给出一个简短的正确和“不正确”的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). |
|
|
|
“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.) |
|
|
|
你好,附件是我的电路图。用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) |
|
|
|
当您将输入多路复用器从FVR切换到AN0时,您不能获得足够的捕获时间。在这两个线路之间增加至少5U的延迟。在设置GO/DE之后,您可以消除50US延迟。即,您在错误的位置上有延迟。
以上来自于百度翻译 以下为原文 You're not allowing enough acquisition time when you switch the input MUX from FVR to AN0. Add at least a 5us delay between these two lines. ADCON0 = 0b00000001; // AN_0, GO_nDONE = 1; // Initializes A/D conversion and you can get rid of the 50us delay after setting GO/DONE. i.e. you have the delay in the wrong place. |
|
|
|
我假设这不是你真正的代码,因为你从不使用“结果”变量,并且它以非C89兼容的方式声明。
以上来自于百度翻译 以下为原文 I assume that is not your real code, as you never use the "result" variable, and it is declared in a non-C89 compatible manner. |
|
|
|
这个ADC实现看起来有点奇怪。建议用0x0FU重新排序,然后再检查结果。(虽然我目前无法想象ADC的“奇怪”格式的确切表达方式,但我觉得比特12/符号位可能会干扰简单地将ADRESX比特累加到I中。nt16t t值
以上来自于百度翻译 以下为原文 This ADC implementation looks somewhat weird. Suggest to and ADRESH with 0x0Fu and check the results then again. (While I currently cannot imagine how exactly the "weird" format of the ADC might express, I feel that the Bit12/sign bit might interfere with simply accumulating the ADRESx bits into an int16_t value.) |
|
|
|
此外,你的源阻抗远远超过推荐的10K最大数据表。
以上来自于百度翻译 以下为原文 Also your source impedance far exceeds the datasheet recommended 10k max. |
|
|
|
只有小组成员才能发言,加入小组>>
5170 浏览 9 评论
2001 浏览 8 评论
1931 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3176 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2228 浏览 5 评论
736浏览 1评论
619浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
507浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
633浏览 0评论
530浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 13:09 , Processed in 1.593732 second(s), Total 91, Slave 74 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号