【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:
|