GD32F450发现ADC采集会出现阶梯状,使用高精度电源以0.01V的变化从0V上升到3.3V过程中(或者使用单片机自身DAC输出),ADC的任意模块、任意通道采集到的值会出现恒定不变情况。例如外部电源电压从0.59V变化到0.63V过程中,ADC采集值在某个区间一直无变化。整个过程其他电压点也会出现类似的情况。单片机的ADC寄存器值不变。此现象目前只出现于GD32F4系列单片机。用了GD32F450、GD32F407、GD32F103、105等单片机。F1系列则无此现象。
求助于大神。可有解。
void dac_init()
{
rcu_periph_clock_enable(RCU_DAC); //打开DAC时钟
dac_deinit();
/* once enabled the DAC, the corresponding GPIO pin is connected to the DAC converter automatically */
gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_4);
/* configure the DAC0 */
dac_trigger_source_config(DAC0, DAC_TRIGGER_SOFTWARE); //DAC触发源
dac_trigger_enable(DAC0); //触发使能
dac_wave_mode_config(DAC0, DAC_WAVE_DISABLE); // DAC噪声波模式
dac_output_buffer_enable(DAC0);
/* enable DAC0 for DAC0 */
dac_enable(DAC0);
}
void adc_init(void)
{
/* enable ADC clock */
rcu_periph_clock_enable(RCU_ADC0);
/* config ADC clock */
adc_clock_config(ADC_ADCCK_PCLK2_DIV6);
/* enable GPIOA clock */
rcu_periph_clock_enable(RCU_GPIOA);
/* config the GPIO as analog mode, for ADC */
gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_0);
/* reset ADC */
adc_deinit();
/* ADC mode config */
adc_sync_mode_config(ADC_SYNC_MODE_INDEPENDENT); //ADC独立模式
/* ADC contineous function disable */
adc_special_function_config(ADC0, ADC_CONTINUOUS_MODE, DISABLE); //关闭连续模式
/* ADC scan mode disable */
adc_special_function_config(ADC0, ADC_SCAN_MODE, DISABLE); //关闭扫描模式
/* 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); //1个转换在规则序列中 也就是只转换规则序列1
/* ADC trigger config */
adc_external_trigger_source_config(ADC0, ADC_REGULAR_CHANNEL, ADC_EXTTRIG_REGULAR_T0_CH0);
adc_external_trigger_config(ADC0, ADC_REGULAR_CHANNEL, EXTERNAL_TRIGGER_DISABLE); //规则组外部触发关闭
/* enable ADC interface */
adc_enable(ADC0);
delay_xms(1U);
/* ADC calibration and reset calibration */
adc_calibration_enable(ADC0); //校准ADC0
}
void getADCV()
{
static u16 DacOut = 730;
float adcU;
u16 adcV;
DacOut++;
dac_data_set(DAC0, DAC_ALIGN_12B_R, DacOut); //12位右对齐
dac_software_trigger_enable(DAC0); //DAC软件触发
delay_xms(100);
adcV = adc_channel_sample(ADC0,0);
adcU = (adcV*3.286 )/ 4096;
printf("DacOut:%d ADC:%d U:%.3f\r\n",DacOut,adcV,adcU);
}
|