用ADC采样内部vref,电源3.8V左右。连续采样,出来的结果偶尔会出现800+的数值,正常是320左右
例如:
adc:320
adc:812
adc:320
adc:320
adc:321
adc:321
adc:321
是什么原因,如何避免?
电源是锂电池,电压比较稳定,用示波器观察没有纹波或者跳变。
采样程序如下
int adcConvert(unsigned char averageTime){
ADC_DiscModeChannelCountConfig(ADC1, 1);
ADC_RegularChannelConfig(ADC1, 8, 1, ADC_SampleTime_241Cycles);
ADC1->CTLR2|=((uint32_t)0x00e0000); //SWSTART_SEL
for(unsigned char x=0;x<=averageTime;x++){
ADC1->CTLR2|=((uint32_t)0x00400000); //start convert;
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));
int adc;
adc=ADC_GetConversionValue(ADC1);
printf("adc:%d\n",adc);;
result+=adc;
if(x==0)result=0;
}
return result/averagetime;