完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
您好,这是我在Microchip论坛上的第一篇文章,我非常感谢大家的帮助。我目前使用的是DSPIC33 EP512MC204微控制器,我在ADC功能方面遇到了一些问题。我配置它是在12位模式,但转换发生在10位(ADC1BUF0只包含10位)。电压基准是3.3V,而我正在接收的值确认我处于10位模式。我检查了配置寄存器和勘误表,但是我的init函数对于12位模式似乎是正确的。我尝试用10位模式配置它,同样的问题也出现了:在转换之后,我只接收8位。我需要12位来增加我的应用程序的分辨率。我正在使用的代码(见下面)是我为适应我的应用而定制的一个例子。谢谢你的帮助。玛丽
以上来自于百度翻译 以下为原文 Hello, this is my first post on the Microchip forum and I thank you all in advance for your help. I'm currently using DSPIC33EP512MC204 microcontroller and I'm experiencing some issues with the ADC feature. I configure it to be in 12 bits mode but the conversion is occuring in 10 bits (ADC1BUF0 contains only 10 bits). The voltage reference is 3.3V and the values I'm receiving confirm that I'm in a 10 bits mode. I checked the config registers and the errata but my init function seems right for a 12 bits mode. I tried to configure it in a 10 bits mode and the same problem is appearing: I receive only 8 bits after the conversion. I need 12 bits to increase the resolution of my application. The code I'm using (see below) is an example I customed to fit my application. #include #include #include "main.h" #include "adcdrv2.h" #include "tglpin.h" // ***************************************************************************** // ***************************************************************************** // Section: File Scope or Global Constants // ***************************************************************************** // ***************************************************************************** /* This section defines the input and the output buffers having a integer data type. The input buffers are stored in either the extended data space or the x-memory area depending on whether the extended data space (EDS) is available in the given dsPIC33E device. */ #ifdef _HAS_DMA_ __eds__ int bufferA[NUMSAMP] __attribute__( (eds, space(dma)) ); __eds__ int bufferB[NUMSAMP] __attribute__( (eds, space(dma)) ); #else int bufferA[NUMSAMP] __attribute__( (space(xmemory)) ); int bufferB[NUMSAMP] __attribute__( (space(xmemory)) ); #endif void ProcessADCSamples( __eds__ int *adcBuffer ); /****************************************************************************** * Function: void InitAdc1(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: This function is used to configure A/D to convert channel 5 on Timer event. It generates event to DMA on every sample/convert sequence. ADC clock is configured at 625Khz. *****************************************************************************/ void InitAdc1( void ) { AD1CON1bits.AD12B = 1; // 12 bits mode AD1CON1bits.FORM = 0; // Data Output Format: Integer AD1CON1bits.SSRC = 7; // Interan Counter (SAMC) ends sampling and starts convertion AD1CON1bits.SIMSAM = 0; AD1CON1bits.ASAM = 1; // ADC Sample Control: Sampling begins immediately after conversion AD1CON2bits.CHPS = 0; // Converts CH0/CH1 AD1CON3bits.ADRC = 0; // ADC Clock is derived from Systems Clock AD1CON3bits.SAMC = 0; // Auto Sample Time = 0*Tad AD1CON3bits.ADCS = 30; // ADC Conversion Clock AD1CON1bits.ADDMABM = 1; // DMA buffers are built in conversion order mode AD1CON2bits.SMPI = 0; // SMPI must be 0 AD1CON4bits.ADDMAEN = 1; // Converts in ADC1BUF0 AD1CHS0bits.CH0SA = 2; // MUXA +ve input selection (AIN20) for CH0 AD1CHS0bits.CH0NA = 0; // MUXA -ve input selection (Vref-) for CH0 AD1CHS0bits.CH0NB = 0; AD1CHS0bits.CH0SB = 0b000001; IFS0bits.AD1IF = 0; // Clear the A/D interrupt flag bit IEC0bits.AD1IE = 0; // Do Not Enable A/D interrupt AD1CON1bits.ADON = 1; // Turn on the A/D converter } /****************************************************************************** * Function: void InitDma0(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: DMA0 configuration function. Direction: Read from peripheral address 0-x300 (ADC1BUF0) and write to DMA RAM AMODE: Register indirect with post increment MODE: Continuous, Ping-Pong Mode IRQ: ADC Interrupt ADC stores results stored alternatively between DMA_BASE[0]/DMA_BASE[16] on every 16th DMA request *****************************************************************************/ void InitDma0( void ) { DMA0CONbits.AMODE = 0; // Configure DMA for Register indirect with post increment DMA0CONbits.MODE = 2; // Configure DMA for Continuous Ping-Pong mode DMA0PAD = ( int ) &ADC1BUF0; DMA0CNT = ( NUMSAMP - 1 ); DMA0REQ = 13; #ifdef _HAS_DMA_ DMA0STAL = __builtin_dmaoffset( &bufferA ); DMA0STAH = __builtin_dmapage( &bufferA ); DMA0STBL = __builtin_dmaoffset( &bufferB ); DMA0STBH = __builtin_dmapage( &bufferB ); #else DMA0STAL = ( unsigned int ) &bufferA; DMA0STAH = ( unsigned int ) &bufferA; DMA0STBL = ( unsigned int ) &bufferB; DMA0STBH = ( unsigned int ) &bufferB; #endif IFS0bits.DMA0IF = 0; //Clear the DMA interrupt flag bit IEC0bits.DMA0IE = 1; //Set the DMA interrupt enable bit DMA0CONbits.CHEN = 1; } unsigned int dmaBuffer = 0; #ifdef TEST_MODE unsigned char test_flag_buffA=0; unsigned char test_flag_buffB=0; #endif /****************************************************************************** * Function: void __attribute__((interrupt, auto_psv)) _DMA0Interrupt(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: Depending on the dmaBuffer value, the data in bufferA or bufferB is passed *****************************************************************************/ void __attribute__ ( (interrupt, auto_psv) ) _DMA0Interrupt( void ) { if( dmaBuffer == 0 ) { #ifdef TEST_MODE test_flag_buffA=1; #endif ProcessADCSamples( bufferA ); } else { #ifdef TEST_MODE test_flag_buffB=1; #endif ProcessADCSamples( bufferB ); } dmaBuffer ^= 1; IFS0bits.DMA0IF = 0; //Clear the DMA0 Interrupt Flag } End of File */ Thanks for your help. Marie |
|
相关推荐
3个回答
|
|
而不是只是说“我已经检查”,如何报告你所投入的和你得到的,让别人仔细检查你的计算。
以上来自于百度翻译 以下为原文 Rather than just saying "I've checked", how about reporting what you put in and what you got out to let others double check your calculations. |
|
|
|
嗨,玛丽,这2行是重复[ /代码]保持[ /代码],因为你似乎使用DMA,我建议你看看代码示例CE401和CE420。因为它们是MPLAB 8项目,只需导入它们,它们将被转换成MPLAB X项目。10个或12个比特
以上来自于百度翻译 以下为原文 Hi Marie, these 2 lines are duplicates #include #include Just keep #include As it seems you use DMA, I suggest you look at the Codeexamples CE401 and CE420. As they are MPLAB 8 projects, just import them and they will be converted into MPLAB X projects I used them successfully to have ADC & DMA operating with either 10 or 12 bits regards |
|
|
|
嗨,RISC,我遵照你的建议,用CE420例子。多亏了你,我的ADC现在用12位的DMA操作来转换数字音频信号。对于信息,CE401是我在第一个地点使用的例子。
以上来自于百度翻译 以下为原文 Hi RISC, I followed your advice and used CE420 example. Thanks to you my ADC is now operating in 12 bits with DMA to convert an audio signal in digital. For information, CE401 was the example I used in the first place. Regards. |
|
|
|
只有小组成员才能发言,加入小组>>
5184 浏览 9 评论
2005 浏览 8 评论
1932 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3179 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2230 浏览 5 评论
742浏览 1评论
628浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
512浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
640浏览 0评论
538浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-28 22:17 , Processed in 1.384537 second(s), Total 80, Slave 63 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号