完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
我使用的MCU为ADuC7061,我使用主ADC,配置为单端模式、转换速率4Hz、使用内部基准电压源1.2V、主ADC增益为1,使用ADC3通道。我出现的故障是我ADC3的电压为0.59V,但是经ADC转换后却出现主ADC转换错误ADC0DAT里面值为0x00,ADCSTA的值为0x1000.请问大侠这是怎么回事?下面附上我的程序
************************************************************************************************/ #include # include "stdio.h" # include "string.h" // Bit Definitions #define BIT0 0x01 #define BIT1 0x02 #define BIT2 0x04 #define BIT3 0x08 #define BIT4 0x10 #define BIT5 0x20 #define BIT6 0x40 #define BIT7 0x80 #define BIT8 0x100 #define BIT9 0x200 #define BIT10 0x400 #define BIT11 0x800 #define BIT12 0x1000 #define BIT13 0x2000 #define BIT14 0x4000 #define BIT15 0x8000 volatile unsigned char bSendResultToUART = 0; // Flag used to indicate ADC3 resutl ready to send to UART unsigned char szTemp[16] = ""; // Used to store ADC3 result before printing to UART unsigned char ucTxBufferEmpty = 0; // Used to indicate that the UART Tx buffer is empty volatile unsigned long ulADC0Result = 0; // Variable that ADC0DAT is read into in ADC0 IRQ //函数声明 void ADC0Init(void); void UARTInit(void); void Delay(int a); /****************************************************************************** 函数名 : int main(void) 描述 : 主函数 输入 : void 输出 : void 返回 : *******************************************************************************/ int main(void) { unsigned char i = 0; unsigned char nLen = 0; POWKEY1 = 0x1; POWCON0 = 0x78; // Set core to max CPU speed of 10.24Mhz POWKEY2 = 0xF4; UARTInit() ADC0Init(); IRQEN = BIT10 + BIT11; // Enable ADC and UART interrupts bSendResultToUART = 0; while (1) { } } /****************************************************************************** 函数名 : void IRQ_Handler(void) __irq 描述 : IRQ中断服务程序 输入 : void 输出 : void 返回 : void *******************************************************************************/ void IRQ_Handler(void) __irq { unsigned long IRQSTATUS = 0; unsigned char ucCOMIID0 = 0; IRQSTATUS = IRQSTA; // Read off IRQSTA register if ((IRQSTATUS BIT11) == BIT11) //UART interrupt source { ucCOMIID0 = COMIID0; if ((ucCOMIID0 0x2) == 0x2) // Transmit buffer empty { ucTxBufferEmpty = 1; } } if ((IRQSTATUS BIT10) == BIT10) //If ADC0 interrupt source { ulADC0Result = ADC0DAT; // Read ADC0 conversion result bSendResultToUART = 1; } } /****************************************************************************** 函数名 : ADC0Init() 描述 : 初始化ADuC7061的主ADC 输入 : void 输出 : void 返回 : void *******************************************************************************/ void ADC0Init(void) { // // Configure ADC0 for continuous conversions, 4hz, AIN3 in Single-ended mode // ADCMSKI = BIT0; // Enable ADC0 result ready interrupt source ADCFLT = 0xFF1F; // Chop on, Averaging, AF=63, SF=31, 4Hz ADCCFG = 0; ADC0CON = BIT6 + BIT7 + BIT8 + // ADC3/ADC5(单端模式),AIN3,使用内部基准电压1.2V。 BIT10 + // Unipolar ADC output BIT15; // Enable Primary_ADC. ADCMDE = 0x94; // Offest Self Calibration while((ADCSTA BIT15) == BIT15){} // Wait for Calibration routine to complete ADCMDE = 0x95; // Gain Self Calibration while((ADCSTA BIT15) == BIT15){} // Wait for Calibration routine to complete ADCMDE = BIT0 + BIT4 + BIT7; // continuous conversions } /****************************************************************************** 函数名 : UARTInit() 描述 : 初始化ADuC7061的主UART 输入 : void 输出 : void 返回 : void *******************************************************************************/ void UARTInit(void) { // Initialize the UART for 9600-8-N GP1CON = BIT0 + BIT4; // Select UART functionality for P1.0/P1.1 COMCON0 = BIT7; // Enable access to COMDIV registers COMDIV0 = 0x21; // Set baud rate to 9600. COMDIV1 = 0x00; //COMDIV2 = 0x21 + BIT11; // Enable fractional divider for more accurate baud rate setting COMCON0 = BIT0 + BIT1 + BIT2; COMIEN0 = BIT0 + BIT1; // Enable UART interrupts when Rx full and Tx buffer empty. } /****************************************************************************** 函数名 : void Delay(int a) 描述 : 延时函数 输入 : int a 输出 : void 返回 : void *******************************************************************************/ void Delay(int a) { int i,j; for(i = 1 ; i < a ; i++) for(j = 1 ; j < 1000 ; j++); } |
|
相关推荐
1个回答
|
|
|
根据您提供的信息,可能有几个原因导致您遇到的问题:
1. ADC引脚连接错误:请确保ADC3通道的引脚连接正确,没有接错或接触不良。 2. ADC配置错误:请仔细检查您的ADC配置是否正确,包括单端模式和转换速率等。 3. 参考电压源问题:请检查使用的内部基准电压源1.2V是否正常工作,确认其输出电压稳定且正确。 4. GPIO配置错误:请确保ADC3通道对应的GPIO口已正确配置为 ADC 输入模式。 5. MCU内部故障:如果以上问题都没有找到错误,那么可能是MCU本身出现了故障。您可以尝试重新烧录程序或更换一个MCU进行测试。 综上所述,您可以逐一检查以上可能的原因,找到并解决问题。如果问题仍然存在,建议查看MCU的手册或与相关厂商的技术支持联系以获取更多帮助。 |
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
265 浏览 0 评论
【原创】【RA4M2-SENSOR开发板评测】低功耗+USB综合测试
789 浏览 0 评论
1306 浏览 2 评论
787 浏览 0 评论
【RA4M2-SENSOR开发板评测】Analogue+Timers综合测试
1587 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
16901 浏览 31 评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 02:23 , Processed in 0.787379 second(s), Total 72, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
524