UHRGAV

#Bootcamp# A Simple Digital Oscilloscope Project Based on GD32

 
Overview
This is a simple digital oscilloscope project based on the GD32 microcontroller. It's in the beginner's section, so the hardware details won't be explained in detail.
Please see the readme file in the Doc folder in the attachments for specific instructions.
I prefer using UTF-8 encoding in Keil to ensure compatibility with various needs, so I generally don't include Chinese comments in the project. The English comments are similar to construction site jargon, and I think it's necessary to write a separate document to explain some aspects of the project. This project is based on the open-source code by Mr. Chen from JLCPCB, with some modifications. The open-source website is: https://gitee.com/chen11232/GD32E230-Oscilloscope.
Let's start with main.c, which includes clock configuration, LED pin initialization, and KEY pin initialization.
After the initialization function, a JLCPCB image is added as the standby screen. Toggling KEY1 skips this screen and enters the normal program. The header file containing the image has been removed from files with the "Simplified" suffix, which may shorten the download time.
The standby screen program is implemented as follows:
LED pin initialization and KEY pin initialization are relatively basic and will not be discussed in detail. Of particular note are the `Key_GetState()` and `Key_GetNum()` functions in `Key.c`. `Key_GetState()` returns the key value corresponding to each key pressed. For example, if key 1 is detected as pressed (GPIO PB13 pin is low), the key state is returned as the return value. In `Key_GetNum()`, the previous and current key states are read. If a key is always pressed, the current key state will never be zero, and the function returns the previous value of `keynum`. Only when a key is released does the function begin to determine which key was previously pressed based on the previous state. For example, if the current key state is 0 and the previous key state was 1, then KEY1 can be considered pressed, and the key value of KEY1 is returned.
Serial port initialization and external interrupt initialization are also quite basic and will not be discussed in detail. It's worth noting the external interrupt function 4-15 (void EXTI4_15_IRQHandler(void)) in main.c. This function adjusts the PWM output frequency, duty cycle, and ADC sampling time of the GD32 chip based on the current key value and the rotation state of the rotary encoder. Within the function, the variables cnt1 and cnt2 store the clockwise (counterclockwise) rotation of the rotary encoder, primarily to prevent misjudgments.
Optional values ​​can be found in the gd32e23x_adc.c file by pressing Ctrl+F in the project, entering ADC_SAMPLETIME_239POINT5 in Find what, looking in the Current Project dropdown, and clicking Find Next at the bottom of the window. The optional values ​​can be found in the gd32e23x_adc.c file.
I haven't modified the ADC, FREQ related functions, or screen initialization, so I won't go into detail. For more information, please refer to the relevant videos on software by Bilibili user 立创EDA (LICHENG EDA) and the Oscilloscope Training Camp.
PWM initialization is quite basic and won't be discussed further. It's worth noting that I defined the functions `PWM_PulseAdjustment()` and `PWM_FrequencyAdjustment()`, which are used to calculate the duty cycle and frequency of the output PWM wave. In the `Key_ControlPWM()` function, the PWM output is controlled by checking if `Timer14flag` is 0 to enable or disable Timer14. This flag is controlled by external interrupt functions 4-15. `ONflag` and `OFFflag` prevent frequent refreshes of the display state; the display is refreshed only after the first change in `Timer14flag`, and then the previous display state is retained. `Pulse_temp`, `AutoloadValue_temp`, and `SampleTime_temp` are defined to store the `Pulse`, `AutoloadValue`, and `SampleTime` values ​​of the previous state, respectively. The screen is only refreshed when `Pulse`, `AutoloadValue`, and `SampleTime` change. It's also worth noting that a maximum and minimum output frequency are set, with a minimum of approximately 16Hz and a maximum of approximately 40kHz. After reaching the minimum value, rotating the rotary encoder counterclockwise while in KEY3 state will trigger a screen prompt with a 3-second delay. The input frequency and amplitude will only refresh after the prompt disappears. The prompt appears only once, and rotating the rotary encoder is ineffective while in the prompt state; the output frequency can only be adjusted normally after the 3-second delay.
The garbled characters are due to initially using GB32 encoding, which was later changed back to UTF-8. Therefore, it's crucial to develop good coding habits and maintain consistent encoding formats. The same applies to sampling time; changing the sampling time will trigger a prompt, and the sampling time can only be changed after the prompt ends. The Key_ControlPWM() function adds the functionality to display changes on the screen when the sampling time changes. The last two lines are spaces used to refresh the screen and display the sampling time prompt.
This project does not use Chen's Oscilloscope structure variable; therefore, most parameters are passed directly using global variables in main.c, which is a poor practice.
Important Notes: My programming contains numerous bugs due to oversights. If anyone sees this post and burns my program, please leave a comment if you encounter any bugs. I will attempt to fix them when I have the time and energy, and upload a modified version. This is why the uploaded program is labeled V1 and V2. Thank you!
The main problem I encountered was that initially, when using an oscilloscope probe with only 10x attenuation as the input probe, I couldn't measure the frequency and voltage correctly. Using a probe with selectable 1x and 10x attenuation resolved the issue.
参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2026-03-28 01:13:15

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号