1668 views|11 replies

85

Posts

0

Resources
The OP
 

[HC32F448 Review] +ADC Sampling + FFT Analysis [Copy link]

 
 

Chapter 9: ADC Sampling + FFT Analysis

Continuing from the configuration in the previous article, the DSP library has been configured in the previous article. Next, we will test the use of ADC to collect analog data for Fourier analysis.

First, refer to the example to configure the ADC. The parameters of the ADC are relatively simple. What needs to be noted is its clock. It has two clocks, including the conversion clock PCLK2 and the digital interface clock PCLK4. The conversion clock PCLK2 has three clock sources, including the system clock, PLLHQ, and PLLHR. If the system clock is used, the highest main frequency is 50MHz. If PLLHQ and PLLHR are used, the frequency can be multiplied to 60MHz through PLL. PCLK4 has three clock sources like PCLK2. For convenience, the system clock is used here, PCLK2=50MHz, PCLK4=100MHz.

ADC has several scanning modes, single scan, continuous scan, buffered scan, etc. Here we choose the continuous scan mode: stcAdcInit.u16ScanMode=ADC_MD_SEQA_CONT;

At the same time, the trigger source selects software trigger:

ADC_Start(CM_ADC1);

Then run the following program in a loop: query the status bit, then clear it to zero and read the data.

while(ADC_GetStatus(ADC_UNIT, ADC_EOC_FLAG) != SET);

ADC_ClearStatus(ADC_UNIT, ADC_EOC_FLAG);

ADC_DATA[ADCnum]=ADC_UNIT->DR10;

Because real-time analysis is not possible at present, FFT analysis can only be performed when the data is full of 1024. Input a 1KHz square wave, and the figure below is the waveform measured by ADC

Then perform FFT analysis on the data and take the first 64 data for plotting. It can be found that there are signals with multiple frequencies. In addition to the 1KHz fundamental wave, there are also 3KHz 3rd harmonic, 5KHz 5th harmonic, etc. This is in line with the characteristics of a square wave: it is composed of the superposition of sinusoidal waves of multiple frequencies.

The figure below shows the waveform measured by a virtual oscilloscope and the results of FFT analysis, which are basically consistent.

The above is the effect I can achieve at present. Since the following problems have not been solved, there is no way to achieve a more practical FFT effect:

1. There is no problem of transferring ADC data through DMA, because the related problems have not been solved, and I am not familiar with using DMA, so I cannot transfer 1024 ADC data at one time.

2. After turning on the ADC conversion completion interrupt (ADC_INT_EOCA), it is found that it gets stuck, which makes the buttons on the development board unusable. The main reason may be interrupt conflict. The interrupt of HC32 is very powerful, but it is still difficult for me to understand it. I will study it later if I have the opportunity.

3. I found that the system would freeze if the timer output PWM wave and FFT were turned on at the same time. I don’t know why. Another thing is that the FFT seems to be unstable and there will be problems when it is turned on with multiple peripherals. I will study it when I have the chance.

4. Because the waveforms are output through the serial port and then drawn in Excel, if you want it to be more intuitive, you need to display it on the LCD or transmit it to the host computer in real time. The host computer draws the line in real time. This has higher requirements because it is similar to an oscilloscope and takes more time.

This post is from Domestic Chip Exchange

Latest reply

To separate the real-time acquisition, communication, and FFT tasks: The acquisition and communication are relatively "timed" completion, but FFT is a relatively non-real-time task with statistical concepts. It is impossible to do FFT at one point, so it can be put into the main program without interrupt processing, and the relative time accuracy is sufficient. Moreover, FFT only takes 1-5ms to complete, which will not cause task accumulation and conflict. This ensures the completion of real-time tasks and avoids "conflicts".   Details Published on 2023-9-20 11:25
 
 

1668

Posts

0

Resources
2
 

Turning on the timer to output PWM wave and FFT at the same time will cause the system to freeze. Turn on one at a time and increase the number gradually to see which aspect causes the problem.

This post is from Domestic Chip Exchange
 
 
 

85

Posts

0

Resources
3
 
Hot Ximi Show published on 2023-9-12 07:29 If you start the timer to output PWM wave and FFT at the same time, the system will freeze. Start one first and increase it slowly to see which aspect causes the problem

Mainly because I don't have time to do this now. I will study it next time when I have time.

This post is from Domestic Chip Exchange
 
 
 

6841

Posts

11

Resources
4
 
The OP is very good. As for the serial port, if you increase the speed a bit, there shouldn't be any pressure.
This post is from Domestic Chip Exchange
 
 
 

1463

Posts

0

Resources
5
 
dmzdmz666666 posted on 2023-9-12 14:13 Mainly because I don’t have time to do this now, I will study it next time when I have time

Why does the system freeze when the timer outputs PWM wave and FFT are turned on at the same time?

This post is from Domestic Chip Exchange
 
 
 

85

Posts

0

Resources
6
 
lugl4313820 posted on 2023-9-14 17:04 The OP is really good. If you increase the serial port rate, there shouldn't be any pressure.

If it is too fast, it will interrupt the ADC sampling, so it is usually sampled and then displayed like an oscilloscope.

This post is from Domestic Chip Exchange
 
 
 

85

Posts

0

Resources
7
 
dmzdmz666666 posted on 2023-9-15 10:22 If it is too fast, it will interrupt the ADC sampling, so it is usually sampled and then displayed like an oscilloscope

I don't know, no research yet.

This post is from Domestic Chip Exchange
 
 
 

58

Posts

0

Resources
8
 
You can download VOFA and draw pictures by yourself
This post is from Domestic Chip Exchange
 
 
 

6841

Posts

11

Resources
9
 
dmzdmz666666 posted on 2023-9-15 10:22 If it is too fast, it will interrupt the ADC sampling, so it is usually sampled and then displayed like an oscilloscope

If so, will real-time performance be affected?

This post is from Domestic Chip Exchange
 
 
 

85

Posts

0

Resources
10
 
lugl4313820 posted on 2023-9-15 12:35 If this is the case, will the real-time performance be affected?

There will be an impact, so for example, an oscilloscope will have a dead time, which is when no sampling occurs but only the display is displayed. Therefore, the dead time can only be shortened, that is, the waveform refresh rate is increased.

This post is from Domestic Chip Exchange
 
 
 

85

Posts

0

Resources
11
 
Study study study study study published on 2023-9-15 12:06 You can download VOFA and draw your own pictures

I'll try it when I have time.

This post is from Domestic Chip Exchange
 
 
 

1025

Posts

0

Resources
12
 

To separate the real-time acquisition, communication, and FFT tasks:

The acquisition and communication are relatively "timed" completion, but FFT is a relatively non-real-time task with statistical concepts. It is impossible to do FFT at one point, so it can be put into the main program without interrupt processing, and the relative time accuracy is sufficient. Moreover, FFT only takes 1-5ms to complete, which will not cause task accumulation and conflict.

This ensures the completion of real-time tasks and avoids "conflicts".

This post is from Domestic Chip Exchange
Personal signatureچوآن شـين
 
 
 

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