DDS Unit

DDS 是一个信号源 Unit。它使用 AD9833 可编程波形发生器 + STM32F0 微控制器。基于 I2C 通信接口(addr:0x31),可轻松控制信号源输出多种波形(正弦波、三角波、方波输出、锯齿波,信号输出幅度 0-0.6V),并可调节频率和相位。

支持以下产品:

DDSUnit

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 应用示例

example.png

cores3_dds_example.m5f2

class DDSUnit

Constructors

class DDSUnit(i2c: I2C, address: int | list | tuple = 0x31)

初始化 DDSUnit。

参数:
  • i2c (I2C) – 单元所连接的 I2C 总线。

  • address (int) – DDSUnit 的 I2C 地址。默认为 0x31。

UiFlow2

init.png

Methods

DDSUnit.set_freq(index: int = 0, freq: int = 1000) None

设置 DDS 的频率。

参数:
  • index (int) – DDS 的寄存器编号,范围为 0 到 1。

  • freq (int) – DDS 的频率,单位为 Hz。

UiFlow2

set_freq.png

DDSUnit.set_phase(index: int = 0, phase: int = 0) None

设置 DDS 的相位。

参数:
  • index (int) – DDS 的寄存器编号,范围为 0 到 1。

  • phase (int) – DDS 的相位(单位:度)。

UiFlow2

set_phase.png

DDSUnit.set_freq_phase(f_index: int = 0, freq: int = 1000, p_index: int = 0, phase: int = 0) None

设置 DDS 的频率和相位。

参数:
  • f_index (int) – 频率的寄存器编号,范围为 0 到 1。

  • freq (int) – DDS 的频率,单位为 Hz。

  • p_index (int) – 相位的寄存器编号,范围为 0 到 1。

  • phase (int) – DDS 的相位(单位:度)。

UiFlow2

set_freq_phase.png

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

set_mode.png

DDSUnit.set_ctrl(f_index_sel: int = 0, p_index_sel: int = 0, disable_mclk=False, disable_dac=False, reset=False) None

设置 DDS 的控制字节。

参数:
  • f_index_sel (int) – 频率寄存器选择。范围为 0 到 1。

  • p_index_sel (int) – 相位寄存器选择。范围为 0 到 1。

  • disable_mclk (bool) – 禁用 MCLK。

  • disable_dac (bool) – 禁用 DAC。

  • reset (bool) – 复位 DDS。如果为 true,则会忽略其他参数。

UiFlow2

set_ctrl.png

DDSUnit.select_freq_reg(index: int = 0) None

选择 DDS 的频率寄存器。

参数:

index (int) – 频率寄存器的索引,范围为 0 到 1。

UiFlow2

select_freq_reg.png

DDSUnit.select_phase_reg(index: int = 0) None

选择 DDS 的相位寄存器。

参数:

index (int) – 相位寄存器的索引,范围为 0 到 1。

UiFlow2

select_phase_reg.png

DDSUnit.quick_output(mode: int = WAVE_SINE, freq: int = 1000, phase: int = 0) None

快速设置 DDS 的输出模式、频率和相位。

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

  • freq (int) – DDS 的频率,单位为 Hz。

  • phase (int) – DDS 的相位(单位:度)。

UiFlow2

quick_output.png

DDSUnit.output(f_index: int = 0, p_index: int = 0) None

输出 DDS 信号。

参数:
  • f_index (int) – 频率寄存器的索引,范围为 0 到 1。

  • p_index (int) – 相位寄存器的索引,范围为 0 到 1。

UiFlow2

output.png

DDSUnit.set_sleep_mode(mode: int = SLEEP_MODE_1) None

设置 DDS 的睡眠模式。

参数:

mode (int) – DDS 的睡眠模式。选项: - DDSUnit.SLEEP_MODE_NONE:无 - DDSUnit.SLEEP_MODE_1:禁用 MCLK - DDSUnit.SLEEP_MODE_2:禁用 MCLK 和 DAC

UiFlow2

set_sleep_mode.png

DDSUnit.reset() None

重置 DDS。

UiFlow2

reset.png

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。