DDS Unit

DDS is a signal source Unit. It uses the AD9833 programmable waveform generator + STM32F0 micro controller. Based on I2C communication interface (addr:0x31) It can easily control the signal source to output multiple waveforms (sine wave, triangle wave, square wave output, sawtooth wave, signal output amplitude 0-0.6V) and adjust the frequency and phase.

Support the following products:

DDSUnit

Micropython Example:

 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:

example.png

cores3_dds_example.m5f2

class DDSUnit

Constructors

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

Initialize the DDSUnit.

参数:
  • i2c (I2C) – The i2c bus the unit is connected to.

  • address (int) – The I2C address of the DDSUnit. Default is 0x31.

UIFLOW2:

init.png

Methods

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

Set the frequency of the DDS.

参数:
  • index (int) – The register number of the DDS, range from 0 to 1.

  • freq (int) – The frequency of the DDS in Hz.

UIFLOW2:

set_freq.png

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

Set the phase of the DDS.

参数:
  • index (int) – The register number of the DDS, range from 0 to 1.

  • phase (int) – The phase of the DDS in degrees.

UIFLOW2:

set_phase.png

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

Set the frequency and phase of the DDS.

参数:
  • f_index (int) – The register number of the frequency, range from 0 to 1.

  • freq (int) – The frequency of the DDS in Hz.

  • p_index (int) – The register number of the phase, range from 0 to 1.

  • phase (int) – The phase of the DDS in degrees.

UIFLOW2:

set_freq_phase.png

DDSUnit.set_mode(mode) None

Set the output mode of the DDS.

参数:

mode (int) –

The output mode of the DDS.

Options:
  • DDSUnit.WAVE_SINE: Sine

  • DDSUnit.WAVE_TRIANGLE: Triangle

  • DDSUnit.WAVE_SQUARE: Square

  • DDSUnit.WAVE_SAWTOOTH: Sawtooth

  • DDSUnit.WAVE_DC: 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

Set the control bytes of the DDS.

参数:
  • f_index_sel (int) – The frequency register select. range from 0 to 1.

  • p_index_sel (int) – The phase register select. range from 0 to 1.

  • disable_mclk (bool) – disable the MCLK.

  • disable_dac (bool) – disable the DAC.

  • reset (bool) – reset the DDS. If is true, other parameters will be ignored.

UIFLOW2:

set_ctrl.png

DDSUnit.select_freq_reg(index: int = 0) None

Select the frequency register of the DDS.

参数:

index (int) – The index of the frequency register. range from 0 to 1

UIFLOW2:

select_freq_reg.png

DDSUnit.select_phase_reg(index: int = 0) None

Select the phase register of the DDS.

参数:

index (int) – The index of the phase register. range from 0 to 1

UIFLOW2:

select_phase_reg.png

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

Quickly set the output mode, frequency and phase of the DDS.

参数:
  • mode (int) –

    The output mode of the DDS.

    Options:
    • DDSUnit.WAVE_SINE: Sine

    • DDSUnit.WAVE_TRIANGLE: Triangle

    • DDSUnit.WAVE_SQUARE: Square

    • DDSUnit.WAVE_SAWTOOTH: Sawtooth

    • DDSUnit.WAVE_DC: DC

  • freq (int) – The frequency of the DDS in Hz.

  • phase (int) – The phase of the DDS in degrees.

UIFLOW2:

quick_output.png

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

Output the DDS signal.

参数:
  • f_index (int) – The index of the frequency register. range from 0 to 1

  • p_index (int) – The index of the phase register. range from 0 to 1

UIFLOW2:

output.png

DDSUnit.set_sleep_mode(mode: int = SLEEP_MODE_1) None

Set the sleep mode of the DDS.

参数:

mode (int) –

The sleep mode of the DDS.

Options:
  • DDSUnit.SLEEP_MODE_NONE: None

  • DDSUnit.SLEEP_MODE_1: Disable MCLK

  • DDSUnit.SLEEP_MODE_2: Disable MCLK and DAC

UIFLOW2:

set_sleep_mode.png

DDSUnit.reset() None

Reset the DDS.

UIFLOW2:

reset.png

Constants

DDSUnit.WAVE_SINE

Sine wave output.

DDSUnit.WAVE_TRIANGLE

Triangle wave output.

DDSUnit.WAVE_SQUARE

Square wave output.

DDSUnit.WAVE_SAWTOOTH

Sawtooth wave output.

DDSUnit.WAVE_DC

DC wave output.

DDSUnit.SLEEP_MODE_NONE

No sleep mode.

DDSUnit.SLEEP_MODE_1

Disable mclk but keep dac.

DDSUnit.SLEEP_MODE_2

Disable mclk and dac.