当前位置:网站首页>STM32输出正弦波+cubeMX配置+HAL库
STM32输出正弦波+cubeMX配置+HAL库
2022-07-23 08:02:00 【也无风雨也无晴W】
一些前提:
cubemx里面的 主频设置,外设时钟和一些基础的配置我就不多说了,网上相关的很多
直接进入正题吧
我这里主频设置的72MHz
输出正弦波需要用到STM32的外设DAC
DAC概念:
一种将二进制数字量形式的离散信号转换成以标准量(或参考量)为基准的模拟量的转换器,简称 DAC
正弦波输出 代码的具体实现
DAC的配置
定时器6的设置
使用定时器6作为中断触发,相当于每进一次定时器6改一次输出DAC的值,最后模拟出正弦的变化。
keil中代码部分:
定义点数和存放点数值的数组
#include "math.h"
#define n 1000
uint16_t DualSine12bit[n];

生成正弦波的点数函数
//num:要在一个正弦波中采集多少点
//*D:创建的一个数组用来存放正弦波各个点的数值的
//U:输出电压的峰值(0~1.5V)
//Pi:3.1415926 自己定义
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);
}
}
输出
//开启定时器
HAL_TIM_Base_Start(&htim6);
//输出正弦波
SineWave_Data(n,DualSine12bit,1.6);
HAL_DAC_Start_DMA(&hdac,DAC_CHANNEL_1,(uint32_t *)DualSine12bit,n,DAC_ALIGN_12B_R);
最后频率的计算:
频率计算:主频 / 分频系数/ 计数值 / 取点数
72000000 / 1 / 10 / 1000 / 2 = 3600HZ

边栏推荐
- 第七天笔记
- MGRE experiment
- 强化學習——策略梯度理解點
- Notes on the fourth day
- Rip experiment
- ThreadLocal 面试夺命11连问
- Day108. Shang Yitong: interface docking of hospital simulation system - query of hospital | Department | shift scheduling, addition, deletion, modification and paging conditions
- Which is the difference between iqoo 10 pro and vivo X80 pro? Detailed parameter configuration comparison
- Spark统计每天新增用户
- UIScrollView(UICollectionView)禁止横向和竖向同时滑动
猜你喜欢

Creo 9.0 如何快速修改CAD坐标系?

使用Stream流来进行分类展示。

Notes on the fifth day

Thousands of databases, physical machines all over the country, JD logistics full volume cloud live record | interview with excellent technical team

酷睿i7 1165g7相当于什么水平 i71165g7属于哪个档次

Kafka consumption reports an error coordinator unavailable Rediscovery will be attempt redisCovery

ERP生产作业控制

OSPF detailed explanation (LSA) (2)

Which is the difference between iqoo 10 pro and vivo X80 pro? Detailed parameter configuration comparison

MYSQL练习题:向CEO汇报的所有员工
随机推荐
How many processors is Tianji 720 equivalent to Xiaolong? How about Tianji 720 equivalent to Xiaolong
NR Modulation 5
中等靶场
How about the performance of Intel Celeron 7305? What level is it equivalent to
判断一个对象是否是空对象的处理办法
设计例化和连接
Day108. Shang Yitong: interface docking of hospital simulation system - query of hospital | Department | shift scheduling, addition, deletion, modification and paging conditions
Network security note 1 - Security of Internet Protocol
Uiscrollview (uicollectionview) prohibits horizontal and vertical sliding at the same time
200 lines of code, in-depth analysis of the principle and implementation of dynamic calculation diagram
天玑820相当于骁龙多少处理器 天玑1100相当于骁龙多少 天玑820怎么样
Principle of container network
js 实现随机生成UUID
Description of test platform and hardware design
Notes on the fifth day
Best practices of JD cloud Distributed Link Tracking in financial scenarios
ERP生产作业控制
MGRE experiment
Renforcement de l'apprentissage - points de compréhension du gradient stratégique
达人评测酷睿i7 12850hx和i7 12700h选哪个