ADC初始化函数void ADC_Configuration(void)
{
/* ADC channel length config */
adc_channel_length_config(ADC_REGULAR_CHANNEL, 2);
/* ADC regular channel config */
adc_regular_channel_config(1, ADC_CHANNEL_10, ADC_SAMPLETIME_239POINT5); //USB 5V
adc_regular_channel_config(2, ADC_CHANNEL_4, ADC_SAMPLETIME_239POINT5); //BAT 12V
/* ADC external trigger enable */
adc_external_trigger_config(ADC_REGULAR_CHANNEL, ENABLE);
/* ADC external trigger source config */
adc_external_trigger_source_config(ADC_REGULAR_CHANNEL, ADC_EXTTRIG_REGULAR_SWRCST);
/* ADC data alignment config */
adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
/* ADC discontinuous mode */
//adc_discontinuous_mode_config(ADC_REGULAR_CHANNEL,1);
/* enable ADC interface */
adc_enable();
/* ADC calibration and reset calibration */
adc_calibration_enable();
/* ADC software trigger enable */
//adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
}
//使用ADC通道4和10,应用函数如下:
..... fun()
{
Sysinfo.vbat_detect_ctr = 0;
adc_software_trigger_enable(ADC_REGULAR_CHANNEL); //第1次测量USB 5V
while(adc_flag_get(ADC_FLAG_EOC)==RESET) ;
tmp = adc_regular_data_read();
Sysinfo.vusb_value = 6.6;
Sysinfo.vusb_value *= tmp;
Sysinfo.vusb_value /= 4096;
adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
while(adc_flag_get(ADC_FLAG_EOC)==RESET) ;
adc_flag_clear(ADC_FLAG_STRC);
tmp = adc_regular_data_read();
Sysinfo.vbat_value = 17.886;
Sysinfo.vbat_value *= tmp;
Sysinfo.vbat_value /= 4096;
}
规则通道 第1个通道CH_10的数据可以正确采集到,但是第2个通道CH4的数据无法采集正确。官网的例子找不到相关信息,难道一定要弄DMA输出? 各位帅哥多多指教啊。 |