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:
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:
class DDSUnit
Constructors
Methods
- DDSUnit.set_freq(index: int = 0, freq: int = 1000) None
Set the frequency of the DDS.
- 参数:
UIFLOW2:
- 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.
- 参数:
UIFLOW2:
- DDSUnit.set_mode(mode) None
Set the output mode of the DDS.
- 参数:
mode (int) –
The output mode of the DDS.
- Options:
DDSUnit.WAVE_SINE
: SineDDSUnit.WAVE_TRIANGLE
: TriangleDDSUnit.WAVE_SQUARE
: SquareDDSUnit.WAVE_SAWTOOTH
: SawtoothDDSUnit.WAVE_DC
: DC
UIFLOW2:
- 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.
- 参数:
UIFLOW2:
- 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:
- 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:
- 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.
- 参数:
UIFLOW2:
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.