SKU_DFR0973_AD9837_DDS_Waveform_Generator-DFRobot

[](Product Link)

Introduction

The AD9837 is a low power, programmable waveform generator capable of producing sine, triangular, and square wave outputs. The output frequency and phase are software programmable, allowing easy tuning. The frequency registers are 28 bits wide: with a 16 MHz clock rate, resolution of 0.06 Hz can be achieved. The AD9837 is written to via a 3-wire serial interface. This serial interface operates at clock rates up to 40 MHz and is compatible with DSP and microcontroller standards. The device operates with a power supply from 3.3V to 5.5V. The AD9837 has a power-down (sleep) function. Sections of the device that are not being used can be powered down to minimize the current consumption of the part. For example, the DAC can be powered down when a clock output is being generated.

Features

Application

Specification

Dimensional Diagram

Dimension

Terms

DDS

Direct digital synthesis (DDS) is a method of producing an analog waveform—usually a sine wave—by generating a time-varying signal in digital form and then performing a digital-to-analog conversion.

The ability to accurately produce and control waveforms of various frequencies and profiles has become a key requirement common to a number of industries. Whether providing agile sources of low-phase-noise variable-frequencies with good spurious performance for communications, or simply generating a frequency stimulus in industrial or biomedical test equipment applications, convenience, compactness, and low cost are important design considerations.

DAC

In electronics, a digital-to-analog converter (DAC, D/A, D2A, or D-to-A) is a system that converts a digital signal into an analog signal. DACs are commonly used in music players to convert digital data streams into analog audio signals

Sine Wave

A sine wave consists of a single frequency only. It is a mathematical curve defined in terms of the sine trigonometric function. Any complex signal, such as spectral signal, can be regarded as composed of many sine waves with different frequencies and sizes. For example, the household electricity we use every day is a sine wave AC with a frequency of 50Hz.

Board Overview

Pinout

Label Full Name Function Description
VCC VCC Power input 3.3-5V(Need to be consistent with maincontroller level)
GND DGND Digital Ground Need to be connected to GND digital ground when connecting a maincontroller
DAT SDATA Serial data input Input 16bit serial data from this port
CLK SCLK Digital clock input The DDS output frequency is a fraction of the MCLK frequency, and the numerator of the fraction is a binary number. Both output frequency accuracy and phase noise are determined by this clock.
FSC FSNYC Active low control input This is the frame synchronization signal of the input data
OUT VOUT Waveform output Both digital and ananlog outputs of AD9837 are provided by this pin
AGND(AG) AGND Analog ground Connect AGND when outputting waveform
NC NC Empty pin Empty

Tutorial for ESP32-E

Requirements

Connection Diagram

Connection 1

Connection description

