4881 views|4 replies

931

Posts

3

Resources
The OP
 

【GD32E503 Evaluation】 ADC Experiment (Continued) [Copy link]

 

After testing the ADC conversion of the internal temperature and reference voltage, the ADC test on the board was then started. The manufacturer provided four ADC-related examples. The first one is the test of the internal temperature and reference voltage. The other three are follow-up mode, regular parallel mode and channel differential mode (see the figure below):

I compiled and downloaded the examples of the above three modes separately, but when running the sample code, no matter how I adjusted the potentiometer of the ADC test, the value would not change accordingly (see the figure below):

The following figure shows the data read in channel differential mode:

Looking at the code, the channel pins enabled by ADC in the three examples are PC2 and PC3, rather than the PA1 and PA2 pins given in the circuit diagram. The following figure is a screenshot of the GPIO configuration code:

The following figure shows that ADC1 (connected to a potentiometer) is connected to the PA1 pin, and the external input (or DAC) is connected to the PA2 pin:

I tried to refer to the sample code and display the ADC conversion value on the screen and display the value change through the graph while sending the ADC conversion value through the serial port. Since the ADC conversion value only changes slightly, the graph display is not intuitive (see the figure below):

I tried to enable ADC1 and ADC2 on the board by modifying the code, and first analyzed the relevant functions of ADC configuration (see the figure below):

First, modify the GPIO configuration to PA1 and PA2:

void gpio_config(void)
{
    /* configure the GPIO as analog mode */
//    gpio_init(GPIOC, GPIO_MODE_AIN, GPIO_OSPEED_MAX, GPIO_PIN_2|GPIO_PIN_3);
    gpio_init(GPIOA, GPIO_MODE_AIN, GPIO_OSPEED_MAX, GPIO_PIN_1|GPIO_PIN_2);
}

At the same time, the corresponding clock is turned on:

void rcu_config(void)
{

    /* enable GPIO clock */
    rcu_periph_clock_enable(RCU_GPIOC|RCU_GPIOA);
    /* enable ADC0 clock */
    rcu_periph_clock_enable(RCU_ADC0);
    /* enable ADC1 clock */
    rcu_periph_clock_enable(RCU_ADC1);
    /* enable DMA0 clock */
    rcu_periph_clock_enable(RCU_DMA0);
    /* enable TIMER1 clock */
    rcu_periph_clock_enable(RCU_TIMER1);
    /* configure ADC clock */
    rcu_adc_clock_config(RCU_CKADC_CKAPB2_DIV6);
//    rcu_adc_clock_config(RCU_CKADC_CKAPB2_DIV12);
}

The configuration of ADC is modified as follows:

void adc_config(void)
{
    /* enable ADC continous function 启用ADC连续功能 */
    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);
    /* configure ADC data alignment 配置ADC数据对齐 */
    adc_data_alignment_config(ADC0, ADC_DATAALIGN_RIGHT);
//    adc_data_alignment_config(ADC1, ADC_DATAALIGN_RIGHT);  
    /* configure ADC mode 配置ADC模式 */
    adc_mode_config(ADC_DAUL_REGULAL_FOLLOWUP_FAST);
    
    /* configure ADC channel length 配置ADC通道长度 */
    adc_channel_length_config(ADC0, ADC_REGULAR_CHANNEL, 2);
//    adc_channel_length_config(ADC1, ADC_REGULAR_CHANNEL, 2);
    /* configure ADC regular channel 配置ADC常规通道 */
    adc_regular_channel_config(ADC0, 0, ADC_CHANNEL_1, ADC_SAMPLETIME_55POINT5);
	adc_regular_channel_config(ADC0, 1, ADC_CHANNEL_2, ADC_SAMPLETIME_55POINT5);
//    adc_regular_channel_config(ADC0, 0, ADC_CHANNEL_12, ADC_SAMPLETIME_55POINT5);
//    adc_regular_channel_config(ADC0, 1, ADC_CHANNEL_13, ADC_SAMPLETIME_55POINT5);
//    adc_regular_channel_config(ADC1, 0, ADC_CHANNEL_13, ADC_SAMPLETIME_55POINT5);
//    adc_regular_channel_config(ADC1, 1, ADC_CHANNEL_12, ADC_SAMPLETIME_55POINT5);
    /* configure ADC trigger 配置ADC触发器 */
    adc_external_trigger_source_config(ADC0, ADC_REGULAR_CHANNEL, ADC0_1_EXTTRIG_REGULAR_T1_CH1);
//    adc_external_trigger_source_config(ADC1, ADC_REGULAR_CHANNEL, ADC0_1_2_EXTTRIG_REGULAR_NONE);
    /* enable ADC external trigger 启用ADC外部触发器 */
    adc_external_trigger_config(ADC0, ADC_REGULAR_CHANNEL, ENABLE);
//    adc_external_trigger_config(ADC1, ADC_REGULAR_CHANNEL, ENABLE);

    /* enable ADC interface 启用ADC接口 */
    adc_enable(ADC0);
    delay_1ms(1);
    /* ADC calibration and reset calibration ADC校准和复位校准 */
    adc_calibration_enable(ADC0);
    /* enable ADC interface 启用ADC接口 */
//    adc_enable(ADC1);
//    delay_1ms(1);
    /* ADC calibration and reset calibration ADC校准和复位校准 */
//    adc_calibration_enable(ADC1);

    /* enable ADC DMA function 启用ADC DMA功能 */
    adc_dma_mode_enable(ADC0);
	
}

Through the above modifications, compile and burn the test, the ADC value of channel 1 can change with the adjustment of the potentiometer. So far, the ADC test on the board has been successful. The figure below is a photo of the test. The two groups of data on the middle right of the screen are the values of ADC1 and ADC2 respectively. The value of ADC1 changes with the rotation of the potentiometer. ADC2 is not connected, so the value remains basically unchanged.

The following figure shows the data obtained by the serial port debugging assistant:

This post is from Domestic Chip Exchange

Latest reply

Thanks for sharing   Details Published on 2021-7-18 17:56
 
 

931

Posts

3

Resources
2
 

This is a compressed package of the test code. Due to repeated testing, there are a lot of commented codes that have not been deleted, so the code is a bit messy.

MyTest.rar (385.36 KB, downloads: 9)

This post is from Domestic Chip Exchange
 
 
 

144

Posts

0

Resources
3
 

Parsing the code is really time-consuming

This post is from Domestic Chip Exchange
 
 
 

661

Posts

0

Resources
4
 

Thanks for sharing

This post is from Domestic Chip Exchange
 
 
 

2

Posts

0

Resources
5
 

Thanks for sharing

This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list