大家帮我看看 小弟我单独设置一路AD通道 读取的值是OK的, 但是我多添加几路AD后,读取的AD值就不停的跳变 是不是我读取的方法有问题 请大家帮我指正一下 谢谢!
#include "ADC.h"
__IO uint16_t ADC1ConvertedValue1 = 0,ADC1ConvertedValue2 = 0,
ADC1ConvertedValue3 = 0,ADC1ConvertedValue4 = 0,
ADC1ConvertedValue5 = 0;
void Get_ADC_Data(void)
{
static __IO uint16_t count;
uint16_t temp;
if(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) != RESET)
{ temp= ADC_GetConversionValue(ADC1);
if((++count)>5)
count=1;
switch(count)
{ case 1:
ADC1ConvertedValue1=temp;
break;
case 2:
ADC1ConvertedValue2=temp;
break;
case 3:
ADC1ConvertedValue3=temp;
break;
case 4:
ADC1ConvertedValue4=temp;
break;
case 5:
ADC1ConvertedValue5=temp;
break;
default:
ADC1ConvertedValue1=0;
ADC1ConvertedValue2=0;
ADC1ConvertedValue3=0;
ADC1ConvertedValue4=0;
ADC1ConvertedValue5=0;
break;
}
}
}
void ADC1_Config(void)
{
ADC_InitTypeDef ADC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* ADC1 Configuration *******************************************************/
/* ADCs DeInit */
ADC_DeInit(ADC1);
/* GPIOA Periph clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* ADC1 Periph clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
/* Configure ADC Channel_11 as analog input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Initialize ADC structure */
ADC_StructInit(&ADC_InitStructure);
/* Configure the ADC1 in continous mode withe a resolutuion equal to 12 bits*/
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward; //ÏòǰɨÃè 0-18
ADC_Init(ADC1, &ADC_InitStructure);
/* Convert the ADC1 Channel 11 with 13.5 Cycles as sampling time */
ADC_ChannelConfig(ADC1, ADC_Channel_0, ADC_SampleTime_28_5Cycles);
ADC_ChannelConfig(ADC1, ADC_Channel_1, ADC_SampleTime_28_5Cycles);
ADC_ChannelConfig(ADC1, ADC_Channel_2, ADC_SampleTime_28_5Cycles);
ADC_ChannelConfig(ADC1, ADC_Channel_3, ADC_SampleTime_28_5Cycles);
ADC_ChannelConfig(ADC1, ADC_Channel_4, ADC_SampleTime_28_5Cycles);
/* ADC Calibration */
ADC_GetCalibrationFactor(ADC1); //adjust adc
/* Enable ADCperipheral[PerIdx] */
ADC_Cmd(ADC1, ENABLE);
/* Wait the ADCEN falg */
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN));
/* ADC1 regular Software Start Conv */
ADC_StartOfConversion(ADC1);
}
|