DDS Unit
DDS 是一个信号源 Unit。它使用 AD9833 可编程波形发生器 + STM32F0 微控制器。基于 I2C 通信接口(addr:0x31),可轻松控制信号源输出多种波形(正弦波、三角波、方波输出、锯齿波,信号输出幅度 0-0.6V),并可调节频率和相位。
支持以下产品:
MicroPython 应用示例:
1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from hardware import * 9from unit import DDSUnit 10 11 12i2c0 = None 13dds_0 = None 14 15 16def setup(): 17 global i2c0, dds_0 18 19 M5.begin() 20 Widgets.fillScreen(0x222222) 21 22 i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000) 23 dds_0 = DDSUnit(i2c0, 0x31) 24 dds_0.set_mode(dds_0.WAVE_SQUARE) 25 dds_0.set_freq(0, 1000) 26 27 28def loop(): 29 global i2c0, dds_0 30 M5.update() 31 32 33if __name__ == "__main__": 34 try: 35 setup() 36 while True: 37 loop() 38 except (Exception, KeyboardInterrupt) as e: 39 try: 40 from utility import print_error_msg 41 42 print_error_msg(e) 43 except ImportError: 44 print("please update to latest firmware")
UiFlow2 应用示例
class DDSUnit
Constructors
Methods
- DDSUnit.set_freq_phase(f_index: int = 0, freq: int = 1000, p_index: int = 0, phase: int = 0) None
设置 DDS 的频率和相位。
- 参数:
UiFlow2

- DDSUnit.set_mode(mode) None
设置 DDS 的输出模式。
- 参数:
mode (int) – DDS 的输出模式。选项: -
DDSUnit.WAVE_SINE:正弦波 -DDSUnit.WAVE_TRIANGLE:三角波 -DDSUnit.WAVE_SQUARE:方波 -DDSUnit.WAVE_SAWTOOTH:锯齿波 -DDSUnit.WAVE_DC:直流
UiFlow2

- DDSUnit.set_ctrl(f_index_sel: int = 0, p_index_sel: int = 0, disable_mclk=False, disable_dac=False, reset=False) None
设置 DDS 的控制字节。
- 参数:
UiFlow2

- DDSUnit.select_freq_reg(index: int = 0) None
选择 DDS 的频率寄存器。
- 参数:
index (int) – 频率寄存器的索引,范围为 0 到 1。
UiFlow2

- DDSUnit.select_phase_reg(index: int = 0) None
选择 DDS 的相位寄存器。
- 参数:
index (int) – 相位寄存器的索引,范围为 0 到 1。
UiFlow2

- DDSUnit.quick_output(mode: int = WAVE_SINE, freq: int = 1000, phase: int = 0) None
快速设置 DDS 的输出模式、频率和相位。
- 参数:
UiFlow2

Constants
- DDSUnit.WAVE_SINE
正弦波输出。
- DDSUnit.WAVE_TRIANGLE
三角波输出。
- DDSUnit.WAVE_SQUARE
方波输出。
- DDSUnit.WAVE_SAWTOOTH
锯齿波输出。
- DDSUnit.WAVE_DC
DC 波形输出。
- DDSUnit.SLEEP_MODE_NONE
无睡眠模式。
- DDSUnit.SLEEP_MODE_1
禁用 mclk 但保留 dac。
- DDSUnit.SLEEP_MODE_2
禁用 mclk 和 dac。







