完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
嘿,各位,我在Explorer 16演示板上的ADC转换器工作。AN5是潜在的仪表端口。我正在尝试测试ADC功能。如果ADC值大于500,则LeD10将闪烁。我已经检查了很多次关于我的代码。它不起作用。我认为问题是在while循环中。我可以这样做……//FoCC 3200 000 L//FCY(FoC/C 2)/ /芯片运行在8 MIPS(百万指令每秒)//STED0.125US定义FXCY 800 000 UL,定义Max AdCl值20包括:STDIO。不知道是否DE“LIbPIC30.H”无符号短ADCVal[Max AdCyValu];//无符号AIN;INT主(){//初始化设备TrISA=0x000;AD1PCFGBIT.PCFG5=0;AD1CON1= 0x2002;AD1CON3= 0x0100;AD1CHS= 0x5;AD1CSSL=0x000;//不需要扫描AD1CON1ADON=1;//打开ADC;IFS0BITS AD1IF=0;而(1){AD1CHS=0x5;AD1CON1BITS。SAMP=1;/ /开始采样α-DelayyMs(1);AD1CON1BITS。SAMP=0;//开始转换,(!)Ad1CON1BIT。{};AIN=ADC1BUF0;//读取转换结果(AIN和Gt;500){ LATA7=1;γ-DelayyMS(100);γLATA7=0;γ-DelayyMS(100);}返回0;}
以上来自于百度翻译 以下为原文 Hey everyone, I am working on the ADC converter on explorer 16 demo board. AN5 is the potential-meter port. I was trying to test the ADC function. If the ADC value is greater than 500, LED10 will be blinking. I have check many times about my code. it is not working. I think the problem is in the while loop. Don't know if I can do it this way... //FOSC 32000000L //FCY (FOSC/2) //the chip is running at 8 MIPS (million instructions per second) //TCY 0.125us #define FCY 8000000UL #define MAX_ADC_VALUES 20 #include #include #include #include #include "libpic30.h" unsigned short adcValues [MAX_ADC_VALUES]; // array of ADC readings int i; unsigned ain; int main() { // initialize the device TRISA = 0x0000; AD1PCFGbits.PCFG5 = 0; AD1CON1 = 0x2002; AD1CON2 = 0X0000; AD1CON3 = 0x0100; AD1CHS = 0x5; AD1CSSL = 0x0000; // no scanning required AD1CON1bits.ADON = 1; // turn on the ADC; IFS0bits.AD1IF = 0; while (1) { AD1CHS = 0x5; AD1CON1bits.SAMP = 1; // start sampling __delay_ms(1); AD1CON1bits.SAMP = 0; // start converting while (!AD1CON1bits.DONE){}; ain = ADC1BUF0; // read the conversion result if(ain > 500) { _LATA7 = 1; __delay_ms(100); _LATA7 = 0; __delay_ms(100); } } return 0; } |
|
相关推荐
3个回答
|
|
|
“它不起作用”从来不是一个很好的问题描述你真正的测试,你所期望的,以及你实际看到的。请描述一下。我没有检查你的ADC设置,但是你首先要测试的是,你的假设是否正确。如果你评论/如果(AIN & GT?500),它是否“眨眼”如预期?我假设它应该闪烁5赫兹。下一步你应该检查你的AIN(结果)值,以及它们是否是恒定的,有一些噪声,或者“不知何故”跟随电位器的变化。根据结果,你可以再次检查你的ADC配置和代码。
以上来自于百度翻译 以下为原文 "It is not working" never is a good problem description of what you really tested, what you expect, and what you actually see. Please describe. I did not check your ADC setup, but the first thing you should test is, whether your assumptions are right. Does it "blink" as expected, if you comment out // if(ain > 500) ? I would assume that it should blink with 5 Hz. Next you should check your ain (result) values, and whether they are either constant, have some noise, or 'somehow' follow the potentiometer changes. Depending on the results you then may again check your ADC configuration and code. |
|
|
|
|
|
您尝试使用Explorer 16的示例代码吗?如果不是,那么请转到这个链接:HTTP://www. MyCHIP.COM/DealthOrthsStudio/StudioDeLiels.ASPX?PARTNO = D24000 01,向下滚动到文档选项卡。在文档下面有一个演示代码。您可以将其应用到应用程序中。
以上来自于百度翻译 以下为原文 Have you tried using sample code for Explorer 16? If not then please go to this link: http://www.microchip.com/Developmenttools/ProductDetails.aspx?PartNO=DM240001 And scroll down to Documents tab. Under documents there is a Demo code. You can manipulate that to your application. |
|
|
|
|
|
谢谢你,罗迪斯。代码工作正常。我之前测试过,当我说LED没有闪烁时,我没有加上“Y-YelayaysMS(1)”,“Ad1CON1BITS,SAMP=0;//START转换”,现在,我认为这两个代码很重要。
以上来自于百度翻译 以下为原文 Thank you, rodims. The code is working as it is. I tested it. Before, when I said the led is not blinking, I didn't add "__delay_ms(1);" "AD1CON1bits.SAMP = 0; // start converting" Now, I think these two codes are important. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1122浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
872浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-1 22:51 , Processed in 0.736871 second(s), Total 81, Slave 63 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1666