uint16_t ADC_GetSampleAvgN(uint8_t N)
{
uint32_t avg_sample =0x00;
uint16_t adc_sample[8]={0,0,0,0,0,0,0,0};
uint8_t index=0x00;
/* 得到 N 个 ADC 采样 */
for (index=0x00; index<N; index++)
{
/* ADC 开始转换 */
ADC_SoftwareStartConv(ADC1);
/* 等待转换结束 */
while(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC) == RESET);
/* 储存 ADC 采样 */
adc_sample[index] = ADC_GetConversionValue(ADC1);
}
/* 累加 N 个 ADC 采样 */
for (index=0; index<N; index++)
{
avg_sample += adc_sample[index];
}
/* 计算 N 个 ADC 采样的均值 */
avg_sample /= N;
/* 返回均值 */
return avg_sample;
}
|