当前位置:网站首页>STM32 output sine wave +cubemx configuration +hal Library
STM32 output sine wave +cubemx configuration +hal Library
2022-07-23 14:14:00 【Neither rain nor sunshine w】
Some premises :
cubemx Inside Main frequency setting , I won't talk more about peripheral clocks and some basic configurations , There are many related online
Let's get straight to the point
I set the main frequency here 72MHz
Output Sine wave Need to use STM32 The peripherals of DAC
DAC Concept :
A binary The discrete signal in the form of digital quantity is converted into standard quantity ( Or reference quantity ) Benchmarking Analog converter , abbreviation DAC
Sine wave output The concrete implementation of the code
DAC Configuration of 
Timer 6 Set up 
Use timer 6 Trigger as an interrupt , amount to Every time you enter the timer 6 Change the output once DAC Value , Last Simulate sine The change of .
keil Code part in :
Define an array of points and storage values
#include "math.h"
#define n 1000
uint16_t DualSine12bit[n];

Generate the point function of sine wave
//num: How many points to collect in a sine wave
//*D: Create an array to store the values of each point of the sine wave
//U: Peak value of output voltage (0~1.5V)
//Pi:3.1415926 Define your own
void SineWave_Data( uint16_t num,uint16_t *D,float U)
{
uint16_t i;
for( i=0;i<num;i++)
{
D[i]=(uint16_t)((U*sin(( 1.0*i/(num-1))*2*3.14159265358979)+U)*4095/3.3);
}
}
Output
// Turn on timer
HAL_TIM_Base_Start(&htim6);
// Output sine wave
SineWave_Data(n,DualSine12bit,1.6);
HAL_DAC_Start_DMA(&hdac,DAC_CHANNEL_1,(uint32_t *)DualSine12bit,n,DAC_ALIGN_12B_R);
Calculation of final frequency :
Frequency calculation : Main frequency / Division coefficient / Count value / Take points
72000000 / 1 / 10 / 1000 / 2 = 3600HZ

边栏推荐
猜你喜欢

笔记本酷睿i5 1135g7相当于什么水平?i5 1135g7性能怎么样

How can Creo 9.0 quickly modify CAD coordinate system?

rtx3080ti和3090差距 rtx3080ti和3090哪个性价比高

Notes on the fifth day

OSPF details (1)

iQOO 10 Pro和小米12 Ultra哪个好 哪个值得买 两者配置对比
![[wechat applet] case - local life](/img/9d/c1525ce3c199d4db83b7a3b6828b63.png)
[wechat applet] case - local life

OSPF comprehensive experiment

Day108. Shang Yitong: interface docking of hospital simulation system - query of hospital | Department | shift scheduling, addition, deletion, modification and paging conditions

天玑720相当于骁龙多少处理器 天玑720相当于骁龙多少 天玑720怎么样
随机推荐
AppScan的安装与使用
iQOO 10 Pro和小米12 Ultra哪个好 哪个值得买 两者配置对比
canvas橡皮擦功能
第十二天笔记
设计例化和连接
Excitation generator, monitor
Remember that a vulnhub target plane exercise successfully won the root permission
Ansible first knowledge of learning one
200 lines of code, in-depth analysis of the principle and implementation of dynamic calculation diagram
Renforcement de l'apprentissage - points de compréhension du gradient stratégique
中等靶场
Process blocks and methods
-bash: ifconfig: command not found
rtx3080ti和rtx3080差距 3080和3080ti参数对比
Overlayfs source code parsing
How about the performance of Ruilong R7 Pro 5875u? What level is it equivalent to
英特尔赛扬7300性能怎么样?相当于什么水平级别
MYSQL练习题:向CEO汇报的所有员工
How many processors is Tianji 1100 equivalent to snapdragon? How about Tianji 1100 equivalent to snapdragon
Which is the difference between iqoo 10 pro and vivo X80 pro? Detailed parameter configuration comparison