1.RCC SYS配置
2.开通DAC的DAM
定时器2控制
3.打开定时器
4.时钟配置
5.单片机最大时钟频率72MHZ
利用工具箱生成正弦波码表(我用的是72个点)
uint16_t sinData[72]={2136,2314,2490,2663,2830,2992,3147,3293,3430,3556,3671,3773,3863,3938,3999,4045,4076,
4092,4092,4076,4045,3999,3938,3863,3773,3671,3556,3430,3293,3147,2992,2830,2663,
2490,2314,2136,1958,1780,1604,1431,1264,1102,947,801,664,538,423,321,231,
156,95,49,18,2,2,18,49,95,156,231,321,423,538,664,801,
947,1102,1264,1431,1604,1780,1958};
在while(1)前的begin和end之间添加如下两行代码:
HAL_TIM_Base_Start(&htim2);
HAL_DAC_Start_DMA(&hdac,DAC_CHANNEL_1, (uint32_t *)sinData, 72,DAC_ALIGN_12B_R);
上面两段代码:
第一句:打开定时器二
第二句:利用DAC输出正弦波函数
6.输出正弦波的频率
f=7200000/72/(arr+1)文章来源:https://www.toymoban.com/news/detail-690056.html
通过修改定时器arr值可以修改输出正弦波的频率。文章来源地址https://www.toymoban.com/news/detail-690056.html
到了这里,关于STM32F103RC—DAC输出正弦波的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!