完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我在18F4680上的A/D转换上遇到了一个奇怪的问题:使用xc8 1 34和MPLAP 3.35。他分配给“VAL”,我得到完全不同(错误)的值(0x03FF字节组成)!!我附了一个调试会话的截图。有什么想法吗?提前感谢任何帮助
以上来自于百度翻译 以下为原文 Hello all, I'm facing a really odd issue on A/D conversion on a 18F4680; using xc8 1.34 and MPLAP 3.35. This is the code: void ADC_Init(unsigned char PCFG) { // Setup ADC ADCON0 = 0b00000001; // ADON (0): A/D converter is enabled ADCON0 |= 0b00000000; // GO_nDONE (1): A/D idle NOTE: he GO/DONE bit should NOT be set in the same instruction that turns on the A/D. // ADCON0 CHS(5:2): Analog Channel Select bits - dynamically used ADCON1 = PCFG; // PCFG(3:0): A/D Port Configuration Control bits ADCON1 |= 0b00000000; // VCFG0(4): V+ ref is AVDD ADCON1 |= 0b00000000; // VCFG0(5): V- ref is AVSS ADCON2 = 0b00000010; // ADCS (2:0): Fosc/32 (A/D conversion clock for 40MHz) ADCON2 |= 0b00010000; // ACQT4 (5:3): TAD (010 = 4 TAD) ADCON2 |= 0b10000000; // ADFM (7): Right justified } unsigned int ADC_Read(unsigned char channel) { if (channel > 7) // Channel range must be within 0 ~ 7 return 0; ADCON0 &= 0b11000001; // Clear channel selection bits - CHS(5:2) & the GO_nDONE bit ADCON0 |= (channel << 3); // Set channel selection bits // Since we programmed the Automatic Acquisition Time (ACQT4 in ADC_Init()), we don't need to wait for the capacitor to charge //__delay_ms(2); // Acquisition time to charge hold capacitor DELAY_mS(2); GO_nDONE = 1; // Start the A/D conversion while (GO_nDONE); // Wait for conversion to complete // test code BREAKPOINT>>> unsigned int val = (((unsigned int)ADRESH) << 8) + ADRESL; return val; //return (((unsigned int)ADRESH) << 8) + ADRESL; // Return result } void main() { PIE1 = 0; // Disable TMR1/TMR2/CCP1/MSSP/ESUART txrx/AD/PSP peripheral interrupts PIE2 = 0; // Disable ECCP1IE/TMR3IE/HLVDIE/BCLIE/EEIE/CMIE/OSCFIE peripheral interrupts INTCONbits.PEIE = 0; // When RCON.IPEN = 0 disables all Peripheral interrupts INTCONbits.GIE = 0; // When RCON.IPEN = 0 disables all Global interrupts // Setup ADC ADC_Init(0b00001010); // PCFG(3:0): AN0->4 = Analog, all other digital while (1) { DELAY_mS(800); unsigned int val = ADC_Read(1); } } The issue is simple: eventhough I can see that ADRESH:ADRESL (0x19:0x36) have correct values (if I set a breakpoint on where I wrote "BREAKPOINT>>>"), when I step trough the assignment to "val", I get completely different (wrong) values (0x03FF after byte composition)!! I attached a screenshot of a debugging session. Any ideas on why? Thanks in advance for any help Gianni Attached Image(s) |
|
相关推荐
1个回答
|
|
复制-HTTP://www. McCHIP.COM/FUMMS/M945 987.ASPX请继续讨论到一个论坛。苏珊
以上来自于百度翻译 以下为原文 Duplicate - http://www.microchip.com/forums/m945987.aspx Please keep the discussion to one forum. Susan |
|
|
|
只有小组成员才能发言,加入小组>>
5162 浏览 9 评论
2000 浏览 8 评论
1928 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3172 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2226 浏览 5 评论
731浏览 1评论
613浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
503浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
629浏览 0评论
527浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-23 06:47 , Processed in 1.265289 second(s), Total 77, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号