完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
目前我使用的是PIC1T6F1786ADC。但是当我在液晶显示器上读取ADC值时,它没有给出全分辨率输出。输出从0变化到1330,而不是4096,请帮助我解决这个问题。我的代码无效AdCON1= 0xF0;ADCON0= 0x000;AdCON2= 0x0F;TrISA0=1;ANSA0=0x00;//CH0SEL ADIF=0;ADON=1;ADEE=1;PEI= 1;GIE=1;γ-DelayuUS(50);Gonndot= 1;};
以上来自于百度翻译 以下为原文 Currently i am using pic1t6f1786 adc. but when i read adc value on lcd it dosnt give full resolution output. the output vary from 0 to 1330 and not upto 4096 please help me to solve this problem. my code is void read_adc(void) { ADCON1 = 0xF0; ADCON0 = 0x00; ADCON2 = 0x0F; TRISA0 = 1; ANSA0 = 1; ADCON0 = 0x00; //ch0 sel ADIF = 0; ADON = 1; ADIE = 1; PEIE =1; GIE = 1; __delay_us(50); GO_nDONE = 1; } |
|
相关推荐
11个回答
|
|
|
不要每次读ADC时重新初始化ADC,只要在代码开始时就执行一次。为什么要设置中断?您没有显示任何中断服务例程。
以上来自于百度翻译 以下为原文 Don't re-initialise the ADC every time you read it, just do this once at the start of your code. Why are you setting up interrupts? You didn't show any interrupt service routine. |
|
|
|
|
|
如果(ADIFF=1){Advl=;(AdRHS& lt;lt;8)} Adfl=0;电压();{AdCON1= 0xF0;AdCON0= 0x000;AdCON2= 0x0f;Trasa0=1;AsAc0=0x00;//CH0SEL ADIF=0;Adon=1;Adie=1;PEI= 1;GIE=1;γ-DelayuUS(50);Gonndo=空隙中断高IISR(空隙){1;}空隙电压(空隙){if(计数和lt;=48){ADC1+ADCVAL;ADCVAL=0;计数+++;}否则(计数=49){计数=0;ACKN=1;伏特=((ADC1+ADCVAL)/50);ADCVAL=0;ADC1=0;LCDWrreEntIn(Volt);} LCDWriteInt DelayyMS(5);VoluthAdCo();}空(无符号INT VAL){(i=0;I)!= 4;I++){=(Val% 10);Val/= 10;}}
以上来自于百度翻译 以下为原文 void interrupt high_isr (void) { if(ADIF == 1) { adcval = (ADRESH << 8)| ADRESL; ADIF = 0; voltage(); } } void volt_adc(void) { ADCON1 = 0xF0; ADCON0 = 0x00; ADCON2 = 0x0F; TRISA0 = 1; ANSA0 = 1; ADCON0 = 0x00; //ch0 sel ADIF = 0; ADON = 1; ADIE = 1; PEIE =1; GIE = 1; __delay_us(50); GO_nDONE = 1; } void voltage(void) { if(count <= 48) { adc1 = adc1 + adcval; adcval = 0; count++; } else if(count == 49) { count = 0; ackn = 1; volt = ((adc1+adcval)/50); adcval = 0; adc1 = 0; LCDWriteInt(volt); } __delay_ms(5); volt_adc(); } void LCDWriteInt(unsigned int val) { for(i=0; i!=4; i++) { Digit = (val%10); val/=10; } } |
|
|
|
|
|
你没有显示整个程序,没有你的主函数或配置位的符号。当你工作的时候,你应该尝试显示一个阅读,而不是很多阅读的平均值。你很可能会得到一个溢出。没有必要对这种代码使用中断,并且你不应该做比较慢的操作,比如写在LCD上,从中断服务里面。你输入的电压范围是多少?
以上来自于百度翻译 以下为原文 You didn't show the whole program, there's no sign of your main() function or config bits. While you're getting this working, you really should try displaying a single reading, rather than the average of many readings. You could well be getting an overflow. There's really no need to use interrupts for this sort of code, and you should not be doing relatively slow operations, like writing to LCD, from inside an interrupt service. What range of voltages are you inputting? |
|
|
|
|
|
|
|
|
|
|
|
感谢帮助QHB.变量正在溢出,现在它的工作正常
以上来自于百度翻译 以下为原文 Thanks for the help qhb. the variable was overflowing now its working correctly |
|
|
|
|
|
I:“IF(计数=49)”的目的是什么?除非“计数”在别处被修改,否则看起来毫无意义。而且,看起来你平均有49个样本。没关系,只是一个奇怪的数字。注意在“否则”的情况下添加了额外的样本。Sorry.GP.Edit:改变样本计数评论-基本上删除它。
以上来自于百度翻译 以下为原文 In: What is the purpose of the "if (count == 49)" ? Seems pointless unless "count" is modified elsewhere. GP. Edit: Change the sample count comment - basically removed it. |
|
|
|
|
|
它用于50个AVG值。我得到了我的解决方案和程序是正确的。谢谢。
以上来自于百度翻译 以下为原文 its used for the 50 avg values. i got my solution and program is working correctly. thanks |
|
|
|
|
|
|
|
|
|
|
|
“IF(计数=49)”什么也不做。如果达到的话总是正确的。如果达到了其他值,计数必须为49。你应该把它拿走。这令人困惑,浪费了空间。
以上来自于百度翻译 以下为原文 The "if(count == 49)" does nothing. It's always true if reached. If the else is reached, count must = 49. You should remove it. It's confusing and a waste of space. GP |
|
|
|
|
|
|
|
|
|
|
|
一个替代平均数的样本。我不知道这是否有用,但有助于知道。可以在A/D读数上实现一个简单的低通数字滤波器。滤波器模拟一个单极滤波器,该滤波器通常在硬件中实现,具有串联电阻器和CAP到GR。你定义一个全局变量来保存结果。读A/D过滤器函数必须定期调用,(通常是中断驱动的)。滤波器的时间常数是乘以读取频率的样本数。例如,如果读A/D函数每25MS调用一次。样本量为4,滤波器的时间常数为(4×25)=100ms。注意有大样本量的累加器溢出。随着A/D读数在后台不断更新,结果总是可供您在代码中使用。
以上来自于百度翻译 以下为原文 An alternative to averaging a number of samples. I don't know if this will help but is useful to know. It is possible to implement a simple low pass digital filter on the A/D reading. The filter simulates a single pole filter that is normally realised in hardware with a series resistor and a cap to ground. You define a global variable to hold the result. The read A/D filter function must be called at regular intervals, (normally interrupt driven). The time constant of the filter is the number of samples multiplied by the reading frequency. For example, if the read A/D function is called every 25mS and the sample size is 4, the time constant of the filter is (4 * 25) = 100mS. Watch out for accumulator overflow with large sample sizes. As the A/D reading is being constantly updated in the background, the result is always available for you to use in your code. /*--- Global variable ----*/ uint16_t input_volts; /* This is the filtered result */ /*--- Low pass filter ---*/ void read_input_volts(void) { static uint16_t LP_acc = 0U; /* Low pass filter accumulator */ input_volts = LP_acc / 4U; /* Sample size 4, 100mS time constant, this is the filtered result. */ LP_acc += read_ad(); /* Call the A/D read function and add result to accumulator */ LP_acc -= input_volts; /* Subtract filtered value from accumulator */ } |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
503 浏览 0 评论
5812 浏览 9 评论
2350 浏览 8 评论
2237 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3544 浏览 3 评论
1159浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1121浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
888浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
503浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-13 21:45 , Processed in 0.907822 second(s), Total 64, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2532