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

边栏推荐
- JS数据类型判断方式总结
- Script type=module
- OSPF details (1)
- Rtx3080ti and rtx3080 gap 3080 and 3080ti parameter comparison
- Excitation generator, monitor
- Swift 16进制字符串与UIColor互转
- Thousands of databases, physical machines all over the country, JD logistics full volume cloud live record | interview with excellent technical team
- BGP federal experiment
- 采样和数据驱动
- Description of test platform and hardware design
猜你喜欢

Overlayfs source code parsing

Day 12 notes

ERP production operation control

NR Modulation 5

Best practices of JD cloud Distributed Link Tracking in financial scenarios

采样和数据驱动

第六天笔记

rtx3070ti显卡什么水平 rtx3070ti显卡什么级别 rtx3070ti显卡怎么样

Rip experiment

Rtx3080 is equivalent to GTX. What kind of graphics card is rtx3080? What level is rtx3080
随机推荐
js 实现 encode64 加密
网络安全笔记1——Internet协议的安全性
笔记本酷睿i5 1135g7相当于什么水平?i5 1135g7性能怎么样
Comparison of iqoo 10 pro and Xiaomi 12 ultra configurations
接口interface
Fastadmin changes the pop-up size of the default table button
Day 10 notes
过程块和方法
Configure the firetracker process, i.e. stepping on the pit record
Static comprehensive experiment (HCIA)
Swift 16进制字符串与UIColor互转
T-SEDA编码
Day108. Shang Yitong: interface docking of hospital simulation system - query of hospital | Department | shift scheduling, addition, deletion, modification and paging conditions
天玑720相当于骁龙多少处理器 天玑720相当于骁龙多少 天玑720怎么样
How about the nuclear display performance of Ruilong R7 Pro 6850h? What level is it equivalent to
SDF refraction and reflection effect recording
Description of test platform and hardware design
第十天笔记
BGP联邦实验
Golang remote server debugging