当前位置:网站首页>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

边栏推荐
猜你喜欢

考研题库小程序中如何实现打开考研思维导图pdf

Review of HCIA

How about the performance of Intel Celeron 7305? What level is it equivalent to

第十一天笔记

rtx3080相当于gtx什么显卡 rtx3080显卡什么水平 rtx3080显卡怎么样

鸡与蛋,产品与策略

200 lines of code, in-depth analysis of the principle and implementation of dynamic calculation diagram

BERT 文章翻译

How to open the thought map pdf of postgraduate entrance examination in the small program of postgraduate entrance examination question bank

OSPF details (1)
随机推荐
Day 10 notes
T-SEDA编码
What level of rtx3070ti graphics card? What level of rtx3070ti graphics card? How about rtx3070ti graphics card
设计例化和连接
OSPF comprehensive experiment
iQOO 10 Pro和vivo X80 Pro区别 哪个好详细参数配置对比
第五天笔记
Differences between Xiaomi 12s pro and Xiaomi 12pro Tianji version configuration comparison between the two
ThreadLocal interview Kills 11 consecutive questions
JS to implement encode64 encryption
Sampling and data driven
Creo 9.0 如何快速修改CAD坐標系?
Design instantiation and connection
Medium range
JS realize random generation of UUID
Tensor、Numpy、PIL格式转换以及图像显示
How many processors is Tianji 720 equivalent to Xiaolong? How about Tianji 720 equivalent to Xiaolong
Where does pytorch work?
What level is rtx3090ti? What level is rtx3090ti graphics card? How about rtx3090ti graphics card
MGRE comprehensive experiment