当前位置:网站首页>Stm32f4 DMA Da sine wave generator keil5 Hal library cubemx
Stm32f4 DMA Da sine wave generator keil5 Hal library cubemx
2022-06-13 02:27:00 【An unforgettable squirrel】
One 、 introduction
In the previous two articles , The design idea of frequency meter and square wave generator with adjustable duty cycle is explained . This article explains the design idea of sine wave generator .
Frequency meter :https://blog.csdn.net/zzlwl/article/details/115352504
Square wave generator :https://blog.csdn.net/zzlwl/article/details/114882800
At the beginning of the design , in consideration of stm32f4 dma Superior performance , Determined to use dma Carry out the design goal of sine wave generator .
Search data stage , Refer to the routine of punctual atom , But there is no routine for continuous sine wave occurrence . give up .
I found an introduction on the Internet dma Sine wave article , However, it is found that the overload value of its timer has a strange suspense that it only works at a specific value . give up .
During this time, I have been studying CubeMX, Determined to use CubeMX The idea of sine wave generator .
Final realization :1hz-31.25khz( Sine meter 32 Point to 256 Dynamic jump between points ) Sine generator , The maximum frequency interval in this range is approximately equal to the current setting value 2%, The minimum is 0( It depends on factorization , Without theoretical proof )
Two 、 The main data
(1) Buffered or unbuffered ?
Look up stm32F40x-2015-3-ID022152v5 The findings are as follows :

obviously , No buffering is better than buffering .
(2) Speed and frequency
Same as above


obviously , The maximum update rate is 1us,6us I'm sure it can be updated . If 32 spot , Then the highest frequency 1000/32=31.25K
Plan to make the timer count at 80M, The frequency division number is 7(8 frequency division ) Add one digit each time 0.1us. Because the maximum update speed is 1us, Therefore, the minimum value of timer is 9(1us)
3、 ... and 、CubeMX Set up
Enable usart1、dma、dac1 tim6, stay cubeMx To establish dma、dac1、tim6 The connection between . Change the frequency division number in the number of clocks , Let the master clock work at 160Mhz
(CubeMX Please refer to the previous two articles for graphical use )
keil RTE HAL library STM32CubeMX Serial transceiver https://blog.csdn.net/zzlwl/article/details/115431728
Keil RTE Flash program https://blog.csdn.net/zzlwl/article/details/115394066
Four 、 The core idea of the code
(1) Call the interrupt receiving function in the main program
HAL_UART_Receive_IT(&huart1,&(rxData.buff[0]),1); Start interrupt reception
In the callback function void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) Format check in , If a carriage return line feed is received, the command input is considered complete , Otherwise, continue to interrupt the reception .
(2) Generate 256 Point sine meter , And start the timer , start-up dma, Start preset frequency output
HAL_TIM_Base_Start(&htim6);
HAL_DAC_Start_DMA(&hdac, DAC_CHANNEL_1, (uint32_t *)sinTbl, 256,DAC_ALIGN_12B_R);
From the above we can calculate , The preset frequency value is 10,000,000/256/10=3.906K
(10,000,000 by 1 In the second 0.1us The number of ,256 Indicates that the sine meter has 256 A little bit ,10 Indicates the auto reload value of the current timer . Timers every 0.1us Add 1)
(3) Main loop task processing
Complete data input in the main loop , Scope check , Factorization , Reset the timer and dma The job of .
(3.1) Calculate the optimal combination of timing value and sine number
If data entry is valid , Then calculate the periodic value according to the frequency ( Company 0.1us), If the period value >256*10, Then 256 spot , Otherwise, the optimal factorization in a step .
The meaning of a step , Such as the number of cycles <256*10, but >128*10 Then the number of points is guaranteed >128 In the case of circular judgment , Find the best number of points And timer timing value . The so-called optimal , It refers to the minimum error between the above two integer numbers multiplied and the set cycle value .
(3.2) Regenerate sine table , Reset the timer and dma
__HAL_TIM_SET_AUTORELOAD(&htim6,arr-1);// Reset the timer according to the actual timer time
HAL_DAC_Stop_DMA(&hdac, DAC_CHANNEL_1); // If you don't close it first dma Then the following reset points will not work .
HAL_DAC_Start_DMA(&hdac, DAC_CHANNEL_1, (uint32_t *)sinTbl, npoint,DAC_ALIGN_12B_R);//dma Start
Reset timer macro from file #include "stm32f4xx_hal_tim.h", If you are prompted with a compilation error , You can add this file .
5、 ... and 、 After commissioning
This project is in addition to the code mentioned above , Sine table generation 、 Serial receive callback function 、 Optimize timing and sine point code to write for yourself , Other codes are automatically generated by the system . Sensory use CubeMX More clear thinking , In addition, some macros can be used directly do while Packaging implementation , It feels like it takes into account both concept and speed . But there are few Chinese materials , For programmers C level 、 Foreign language proficiency is required .
边栏推荐
- Leetcode 450. Delete node in binary search tree [binary search tree]
- Armv8-m (Cortex-M) TrustZone summary and introduction
- ROS learning -5 how function packs with the same name work (workspace coverage)
- Bai ruikai Electronic sprint Scientific Innovation Board: proposed to raise 360 million Funds, Mr. And Mrs. Wang binhua as the main Shareholder
- Leetcode 450. 删除二叉搜索树中的节点 [二叉搜索树]
- Share three stories about CMDB
- [work notes] xr872 codec driver migration and application program example (with chip debugging method)
- STM32 IIC protocol controls pca9685 steering gear drive board
- Mean Value Coordinates
- Bluetooth module: use problem collection
猜你喜欢

拍拍贷母公司信也季报图解:营收24亿 净利5.3亿同比降10%

Stm32 mpu6050 servo pan tilt support follow

Huawei equipment is configured with IP and virtual private network hybrid FRR
![[work with notes] NDK compiles the open source library ffmpeg](/img/24/ed33e12a07e001fc708e0c023e479c.jpg)
[work with notes] NDK compiles the open source library ffmpeg

Share three stories about CMDB

Priority queue with dynamically changing priority

Mbedtls migration experience

Introduction to arm Cortex-M learning

Is space time attention all you need for video understanding?
![[pytorch] kaggle image classification competition arcface + bounding box code learning](/img/1e/5e921987754da1e1750acdadb36849.jpg)
[pytorch] kaggle image classification competition arcface + bounding box code learning
随机推荐
05 tabBar导航栏功能
[reading point paper] deeplobv3 rethinking atlas revolution for semantic image segmentation ASPP
智能安全配电装置如何减少电气火灾事故的发生?
Area of basic exercise circle ※
What are the differences in cache/tlb?
Common web page status return code crawler
Chapter7-10_ Deep Learning for Question Answering (1/2)
Yovo3 and yovo3 tiny structure diagram
speech production model
Paipai loan parent company Xinye quarterly report diagram: revenue of RMB 2.4 billion, net profit of RMB 530million, a year-on-year decrease of 10%
Is space time attention all you need for video understanding?
1、 Set up Django automation platform (realize one click SQL execution)
Cumulative tax law: calculate how much tax you have paid in a year
An image is word 16x16 words: transformers for image recognition at scale
The precision of C language printf output floating point numbers
[learning notes] xr872 audio driver framework analysis
Thesis reading - autovc: zero shot voice style transfer with only autoencoder loss
js-dom
GMM Gaussian mixture model
柏瑞凱電子沖刺科創板:擬募資3.6億 汪斌華夫婦為大股東