Note: Although AD9837 supports 3.3~5.5V, its power voltage should be consistent with the controller's level voltage. Since the level of FireBeetle ESP32-E is 3.3V, the VCC should be connected to 3V3. If connecting to maincontroller's VCC(VIN) pin, it will cause the AD9837 to misjudge the level, resulting in data error and output waveform error.`

Sample Code 1: Output Sinusoidal Wave

The AD9837 module outputs a sinusoidal wave with a phase of 0 and a frequency of 1000Hz. Connect a oscilloscope at OUT port to observe the output waveform and data.

/*
 * Output sinusoidal wave signal;
 * The amplitude of sinusoidal wave signal is about 0.645V; 
 */

#include <DFRobot_AD9837.h>

uint8_t ssPin = D2;
DFRobot_AD9837 AD9837(/* fscPin= */ssPin, /* *pSpi= */&SPI);   //Init an instance. Call class interface by this instance 

void setup(void)
{
  AD9837.begin(/* frequency= */10000000); //Init SPI communication, frequency: SPI communication max frequency
  AD9837.outputSin(/* phase= */0, /* freq= */1000.0); //Output phase 0, frequency 1KHz
}

void loop()
{
  delay(100);
}

Expected Results

Result

Sample Code 2: Output Triangular Wave

The AD9837 module outputs a triangular wave with a phase of 0 and a frequency of 1000Hz. Connect a oscilloscope at OUT port to observe the output waveform and data.

/*
 * Output triangular wave signal;
 * The amplitude of triangular wave signal is about 0.645V;
 */

#include <DFRobot_AD9837.h>

uint8_t ssPin = D2;
DFRobot_AD9837 AD9837(/* fscPin= */ssPin, /* *pSpi= */&SPI);   //Init an instance. Call class interface by this instance 

void setup(void)
{
  AD9837.begin(/* frequency= */10000000);//Init SPI communication, frequency:SPI communication max frequency
  AD9837.outputTriangle(/* phase= */0, /* freq= */1000.0);//Output phase 0, frequency 1KHz
}

void loop()
{
  delay(100);
}

Expected Results

Result 2

Sample Code 3: Output Square Wave

The AD9837 module outputs a square wave with a phase of 0 and a frequency of 1000Hz. Connect a oscilloscope at OUT port to observe the output waveform and data.

/*
 * Output square wave signal;
 * The amplitude of square wave signal is about equal to VCC voltage; 
 */

#include <DFRobot_AD9837.h>

uint8_t ssPin = D2;
DFRobot_AD9837 AD9837(/* fscPin= */ssPin, /* *pSpi= */&SPI);   //Init an instance. Call class interface by this instance

void setup(void)
{
  AD9837.begin(/* frequency= */10000000);//Init SPI communication, frequency: SPI communication max frequency
  AD9837.outputSquare(/* divide= */AD9837.eDIV2_1, /* phase= */0, /* freq= */1000.0);
  //Output square wave with phase 0 and frequency 1KHz. eDIV2_1: Output MSB of DAC data, eDIV2_2: Output MSB/2 of DAC data;  
}

void loop()
{
  delay(100);
}

Expected Results

Result 3

Tutorial for Arduino UNO

Requirements

Connection Diagram

Connection 2

Connection description

Note: Although AD9837 supports 3.3~5.5V, its power voltage should be consistent with the controller's level voltage. Since the level of FireBeetle ESP32-E is 5V, the VCC should be connected to 5V. If connecting to UNO's 3V3, it will cause the AD9837 to misjudge the level, resulting in data error and output waveform error.`

Sample Code 1: Output Sinusoidal Wave

The AD9837 module outputs a sinusoidal wave with a phase of 0 and a frequency of 1000Hz. Connect a oscilloscope at OUT port to observe the output waveform and data.

/*
 * Output sinusoidal wave signal;
 * The amplitude of sinusoidal wave signal is about 0.645V; 
 */

#include <DFRobot_AD9837.h>

uint8_t ssPin = 5;
DFRobot_AD9837 AD9837(/* fscPin= */ssPin, /* *pSpi= */&SPI);   //Init an instance. Call class interface by this instance

void setup(void)
{
  AD9837.begin(/* frequency= */10000000); //Init SPI communication, frequency: SPI communication max frequency
  AD9837.outputSin(/* phase= */0, /* freq= */1000.0); //Output sinusoidal wave with phase 0 and frequency 1KHz
}

void loop()
{
  delay(100);
}

Expected Results

Result 4

Sample Code 2: Output Triangular Wave

The AD9837 module outputs a triangular wave with a phase of 0 and a frequency of 1000Hz. Connect a oscilloscope at OUT port to observe the output waveform and data.

/*
 * Output triangular wave signal;
 * The amplitude of triangular wave is about 0.645V;
 */
#include <DFRobot_AD9837.h>

uint8_t ssPin = 5;
DFRobot_AD9837 AD9837(/* fscPin= */ssPin, /* *pSpi= */&SPI);   //Init an instance. Call class interface by this instance

void setup(void)
{
  AD9837.begin(/* frequency= */10000000);//Init SPI communication, frequency: SPI communication max frequency
  AD9837.outputTriangle(/* phase= */0, /* freq= */1000.0);//Output triangular wave with phase 0 and frequency 1KHz
}

void loop()
{
  delay(100);
}

Expected Results

Result 5

Sample Code 3: Output Square Wave

The AD9837 module outputs a square wave with a phase of 0 and a frequency of 1000Hz. Connect a oscilloscope at OUT port to observe the output waveform and data.

/*
 * Output square wave signal;
 * The amplitude of square wave signal is about equal to VCC voltage;
 */
#include <DFRobot_AD9837.h>

uint8_t ssPin = 5;
DFRobot_AD9837 AD9837(/* fscPin= */ssPin, /* *pSpi= */&SPI);   //Init an instance. Call class interface by this instance. 

