本帖最后由 pltczw666 于 2022-5-3 23:20 编辑
请教各位大侠:ADC双通道同步采样该怎么设置?
以下是我的代码,不知哪里弄错了,请帮忙指导。谢谢。
void adc_config(void)
{
/* system clocks configuration */
adc_rcu_config();
/* GPIO configuration */
adc_gpio_config();
/* TIMER configuration */
adc_timer_config();
/* DMA configuration */
// adc_dma_config();
/* ADC SCAN function enable */
adc_special_function_config(ADC0, ADC_SCAN_MODE, ENABLE);
adc_special_function_config(ADC0, ADC_CONTINUOUS_MODE, DISABLE);
adc_special_function_config(ADC1, ADC_SCAN_MODE, ENABLE);
adc_special_function_config(ADC1, ADC_CONTINUOUS_MODE, DISABLE);
/* ADC trigger config */
adc_external_trigger_source_config(ADC0, ADC_INSERTED_CHANNEL, ADC0_1_2_EXTTRIG_INSERTED_NONE);
adc_external_trigger_source_config(ADC1, ADC_INSERTED_CHANNEL, ADC0_1_2_EXTTRIG_INSERTED_NONE);
/* ADC mode config */
adc_mode_config(ADC_MODE_FREE);
/* ADC data alignment config */
adc_data_alignment_config(ADC0, ADC_DATAALIGN_RIGHT);
adc_data_alignment_config(ADC1, ADC_DATAALIGN_RIGHT);
/* ADC channel length config */
adc_channel_length_config(ADC0, ADC_INSERTED_CHANNEL, 1);
adc_channel_length_config(ADC1, ADC_INSERTED_CHANNEL, 1);
/* ADC temperature sensor channel config */
adc_inserted_channel_config(ADC0, 0, ADC_CHANNEL_16, ADC_SAMPLETIME_28POINT5);
/* ADC internal reference voltage channel config */
adc_inserted_channel_config(ADC1, 0, ADC_CHANNEL_17, ADC_SAMPLETIME_28POINT5);
/* ADC trigger config */
adc_external_trigger_source_config(ADC0, ADC_INSERTED_CHANNEL, ADC0_1_EXTTRIG_INSERTED_T1_CH0);
adc_external_trigger_source_config(ADC1, ADC_INSERTED_CHANNEL, ADC0_1_EXTTRIG_INSERTED_T1_CH0);
/* ADC external trigger enable */
adc_external_trigger_config(ADC0, ADC_INSERTED_CHANNEL, ENABLE);
adc_external_trigger_config(ADC1, ADC_INSERTED_CHANNEL, ENABLE);
/* ADC temperature and Vrefint enable */
adc_tempsensor_vrefint_enable();
/* 64 times sample, 2 bits shift */
adc_oversample_mode_config(ADC0, ADC_OVERSAMPLING_ALL_CONVERT, ADC_OVERSAMPLING_SHIFT_2B, ADC_OVERSAMPLING_RATIO_MUL64);
adc_oversample_mode_enable(ADC0);
adc_oversample_mode_config(ADC1, ADC_OVERSAMPLING_ALL_CONVERT, ADC_OVERSAMPLING_SHIFT_2B, ADC_OVERSAMPLING_RATIO_MUL64);
adc_oversample_mode_enable(ADC1);
/* clear the ADC flag */
adc_interrupt_flag_clear(ADC0, ADC_INT_FLAG_EOC);
adc_interrupt_flag_clear(ADC0, ADC_INT_FLAG_EOIC);
adc_interrupt_flag_clear(ADC1, ADC_INT_FLAG_EOC);
adc_interrupt_flag_clear(ADC1, ADC_INT_FLAG_EOIC);
/* enable ADC interrupt */
// adc_interrupt_enable(ADC0, ADC_INT_EOIC);
// adc_interrupt_enable(ADC1, ADC_INT_EOIC);
/* enable ADC interface */
adc_enable(ADC0);
delay(1); //delay 1ms
/* ADC calibration and reset calibration */
adc_calibration_enable(ADC0);
/* enable ADC interface */
adc_enable(ADC1);
delay(1); //delay 1ms
/* ADC calibration and reset calibration */
adc_calibration_enable(ADC1);
}
|
|