stm32 adc多通道采集各通道会相互影响

2019-08-16 23:43发布

求助。用DMA方式进行双通道ADC转换,给其中一个通道的电压,这个通道AD转换完全正确,但是为什么另一个通道的电压值也会变化。原本以为AD采样太快,但是增加了采样时间还是会有这个问题。 [mw_shl_code=c,true]#include "adc_dma.h" //#include "delay.h" u16 __IO AD_Value[2]; void ADC1_Init(void) { ADC1_GPIO_Config(); ADC1_DMA_Config(); ADC1_Mode_Config(); } static void ADC1_GPIO_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN; GPIO_Init(GPIOC,&GPIO_InitStructure); } static void ADC1_DMA_Config(void) { DMA_InitTypeDef DMA_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE); DMA_DeInit(DMA1_Channel1); DMA_InitStructure.DMA_PeripheralBaseAddr=(u32)&ADC1->DR; DMA_InitStructure.DMA_MemoryBaseAddr=(u32)&AD_Value; DMA_InitStructure.DMA_DIR=DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize=2; DMA_InitStructure.DMA_PeripheralInc=DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc=DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize=DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize=DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode=DMA_Mode_Circular; DMA_InitStructure.DMA_Priority=DMA_Priority_Medium; DMA_InitStructure.DMA_M2M=DMA_M2M_Disable; DMA_Init(DMA1_Channel1,&DMA_InitStructure); DMA_Cmd(DMA1_Channel1, ENABLE); } static void ADC1_Mode_Config(void) { ADC_InitTypeDef ADC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE); RCC_ADCCLKConfig(RCC_PCLK2_Div8); ADC_DeInit(ADC1); ADC_InitStructure.ADC_Mode=ADC_Mode_Independent; ADC_InitStructure.ADC_ContinuousConvMode=ENABLE; ADC_InitStructure.ADC_ScanConvMode=ENABLE; ADC_InitStructure.ADC_ExternalTrigConv=ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign=ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel=2; ADC_Init(ADC1,&ADC_InitStructure); ADC_RegularChannelConfig(ADC1,ADC_Channel_10,1,ADC_SampleTime_239Cycles5); ADC_RegularChannelConfig(ADC1,ADC_Channel_11,2,ADC_SampleTime_239Cycles5); ADC_Cmd(ADC1,ENABLE); ADC_DMACmd(ADC1,ENABLE); ADC_ResetCalibration(ADC1); while(ADC_GetResetCalibrationStatus(ADC1)); ADC_StartCalibration(ADC1); while(ADC_GetCalibrationStatus(ADC1)); ADC_SoftwareStartConvCmd(ADC1, ENABLE); } u16 get_ChannelVale(u8 ADC_Channel) { u16 ret = 0; switch(ADC_Channel) { case ADC_Channel_10: ret = AD_Value[0]; break; case ADC_Channel_11: ret = AD_Value[1]; break; } return ret; }[/mw_shl_code] [mw_shl_code=c,true]#include "led.h" #include "delay.h" #include "sys.h" #include "lcd.h" #include "usart.h" #include "adc_dma.h" extern __IO u16 AD_Value[2]; int main(void) { u16 adcx; float temp; delay_init(); //???±?????????? NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//?è????????????·?×é??×é2??2??????????????2???ì???????? uart_init(115200); //?®??????????115200 LED_Init(); //LED?????????? LCD_Init(); ADC1_Init(); //ADC?????? POINT_COLOR=RED;//?è??×??????ì?? LCD_ShowString(60,50,200,16,16,"WarShip STM32 ^_^"); LCD_ShowString(60,70,200,16,16,"ADC TEST"); LCD_ShowString(60,90,200,16,16,"ATOM@ALIENTEK"); LCD_ShowString(60,110,200,16,16,"2015/10/30"); //?????á?????? POINT_COLOR=BLUE;//?è??×????????? LCD_ShowString(60,130,200,16,16,"ADC_CH0_VAL:"); LCD_ShowString(60,150,200,16,16,"ADC_CH0_VOL:0.000V"); POINT_COLOR=GREEN;//?è??×????????? LCD_ShowString(60,170,200,16,16,"ADC_CH1_VAL:"); LCD_ShowString(60,190,200,16,16,"ADC_CH1_VOL:0.000V"); while(1) { POINT_COLOR=BLUE;//?è??×????????? adcx=get_ChannelVale( ADC_Channel_10); LCD_ShowxNum(156,130,adcx,4,16,0);//????ADC???? temp=(float)adcx*(3.3/4096); adcx=temp; LCD_ShowxNum(156,150,adcx,1,16,0);//?????????? temp-=adcx; temp*=1000; LCD_ShowxNum(172,150,temp,3,16,0X80); POINT_COLOR=GREEN;//?è??×????????? adcx=get_ChannelVale( ADC_Channel_11); LCD_ShowxNum(156,170,adcx,4,16,0);//????ADC???? temp=(float)adcx*(3.3/4096); adcx=temp; LCD_ShowxNum(156,190,adcx,1,16,0);//?????????? temp-=adcx; temp*=1000; LCD_ShowxNum(172,190,temp,3,16,0X80); LED2_REV; delay_ms(250); } }[/mw_shl_code]



友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。