首页 > 评测 > 【NUCLEO-U575ZI-Q测评】DAC测试

【NUCLEO-U575ZI-Q测评】DAC测试

  
  • 作者:
  • 来源:
  • [导读]
  • 本帖最后由 dql2015 于 2023-3-24 16:26 编辑 STM32U5的DAC支持正常模式和采样保持模式,其中采样保持模式用于低功耗状态使用,每路 DAC 输出均可与 DAC_OUTx 输出引脚断开连接,而且 DAC 输出可与片上外设连

本帖最后由 dql2015 于 2023-3-24 16:26 编辑

STM32U5的DAC支持正常模式和采样保持模式,其中采样保持模式用于低功耗状态使用,每路 DAC 输出均可与 DAC_OUTx 输出引脚断开连接,而且 DAC 输出可与片上外设连接。一般情况下,使用出厂校准即可,芯片上电后自动完成出厂校准。STM32U5内置了高性能带PGA功能的运算放大器,可以通过配置形成多种常用模拟信号处理电路:


配置电压跟随器的用法:


DAC外设配置:

运放配置,将DAC输出连接到运放输入:


正弦输出表:

  1. uint32_t Wave_LUT[128] = {
  2.     2048, 2149, 2250, 2350, 2450, 2549, 2646, 2742, 2837, 2929, 3020, 3108, 3193, 3275, 3355,
  3.     3431, 3504, 3574, 3639, 3701, 3759, 3812, 3861, 3906, 3946, 3982, 4013, 4039, 4060, 4076,
  4.     4087, 4094, 4095, 4091, 4082, 4069, 4050, 4026, 3998, 3965, 3927, 3884, 3837, 3786, 3730,
  5.     3671, 3607, 3539, 3468, 3394, 3316, 3235, 3151, 3064, 2975, 2883, 2790, 2695, 2598, 2500,
  6.     2400, 2300, 2199, 2098, 1997, 1896, 1795, 1695, 1595, 1497, 1400, 1305, 1212, 1120, 1031,
  7.     944, 860, 779, 701, 627, 556, 488, 424, 365, 309, 258, 211, 168, 130, 97,
  8.     69, 45, 26, 13, 4, 0, 1, 8, 19, 35, 56, 82, 113, 149, 189,
  9.     234, 283, 336, 394, 456, 521, 591, 664, 740, 820, 902, 987, 1075, 1166, 1258,
  10.     1353, 1449, 1546, 1645, 1745, 1845, 1946, 2047
  11. };
复制代码

开启运放

  1. HAL_OPAMP_Start(&hopamp1);
  2.  
复制代码

开启DAC

  1. HAL_DAC_Start(&hdac1, DAC_CHANNEL_1);
复制代码


设置DAC输出值

  1. HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, Wave_LUT[i]);
复制代码