void setup(void)
{
  AD9837.begin(/* frequency= */10000000); //Init SPI communication, frequency:SPI communication max frequency
  AD9837.outputSquare(/* divide= */AD9837.eDIV2_1, /* phase= */0, /* freq= */1000.0);
  //Output square wave with phase 0 and frequency 1KHz. eDIV2_1: Output MSB of DAC data, eDIV2_2: Output MSB/2 of DAC data; 
}

void loop()
{
  delay(100);
}

Expected Results

Result 6

API Function Library

/************************ Init ********************************/
  /**
   * @fn DFRobot_AD9837
   * @brief Constructor
   * @param fscPin - active-low control pin, pull down for SPI data transfer
   * @param pSpi - extern SPIClass SPI is defined in SPI.h; so just get SPI object address and the methods in SPI can be pointed to and used
   * @return None
   */
  DFRobot_AD9837(int8_t fscPin=5, SPIClass *pSpi=&SPI);

  /**
   * @fn begin
   * @brief Init function, including SPI communication init, module power-on reset
   * @param frequency - the maximum frequency of SPI communication
   * @return None
   */
  void begin(uint32_t frequency=20000000);

/************************** Config function ******************************/
  /**
   * @fn moduleReset
   * @brief Reset internal registers to 0, this corresponds to an analog output of midscale.
   * @param mode - eReset_EN: reset internal register; eReset_DIS: quit reset status
   * @return None
   * @note RESET operation will not reset the phase, frequency, or control register.
   */
  void moduleReset(eControlRegBit_t mode=eReset_DIS);

  /**
   * @fn moduleSleep
   * @brief The parts of AD9837 that are not in use like the internal clock and DAC can be powered down through the sleep function to minimize power consumption. 
   * @param MCLK - eSleepMCLK_NO: enable internal MCLK; eSleepMCLK_YES: disable internal MCLK. The DAC output remains at its present value as the NCO is no longer
   * @     accumulating.
   * @param dacMode - eSleepDAC_NO: keep DAC active; eSleepDAC_YES: power down on-chip DAC. This is useful when AD9837 is used to output MSB of DAC data.
   * @return None
   * @note  RESET operation will not reset the phase, frequency, or control register.
   */
  void moduleSleep(eControlRegBit_t MCLK=eSleepMCLK_NO, eControlRegBit_t dacMode=eSleepDAC_NO);

/************************** Performance function ******************************/
  /**
   * @fn outputSin
   * @brief OUT  The pin outputs sine wave
   * @param phase - Adjust phase offset, range: 0-360, unit: degree (corresponding to waveform phase offset of 0-2π)
   * @param freq - wave frequency, range: 0.06-8000000.00, unit: Hz
   * @return None
   * @note Recommended frequency range: 60-600000Hz, actual resolution is about 0.06Hz, which is obtained by dividing 16MHz by 2^28 
   */
  void outputSin(uint16_t phase, float freq);

  /**
   * @fn outputTriangle
   * @brief OUT  The pin outputs triangle wave
   * @param phase - adjust phase offset, range: 0-360, unit: degree (corresponding to waveform phase offset of 0-2π)
   * @param freq - wave frequency, range: 0.06-8000000.00, unit: Hz
   * @return None
   * @note Recommended frequency range: 60-600000Hz, actual resolution is about 0.06Hz, which is obtained by dividing 16MHz by 2^28
   */
  void outputTriangle(uint16_t phase, float freq);

  /**
   * @fn outputSquare
   * @brief OUT  The pin outputs square wave
   * @param divide - eDIV2_2: MSB/2 of DAC data is output through VOUT pin; eDIV2_1: MSB of DAC data is output via VOUT pin.
   * @param phase - adjust phase offset, range: 0-360, unit: degree (corresponding to waveform phase offset of 0-2π)
   * @param freq - wave frequency, range: 0.06-8000000.00, unit: Hz
   * @return None
   * @note Recommended frequency range: 60-600000Hz, actual resolution is about 0.06Hz, which is obtained by dividing 16MHz by 2^28
   */
  void outputSquare(eControlRegBit_t divide, uint16_t phase, float freq);

Compatibility

MCU Work Well Work Wrong Untested Remarks
Arduino UNO
Arduino MEGA2560
Arduino Leonardo
FireBeetle-ESP8266
FireBeetle-ESP32
FireBeetle-M0
Micro:bit

FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents