本帖最后由 Itachi80 于 2011-7-24 10:23 编辑
读取平均值的程序如下:
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
AD_value1 = ADC_GetConversionValue(ADC1);
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
AD_value2 = ADC_GetConversionValue(ADC1);
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
AD_value3 = ADC_GetConversionValue(ADC1);
Value=(AD_value1+AD_value2+AD_value3)/3
配置如下
void ADC_Configuration(void)
{
ADC_InitTypeDef
ADC_InitStructure;
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
//ADC 工作模式 ADC1 ADC2 单独工作
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
//关闭多通道扫描模式
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //不启用启用连续转换模式
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
//触发方式为软件触发
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
//数据右对齐
ADC_InitStructure.ADC_NbrOfChannel = 3;
//ADC规则转换通道数量
ADC_Init(ADC1, &ADC_InitStructure);
/*ADC1 regular channel10 configuration */ //配置转换规则
ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 1,ADC_SampleTime_1Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 2, ADC_SampleTime_1Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 3,ADC_SampleTime_1Cycles5);
/*Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/*Enable ADC1 reset calibaration register */
ADC_ResetCalibration(ADC1);
//复位ADC1 校准
/*Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1)); //等待复位完成
/*Start ADC1 calibaration */
ADC_StartCalibration(ADC1);
//开始ADC1 校准转换
/*Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));
//等待转换完成
} |