完整代码如下:

  1. /* USER CODE BEGIN Header */
  2. /**
  3.   ******************************************************************************
  4.   * [url=home.php?mod=space&uid=288409]@file[/url]           : main.c
  5.   * [url=home.php?mod=space&uid=247401]@brief[/url]          : Main program body
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * Copyright (c) 2023 STMicroelectronics.
  10.   * All rights reserved.
  11.   *
  12.   * This software is licensed under terms that can be found in the LICENSE file
  13.   * in the root directory of this software component.
  14.   * If no LICENSE file comes with this software, it is provided AS-IS.
  15.   *
  16.   ******************************************************************************
  17.   */
  18. /* USER CODE END Header */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "main.h"
  21. #include "adc.h"
  22. #include "dac.h"
  23. #include "opamp.h"
  24. #include "ucpd.h"
  25. #include "usart.h"
  26. #include "usb_otg.h"
  27. #include "gpio.h"
  28.  
  29. /* Private includes ----------------------------------------------------------*/
  30. /* USER CODE BEGIN Includes */
  31.  
  32. #include <stdio.h>
  33.  
  34. /* USER CODE END Includes */
  35.  
  36. /* Private typedef -----------------------------------------------------------*/
  37. /* USER CODE BEGIN PTD */
  38.  
  39. /* USER CODE END PTD */
  40.  
  41. /* Private define ------------------------------------------------------------*/
  42. /* USER CODE BEGIN PD */
  43. /* USER CODE END PD */
  44.  
  45. /* Private macro -------------------------------------------------------------*/
  46. /* USER CODE BEGIN PM */
  47.  
  48. /* USER CODE END PM */
  49.  
  50. /* Private variables ---------------------------------------------------------*/
  51.  
  52. /* USER CODE BEGIN PV */
  53.  
  54. uint32_t Wave_LUT[128] = {
  55.     2048, 2149, 2250, 2350, 2450, 2549, 2646, 2742, 2837, 2929, 3020, 3108, 3193, 3275, 3355,
  56.     3431, 3504, 3574, 3639, 3701, 3759, 3812, 3861, 3906, 3946, 3982, 4013, 4039, 4060, 4076,
  57.     4087, 4094, 4095, 4091, 4082, 4069, 4050, 4026, 3998, 3965, 3927, 3884, 3837, 3786, 3730,
  58.     3671, 3607, 3539, 3468, 3394, 3316, 3235, 3151, 3064, 2975, 2883, 2790, 2695, 2598, 2500,
  59.     2400, 2300, 2199, 2098, 1997, 1896, 1795, 1695, 1595, 1497, 1400, 1305, 1212, 1120, 1031,
  60.     944, 860, 779, 701, 627, 556, 488, 424, 365, 309, 258, 211, 168, 130, 97,
  61.     69, 45, 26, 13, 4, 0, 1, 8, 19, 35, 56, 82, 113, 149, 189,
  62.     234, 283, 336, 394, 456, 521, 591, 664, 740, 820, 902, 987, 1075, 1166, 1258,
  63.     1353, 1449, 1546, 1645, 1745, 1845, 1946, 2047
  64. };
  65.  
  66. /* USER CODE END PV */
  67.  
  68. /* Private function prototypes -----------------------------------------------*/
  69. void SystemClock_Config(void);
  70. static void SystemPower_Config(void);
  71. /* USER CODE BEGIN PFP */
  72.  
  73. /* USER CODE END PFP */
  74.  
  75. /* Private user code ---------------------------------------------------------*/
  76. /* USER CODE BEGIN 0 */
  77.  
  78. /* USER CODE END 0 */
  79.  
  80. /**
  81.   * [url=home.php?mod=space&uid=247401]@brief[/url]  The application entry point.
  82.   * @retval int
  83.   */
  84. int main(void)
  85. {
  86.   /* USER CODE BEGIN 1 */
  87.  
  88.   /* USER CODE END 1 */
  89.  
  90.   /* MCU Configuration--------------------------------------------------------*/
  91.  
  92.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  93.   HAL_Init();
  94.  
  95.   /* USER CODE BEGIN Init */
  96.  
  97.   /* USER CODE END Init */
  98.  
  99.   /* Configure the system clock */
  100.   SystemClock_Config();
  101.  
  102.   /* Configure the System Power */
  103.   SystemPower_Config();
  104.  
  105.   /* USER CODE BEGIN SysInit */
  106.  
  107.   /* USER CODE END SysInit */
  108.  
  109.   /* Initialize all configured peripherals */
  110.   MX_GPIO_Init();
  111.   MX_UCPD1_Init();
  112.   MX_USART1_UART_Init();
  113.   MX_USB_OTG_FS_PCD_Init();
  114.   MX_ADC1_Init();
  115.   MX_OPAMP1_Init();
  116.   MX_DAC1_Init();
  117.   /* USER CODE BEGIN 2 */
复制代码


在实际应用中采用定时器定时触发+DMA传输更实用。

  

  • 本文系21ic原创,未经许可禁止转载!

网友评论