完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,芯片是PIC18F46K22,40引脚DIP封装,我使用的是外部XTAL OSC。我用它的ADC读取一个在它的通道0上连接的模拟信号。我已经阅读了数据表,在ADC中有2个参数,虽然我的ADC代码工作正常,但是我仍然关注以下2个参数。1)ACQT-A/D如果系统时钟是20 MHz外部晶体,那么我应该选择上述参数的值吗?我应该为上面的参数选择高值还是低值?我的代码是附加在下面的建议。任何帮助都非常感谢。
以上来自于百度翻译 以下为原文 Hello everyone My chip is PIC18F46K22, 40 pins DIP package, and i am using external XTAL Osc. of 20MHz. I am using its ADC to read an analog signal that is connected on its channel 0. I have read the datasheet and there are 2 parameters in ADC that i could not make sense of although my ADC code is working as expected but still i am concerned about the following 2 parameters. 1) ACQT - A/D Acquisition time select bits 2) ADCS - A/D Conversion Clock Select bits How should i select the values of above parameters if my system clock is 20 MHz external crystal? Should i select a high value or a low value for the above parameters? My code is appended below for suggestions. Any help is highly appreciated. void setup_routine() { ... TRISAbits.TRISA0=1; //AN0 /*Vref+ = VDD, Vref- = VSS.*/ ADCON1bits.NVCFG0 = 0; ADCON1bits.NVCFG1 = 0; ADCON1bits.PVCFG0 = 0; ADCON1bits.PVCFG1 = 0; ADCS0 = 0; ADCS1 = 1; ADCS2 = 1; ADON = 1; // ADC in turned ON ... } void ADC_data() { unsigned char acquisitiontime=100; ... ADCChannel_0(); ADFM = 0; // left justified while(acquisitiontime--); GODONE=1; while(GODONE==1); adcvalue = ADRESH; // only required to read high byte and ignore low byte. ... } |
|
相关推荐
15个回答
|
|
最安全的延迟是最长的延迟。即20TAD。假设你的源阻抗低于10K,你可以使用它们的计算,这给出7.45 U。如果你的TAD是1.6US(见上文),那么等于7.45 / 1.6=4.6个TAD周期,所以6 TAD的延迟应该很好地工作。
以上来自于百度翻译 以下为原文 The safest delay is the longest one. i.e. 20Tad. Assuming your source impedance is below 10k, you could use their calculations, which gives 7.45us. If your Tad is 1.6us (see above), then that equates to 7.45 / 1.6 = 4.6 Tad cycles, so a delay of 6 Tad should work fine. |
|
|
|
|
|
|
|
谢谢你的细节。我已经改变了我的代码,并删除了软件延迟例程获取时间,正如你所建议的。现在它如下:但是它没有给出正确的值。你能看到代码中还有什么其他问题吗?非常感谢你的帮助。
以上来自于百度翻译 以下为原文 Thanks for the details. I have changed my code and removed the software delay routine for acquisition time as you suggested. Now its as following. But its not giving correct value. Can you see what other issues are now in the code? Your help is highly appreciated. void setup_routine { ... PMD2bits.ADCMD = 0; TRISAbits.TRISA0=1; //AN0 ANSELAbits.ANSA0=1; ADCS0 = 0; // @20MHz TAD=1.6us ADCS1 = 1; // freq=Fosc/32 ADCS2 = 0; /*Vref+ = VDD, Vref- = VSS.*/ ADCON1bits.NVCFG0 = 0; ADCON1bits.NVCFG1 = 0; ADCON1bits.PVCFG0 = 0; ADCON1bits.PVCFG1 = 0; ACQT0 = 0; // Acquisition time 16 TAD = 26us ACQT1 = 1; ACQT2 = 1; ... } void ADC_data() { unsigned char adcvalue; ... ADCChannel_0(); ADFM = 0; // left justified ADON = 1; // ADC turn ON GODONE=1; while(GODONE==1); adcvalue = ADRESH; // only high byte needed. ADON = 0; ... } |
|
|
|
每次读完后,不要把ADC关掉。开始时打开它,让它打开。
以上来自于百度翻译 以下为原文 Try not turning the ADC off after every reading. Turn it on at the start, and leave it on. |
|
|
|
我也尝试过,在ADC值中它的读数为零,而ADC输入大约有2V。你知道还有什么会引起这个问题吗?或者我应该回去使用软件延迟获取时间?
以上来自于百度翻译 以下为原文 I tried this also, still its reading zero in 'adcvalue' while there is approx. 2v at the ADC input. Any idea what else could be causing the problem? Or should i go back to using software delay for acquisition time? |
|
|
|
是否有人使用自动获取时间来提供基于轮询的ADC读取的示例代码?
以上来自于百度翻译 以下为原文 can someone give a sample code for polling based ADC read using automatic acquisition time? |
|
|
|
一个延迟不会受到任何伤害,稍后你可以删除它。除了Qhb指出的打开和关闭之外,你的代码应该工作。尝试发布你的新代码…
以上来自于百度翻译 以下为原文 A delay wont' hurt anyway, you can remove it later. Apart from the turning-on and off that Qhb pointed oout, your code should work. Try posting your new code... |
|
|
|
谢谢你的回复。这里是ADC部分的代码,等待您的建议。
以上来自于百度翻译 以下为原文 Thanks for your reply. Here is the code of ADC portion. Waiting for your suggestions. void ADCChannel_0() { // Fuel Input, PIN 2, RA0 CHS0=0; CHS1=0; CHS2=0; CHS3=0; CHS4=0; } void ADC_init() { PMD2bits.ADCMD = 0; TRISAbits.TRISA0=1; //AN0 ANSELAbits.ANSA0=1; ADCS0 = 0; // @20MHz TAD=1.6us ADCS1 = 1; // freq=Fosc/32 ADCS2 = 0; // /*Vref+ = VDD, Vref- = VSS.*/ ADCON1bits.NVCFG0 = 0; ADCON1bits.NVCFG1 = 0; ADCON1bits.PVCFG0 = 0; ADCON1bits.PVCFG1 = 0; ADCChannel_0(); ADFM = 0; // left justified ACQT0 = 0; // Acquisition time 16 TAD ACQT1 = 1; ACQT2 = 1; ADON = 1; // ADC turn ON } void ADC_data() { unsigned char adcvalue; GODONE=1; while(GODONE==1){}; // it takes 1.6usec for the conversion to complete adcvalue = ADRESH; ... } |
|
|
|
听起来很好:你如何测试结果值?
以上来自于百度翻译 以下为原文 Sounds good enough: how are you testing the resulting value? |
|
|
|
我在缓冲区中写“ADCValk”,然后通过串口请求我的PC上的缓冲区值。
以上来自于百度翻译 以下为原文 I am writing the 'adcvalue' in a buffer and then requesting the buffer value on my PC via serial port. |
|
|
|
这个转换会有问题吗?你能发布这部分代码吗?
以上来自于百度翻译 以下为原文 Could it be a problem with this conversion? can you post this part of code? |
|
|
|
我已经取代了所有的代码如下,并连接一个可变电阻器上的ADC引脚,但LED上的RC1是OFF.Pls。建议我如何调试这种情况?
以上来自于百度翻译 以下为原文 I have replaced all the code with the following and connected a variable resistor on the ADC pin, but the LED on RC1 is OFF. Pls. suggest how can i debug this situation? if (adcvalue<50) PORTCbits.RC1=0; else if(adcvalue>=50 && adcvalue<100) PORTCbits.RC1=1; else if(adcvalue>=100 && adcvalue<150) PORTCbits.RC1=0; else if(adcvalue>=150 && adcvalue<200) PORTCbits.RC1=1; else if(adcvalue>=200) PORTCbits.RC1=0; |
|
|
|
|
|
|
|
你已经清除了TISISC1以使该引脚为输出吗?当你没有发布完整的程序时,我们必须不断地问这些问题。注意,你应该写信给LATC。不是PoTC开关个别引脚。
以上来自于百度翻译 以下为原文 Have you cleared TRISC1 to make that pin an output? We have to keep asking these questions when you don't post a complete program. Note, you should be writing to LATC. not PORTC to switch individual pins. |
|
|
|
抱歉,最近更新,问题不在代码,但PIC芯片有故障。
以上来自于百度翻译 以下为原文 sorry for the late update, the problem was not in the code but the PIC chip was faulty. |
|
|
|
只有小组成员才能发言,加入小组>>
5305 浏览 9 评论
2069 浏览 8 评论
1972 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3242 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2279 浏览 5 评论
827浏览 1评论
719浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
664浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
716浏览 0评论
616浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-1-25 03:43 , Processed in 1.970964 second(s), Total 103, Slave 87 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号