Microchip
直播中

罗兰君

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

不能用PIC12F1572读取ADC的值

大家早上好,我不能用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)

王焕树

2019-1-8 15:16:27
你使用哪种编译器?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?
 
举报

陈琳

2019-1-8 15:23:33
感谢使用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
举报

王焕树

2019-1-8 15:37:09
当你做这个测试时,RA1管脚上的电压是多少?当你这样做时,你正在断开程序员?

以上来自于百度翻译


      以下为原文

    What is the voltage on the RA1 pin when you do this test?
You are disconnecting the programmer when you do this?
 
举报

喻唯

2019-1-8 15:42:46
在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
举报

更多回帖

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