找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 858|回复: 0
打印 上一主题 下一主题
收起左侧

STM32 DMA-DAC产生1KHz正弦波程序

[复制链接]
跳转到指定楼层
楼主
ID:607724 发表于 2023-2-16 15:43 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
STM32  DMA-DAC产生1KHz正弦波  例程

单片机源程序如下:
  1. #include "stm32f10x.h"
  2. #include "DMA.h"

  3. const uint16_t Sine12bit[258] = {
  4. 2048, 2098, 2148, 2198, 2248, 2298, 2348, 2398, 2447, 2496,
  5. 2545, 2594, 2642, 2690, 2737, 2785, 2831, 2877, 2923, 2968,
  6. 3013, 3057, 3100, 3143, 3185, 3227, 3267, 3307, 3347, 3385,
  7. 3423, 3460, 3496, 3531, 3565, 3598, 3631, 3662, 3692, 3722,
  8. 3750, 3778, 3804, 3829, 3854, 3877, 3899, 3920, 3940, 3958,
  9. 3976, 3992, 4007, 4021, 4034, 4046, 4056, 4065, 4073, 4080,
  10. 4086, 4090, 4093, 4095, 4095, 4095, 4093, 4090, 4086, 4080,
  11. 4073, 4065, 4056, 4046, 4034, 4021, 4007, 3992, 3976, 3958,
  12. 3940, 3920, 3899, 3877, 3854, 3829, 3804, 3778, 3750, 3722,
  13. 3692, 3662, 3631, 3598, 3565, 3531, 3496, 3460, 3423, 3385,
  14. 3347, 3307, 3267, 3227, 3185, 3143, 3100, 3057, 3013, 2968,
  15. 2923, 2877, 2831, 2785, 2737, 2690, 2642, 2594, 2545, 2496,
  16. 2447, 2398, 2348, 2298, 2248, 2198, 2148, 2098, 2047, 1997,
  17. 1947, 1897, 1847, 1797, 1747, 1697, 1648, 1599, 1550, 1501,
  18. 1453, 1405, 1358, 1310, 1264, 1218, 1172, 1127, 1082, 1038,
  19. 995, 952, 910, 868, 828, 788, 748, 710, 672, 635,
  20. 599, 564, 530, 497, 464, 433, 403, 373, 345, 317,
  21. 291, 266, 241, 218, 196, 175, 155, 137, 119, 103,
  22. 88, 74, 61, 49, 39, 30, 22, 15, 9, 5,
  23. 2, 0, 0, 0, 2, 5, 9, 15, 22, 30,
  24. 39, 49, 61, 74, 88, 103, 119, 137, 155, 175,
  25. 196, 218, 241, 266, 291, 317, 345, 373, 403, 433,
  26. 464, 497, 530, 564, 599, 635, 672, 710, 748, 788,
  27. 828, 868, 910, 952, 995, 1038, 1082, 1127, 1172, 1218,
  28. 1264, 1310, 1358, 1405, 1453, 1501, 1550, 1599, 1648, 1697,
  29. 1747, 1797, 1847, 1897, 1947, 1997 };

  30. void DMA_Config(void)
  31. {
  32.         DMA_InitTypeDef            DMA_InitStructure;
  33.        
  34.         RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);

  35.         /* DMA2 channel2 configuration */
  36.         DMA_DeInit(DMA2_Channel4);
  37.         DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12R2; //指定DMA2通道3的目标地址为DAC1_DHR12R1
  38.         DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&Sine12bit;        //指定DMA的源地址为数组Sine12bit
  39.         DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
  40.         DMA_InitStructure.DMA_BufferSize = 256;
  41.         DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  42.         DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  43.         DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
  44.         DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  45.         DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
  46.         DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
  47.         DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
  48.         DMA_Init(DMA2_Channel4, &DMA_InitStructure);
  49.        
  50.         /* Enable DMA2 Channel2 */
  51.         DMA_Cmd(DMA2_Channel4, ENABLE);
  52. }
复制代码

所有资料51hei附件下载:
Keil代码.7z (179.1 KB, 下载次数: 21)


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表