完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家早上好,我不能用PIC12F1572读取ADC的值。我试图用RA1作为模拟输入,所以我用以下方式初始化ADC模块:ANSELABItiTS。ANSA1=1;/选择RA1作为输入电压ADCON0SIT的模拟输入引脚。CHS=0x01;//我使用AN1作为输入ADCONDOWS。ADON=1。/ADC是启用ADCONLIDE。ADCs=0x01;//选择ADC转换时钟选择为FoC/ 8 ADCON1BIT。ADFFM=0x01;//结果是正确的,那么在主循环中,我使用以下函数:未签名int模拟值;/ /用于捕获捕获后的ADC结果,(1){模拟值=Read值();LATA2=1;//L上的延迟(50000);//250MS@=16MHz LababITIT.LATA2=0;//led OFF延迟(50000);//250MS@ FoCC=16MHz }试图用MPLABX和ICD3调试我的代码,我可以看到连接到RA2的ON/OFF切换,但是变量模拟值总是0x00。谢谢你,安德烈。
以上来自于百度翻译 以下为原文 Goodmorning to all, I'm not able to read a value from ADC with PIC12F1572. I'm trying to use RA1 as analog input, so I initialized the ADC Module in the following way: ANSELAbits.ANSA1=1; // Select RA1 as analog input pin for input voltage ADCON0bits.CHS=0x01; // I'm using AN1 as input ADCON0bits.ADON=1; // ADC is enabled ADCON1bits.ADCS=0x01; // select ADC conversion clock select as Fosc/8 ADCON1bits.ADFM=0x01; // results are right justified Then in the main loop I'm using the following function: unsigned int AnalogValue; // used to store ADC result after capture while(1) { AnalogValue = Read_ADC_Value(); LATAbits.LATA2 = 1; // LED on _delay(50000); // 250ms @ Fosc=16MHz LATAbits.LATA2 = 0; // LED off _delay(50000); // 250ms @ Fosc=16MHz } Trying to debug my code with MPLABX & ICD3, I can see LED connected to RA2 toggling ON/OFF but variable AnalogValue is always 0x0000 Any suggestions will be very appreciated Thank you Andrea |
|
相关推荐
13个回答
|
|
你使用哪种编译器?XC8应该是正确的,C18不能正确处理您的换档。您不为该PIN显示任何TIS设置,您确定它是在输入模式中吗?
以上来自于百度翻译 以下为原文 Which compiler are you using? XC8 should be ok, C18 won't handle your shifting correctly. You don't show any TRIS setting for that pin, re you sure it's in input mode? |
|
|
|
感谢使用XC8编译器,我用这个行设置了PIN:TrISabIt.TrISa1=1;再次感谢安德烈。
以上来自于百度翻译 以下为原文 thanks for the reply I'm using XC8 compiler; I setted the pin with this line: TRISAbits.TRISA1 = 1; thanks again Andrea |
|
|
|
当你做这个测试时,RA1管脚上的电压是多少?当你这样做时,你正在断开程序员?
以上来自于百度翻译 以下为原文 What is the voltage on the RA1 pin when you do this test? You are disconnecting the programmer when you do this? |
|
|
|
在RA1引脚I放置一个分压器,因此在其上测量的模拟电压为48 5MV,如果我给板提供外部电源。当我与调试器连接时,在电阻分压器上给出相同的电压,我仍然在RA1引脚上测量85MV。但我有一个疑问:当我在调试模式连接时,同一个引脚(RA1)连接到程序员的时钟信号。ADC有可能因为这个原因而不能工作吗?我可以尝试建立一个阈值,并产生不同的闪烁频率的LED,当我运行没有调试器,以建立我是否正确阅读ADC感谢。
以上来自于百度翻译 以下为原文 On the RA1 pin I placed a voltage divider, so the analog voltage measured on it is 485mV if I supply the board with an external power supply. When I'm connected with debugger, giving the same voltage on the resistor divider I still measure 485mV on RA1 pin. But I have a doubt: when I'm connected in debug mode, the same pin (RA1) is connected to clock signal of the programmer. Is it possible that ADC doesn't work for this reason? I could try to establish a threshold and produce different blinking frequency for the LED when I'm running without debugger, to establish if I'm reading correctly the ADC. Thanks Andrea |
|
|
|
如果处于调试模式,则不能对任何其他函数使用调试引脚,包括ANALAG输入。
以上来自于百度翻译 以下为原文 If you are in debug mode, you cannot use the debugging pins for any other function, including analag input. |
|
|
|
在定义变量之后,我已经修改了主循环的一部分,(1){ if(类比值& lt;min级别){LababITI. LATA2=1;//led ON-O-DelayyMS(500);LababITS.LATA2=0;//led Offy-DelayyMS(500);} {{LATabIT.LATA2= 1;//led }},因此我预期LED会闪烁。或者继续,但它只在电源打开几秒钟,然后关闭。现在我没有与调试器连接,我编程的PIC和我提供了一个外部来源。
以上来自于百度翻译 以下为原文 I've modified part of the main loop as follow, after defining a variable (#define MINLEVEL 67): while(1) { if (AnalogValue < MINLEVEL) { LATAbits.LATA2 = 1; // LED on __delay_ms(500); LATAbits.LATA2 = 0; // LED off __delay_ms(500); } else { LATAbits.LATA2 = 1; // LED on } } So I expect that the LED will blink or remain ON but it lights only few seconds at power on and then goes to off. Now I'm not connected with debugger, I programmed the pic and I'm supplying it with an external source. |
|
|
|
|
|
|
|
谢谢,在主循环中,Apple Value= Read StAdCyValuy()被放置在MnLead的检查前:(1){类比值=Read AdcCyValuy();如果(类比值& lt;min级别){LATABIT.LATA2=1;//LED上的α-DelayyMs(500);LababITS.LATA2=0;//led Off-Y-DelayyMS(500);} {LATabIT.LATA2=1;/led在}}上
以上来自于百度翻译 以下为原文 Thanks, in the main loop AnalogueValue = Read_ADC_Value() is placed before the check with MINLEVEL: while(1) { AnalogValue = Read_ADC_Value(); if (AnalogValue < MINLEVEL) { LATAbits.LATA2 = 1; // LED on __delay_ms(500); LATAbits.LATA2 = 0; // LED off __delay_ms(500); } else { LATAbits.LATA2 = 1; // LED on } } } |
|
|
|
*现在好了。不知道为什么它不工作-也许重新检查你的ADC设置
以上来自于百度翻译 以下为原文 *now* ok. Not sure why it's not working - maybe re-check your ADC settings |
|
|
|
这不是“定义变量”。它定义了一个常量。你试过用一个常量替换变量“类比值”来验证闪烁代码是否有效?
以上来自于百度翻译 以下为原文 That is not "defining a variable". It's defining a constant. Have you tried replacing the variable "AnalogValue" with a constant just to verify that the blinking code is working? |
|
|
|
|
|
|
|
@ QHB:我已经尝试分配类比值=50,而LED闪烁正确(常数MyLead是67)@ PcStPoCur:看门狗定时器被禁用,用{ PrimaMac配置文件WDTE =关闭/ /禁用看门狗定时器…但是关于未处理的中断,你是对的!!!!我正在使用比较器的中断……评论如下:现在我在ADC PIN/IN上正确地读取模拟电压。Peee=1;//启用外围中断/接口;GIE=1;//启用全局中断PIE2BIT。C1IE=1;/ /使比较器中断非常感谢,现在我必须集中注意力在比较器上,再次感谢……我希望解决方案已经找到,我会在一些全球检查后的2-3天内标记这个线程。安德列
以上来自于百度翻译 以下为原文 @ qhb : I've tried assigning AnalogValue = 50; and the LED blinks correctly (constant MINLEVEL is 67) @ PStechPaul : Watchdog timer is disabled with #pragma config WDTE = OFF // Disable Watchdog Timer ....But regarding unhandled interrupt, you're right!!! I was using interrupt for comparator...and commenting as follows now I'm correctly reading analog voltage on ADC pin //INTCONbits.PEIE=1; // Enable peripheral interrupt //INTCONbits.GIE=1; // enable global interrupt PIE2bits.C1IE=1; // enable the Comparator interrupt Thank you very much, now I've to concentrate on comparator Thanks again for the moment...I hope the solution has been found, I'll mark the thread as solved in 2-3 days after some global checks. Andrea |
|
|
|
好的,我可以考虑这个问题,正如我在上文中解释的那样。谢谢你。
以上来自于百度翻译 以下为原文 ok, I can consider the issue solved as I explained in the post above. thank you all Andrea |
|
|
|
只有小组成员才能发言,加入小组>>
4837 浏览 9 评论
1842 浏览 8 评论
1756 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
2967 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2071 浏览 5 评论
467浏览 1评论
1120浏览 1评论
300浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
371浏览 0评论
268浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-5-5 11:44 , Processed in 0.817431 second(s), Total 55, Slave 49 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号