void adc_config(void)
{
adc_rcu_config();
adc_gpio_config();
/* ADC mode config */
adc_mode_config(ADC_MODE_FREE);
/* ADC data alignment config */
adc_data_alignment_config(ADC0, ADC_DATAALIGN_RIGHT);
/* ADC channel length config */
adc_channel_length_config(ADC0, ADC_REGULAR_CHANNEL, 1U);
/* ADC trigger config */
adc_external_trigger_source_config(ADC0, ADC_REGULAR_CHANNEL, ADC0_1_2_EXTTRIG_REGULAR_NONE);
/* ADC external trigger config */
adc_external_trigger_config(ADC0, ADC_REGULAR_CHANNEL, ENABLE);
adc_tempsensor_vrefint_enable();
/* enable ADC interface */
adc_enable(ADC0);
delay_1ms(1U);
/* ADC calibration and reset calibration */
//adc_calibration_enable(ADC0);
}
uint16_t adc_channel_sample(uint8_t channel)
{
/* ADC regular channel config */
adc_regular_channel_config(ADC0, 0U, channel, ADC_SAMPLETIME_71POINT5);
/* ADC software trigger enable */
adc_software_trigger_enable(ADC0, ADC_REGULAR_CHANNEL);
/* wait the end of conversion flag */
while (!adc_flag_get(ADC0, ADC_FLAG_EOC))
;
/* clear the end of conversion flag */
adc_flag_clear(ADC0, ADC_FLAG_EOC);
/* return regular channel sample value */
return (adc_regular_data_read(ADC0));
}
vref = 1200 * 4096 / getExternalChannel(ADC_CHANNEL_17);
每次都执行一下adc_config后再读取adc的值
不注释掉这行的结果
//adc_calibration_enable(ADC0);
vref=2958.58
vref=2939.30
vref=2936.66
vref=2936.66
vref=2945.82
vref=2901.98
vref=2911.15
vref=2940.38
vref=2955.25
vref=2966.47
vref=2936.13
vref=2911.42
注释掉这行的结果
//adc_calibration_enable(ADC0);
vref=2948.36
vref=2947.16
vref=2947.68
vref=2947.56
vref=2947.76
vref=2947.53
vref=2947.79
vref=2947.48
vref=2947.73
怎么不开校准数据还更稳定了。。。 |