2863 views|0 replies

9

Posts

0

Resources
The OP
 

[GD32F310G-START Review] Review 3: GD32F301 Development Board ADC Module [Copy link]

This post was last edited by cjwmusic on 2022-6-21 04:09

Overview

  • Successive approximation method
  • 12-bit resolution (configurable to 12, 10, 8, 6 bits)
  • Watchdog detection
  • 16 external channels, 2 internal channels, battery voltage channel
  • Conversion mode: single, continuous, scan, intermittent
  • Conversion result: 16 bits, left-aligned/right-aligned
  • Hardware oversampling mechanism

experiment

In this ADC experiment, a 10K 3296 packaged sliding resistor is used to simulate the external, variable analog signal input, which is input into the analog input pin of GD32. After internal conversion, the converted digital result is displayed on the LCD.

Analog circuit schematic diagram

RV1 is a sliding resistor with a maximum resistance of 100K. Pin 2 outputs a variable voltage to the analog pin of the GD32 microcontroller.

R1 is a 10K resistor that serves as a current limiter.

For the convenience of the experiment, the circuit is relatively simple. The actual ADC sampling circuit also needs to add filtering and amplification circuits.

And the analog power supply should be separated from the digital power supply as much as possible. The same 3.3v power supply is used in this experiment.

Experimental circuit built on breadboard

Verification of experimental circuit

After completing the construction of the experimental circuit, while turning the adjustment knob of the sliding rheostat, use an oscilloscope to measure the voltage of pin 2 of the sliding rheostat. It is found that the voltage waveform gradually changes with the adjustment, indicating that there is no problem with the construction of the analog part of the circuit.

Software Writing

  • ADC Clock Configuration
  • ADC GPIO Configuration
  • ADC Configuration

ADC Clock Configuration

From the clock tree in the user manual, we can see that the ADC clock can come from three sources:

  • The APB2 clock is divided into
  • The AHB clock is divided into
  • IRC 28M clock frequency is obtained

Select the ADC clock source by setting the ADCSEL bit in the configuration register 2 (RCU_CFG2).

When using library functions for programming, configure through the rcu_adc_clock_config method.

The specific ADC clock configuration code is as follows:

// ADC 时钟使能
rcu_periph_clock_enable(RCU_ADC);
//ADC 时钟通过APB2时钟6分频获得
rcu_adc_clock_config(RCU_ADCCK_APB2_DIV6);

GPIO Configuration

Correspondence between ADC external input channels and GPIO pins

ADC Pins GPIO Pins
ADC_IN0 - ADC_IN7 PA0 - PA7
ADC_IN8 - ADC_IN9 PB0 - PB1

Since the PA pin is used to drive the LCD, the PB0 pin is used as the analog input in this experiment.

The ADC pin needs to be configured as input mode without pull-up or pull-down resistors.

The specific configuration code is as follows:

gpio_mode_set(GPIOB, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_0);

ADC Configuration

The configuration of ADC mainly includes:

Conversion Mode single
Alignment of conversion results Right Align
Number of conversion channels 1
External trigger configuration No external trigger required
ADC sampling accuracy 12-bit sampling accuracy
ADC sampling time configuration 55.5 clock cycles
ADC Interrupt Configuration Conversion completion triggers interrupt

The specific code is as follows:

    // 单通道用连续转换模式
    adc_special_function_config(ADC_CONTINUOUS_MODE, ENABLE);
    // 转换结果转换右对齐
    adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
    // 转换通道1个
    adc_channel_length_config(ADC_REGULAR_CHANNEL, 1);

    // 不用外部触发转换,软件开启即可
    adc_external_trigger_config(ADC_REGULAR_CHANNEL, ENABLE);
    adc_external_trigger_source_config(ADC_REGULAR_CHANNEL, ADC_EXTTRIG_REGULAR_NONE);    
    // ADC 采样精度配置
    adc_resolution_config(ADC_RESOLUTION_12B);

    // 使能ADC
    adc_enable();
    
    delay_1ms(1);
    
    // 使能ADC校准
    adc_calibration_enable();

    // ADC 采样通道、采样时间
    adc_regular_channel_config(0, ADC_CHANNEL_7, ADC_SAMPLETIME_55POINT5);
    
    // 使能 ADC 中断
    nvic_irq_enable(ADC_CMP_IRQn, 1, 1);
    // 清除 ADC 规则组转换结束中断标志
    adc_interrupt_flag_clear(ADC_INT_FLAG_EOC);
    // 使能 ADC 规则组转换结束中断
    adc_interrupt_enable(ADC_INT_EOC);
    
    // 软件触发ADC转换
    adc_software_trigger_enable(ADC_REGULAR_CHANNEL);

Interrupt code:

void ADC_CMP_IRQHandler(void)
{
	// 清除中断标志位
    adc_interrupt_flag_clear(ADC_INT_FLAG_EOC);              
    // 读取转换结果
    adcValue = adc_regular_data_read();
    LCD_write_english_string(0, 10, "ADC Value:");
    LCD_write_number(20, 20, adcValue);
}

Final experimental results

I uploaded all the codes to github, and you can download and use them if you are interested:

https://github.com/jwkongkong/GD32-NOKIA-5110

Welcome everyone to communicate and correct ~

This post is from GD32 MCU
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
Xinhua Dictionary of Power Supply--A brief review of the book "Basics of Power Supply Design"

Xinhua Dictionary of Power Supply - A Brief Review of the Book "Basics of Power Supply Design" When I was a child, I c ...

Domestic MCU replacement: a pitfall

  As a fan of Butterfly, I feel sorry for the shortage and price increase of STM32. But whether you are making product ...

【Top Micro Intelligent Display Module】IV: Serial port interaction and application of curve, drawing board and animation controls

This post was last edited by Digital Leaf on 2021-11-21 12:00 In the previous article, SGTools was used to generate a s ...

Keysight Technologies’ Prize-giving Live Broadcast: VR/AR Digital Interface Testing Challenge in the Metaverse Testing Workshop Series is now open for registration!

Keysight Technologies’ Prize-giving Live Broadcast: VR/AR Digital Interface Testing Challenge in the Metaverse Testing ...

31 "Millions of Miles" Raspberry Pi Car——Ubuntu MATE System Installation

Next, I was going to start learning ROS, but it was particularly difficult to install it on the Raspberry Pi operating ...

Serial port printing

1. Project Background The CH2601 chip developed by Pingtou Ge has basic core IPs such as GPIO, TIM, SYSTICK, UART, IIC ...

Ask an outrageous question, why do we need to use a resistor to form a discharge path for the capacitor to discharge?

I have an outrageous question. Why do we need to use resistors to form a discharge path for capacitors to discharge and ...

Real-time spectrum analysis basics

673922 673923 673924 673925 673926

SDRAM's confusing address access problem

The compiler used is keil V5.38.0.0 version, the compiler is: 'V5.06 update 7 (build 960)', I have used 'V6.19', the pro ...

High-speed wireless debugger: Walls have ears --- wall penetration test

The content of this test is the wall penetration test of the high-speed wireless debugger. We have already tested the ...

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