GD32F150 ADC问题

[复制链接]
603|1
手机看帖
扫描二维码
随时随地手机跟帖
搬砖的小蚂蚁|  楼主 | 2020-10-21 19:01 | 显示全部楼层 |阅读模式
ADC配置如下,通过PA5(AD_IN5)采集电池电压,每100ms使用adc_software_trigger_enable(ADC_REGULAR_CHANNEL)触发采集一次数据,每10个数据取中值作为电池的电压有效数据。
void adc_config(void)
{
        /* ADC CONTINUOUS function enable */
        adc_special_function_config(ADC_CONTINUOUS_MODE,DISABLE);
       
        /* ADC channel length config */
        adc_channel_length_config(ADC_REGULAR_CHANNEL,1);

        /* ADC regular channel config */
        adc_regular_channel_config(1,ADC_CHANNEL_5,ADC_SAMPLETIME_55POINT5);

        /* 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_NONE);
        /* ADC data alignment config */
        adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
        /* enable ADC interface */
        adc_enable();
        /* ADC calibration and reset calibration */
        adc_calibration_enable();       
}
第一条语句ADC_CONTINUOUS_MODE配置成disable时,采集到的是一个固定的值,配置成enable时采集的是0,用过的帮忙看下哪里配置错误了吗?感谢!串口读到的数据如下:
the Rdata is 0
the Rdata is 0
the Rdata is 0
the Rdata is 0
the Rdata is 0
the Rdata is 0
the Rdata is 0
the Rdata is 0
the Rdata is 0
the Rdata is 0
the Rdata is 0
the Rdata is 1483
the Rdata is 2417
the Rdata is 2945
the Rdata is 3219
the Rdata is 3366
the Rdata is 3437
the Rdata is 3471
the Rdata is 3491
the Rdata is 3496
the Rdata is 3498
the Rdata is 3504
the Rdata is 3503
the Rdata is 3509
the Rdata is 3511
the Rdata is 3516
the Rdata is 3522
the Rdata is 3512
the Rdata is 3510
the Rdata is 3511
the Rdata is 3507
the Rdata is 3504
the Rdata is 3503

使用特权

评论回复
sonicll| | 2020-10-22 08:56 | 显示全部楼层
本帖最后由 sonicll 于 2020-10-22 08:58 编辑

在使能ADC之后加个延迟试试?
adc_enable();
delay_1ms(100);
adc_calibration_enable();  
还有你读取RDATA是怎么操作的,检查EOC标志吗?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

9

帖子

0

粉丝