Example Code for Arduino UNO-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.

Hardware Preparation

  • DFRuino UNO R3 (or similar) x 1
  • AD9837 DDS Waveform Generator Module x1
  • Jumper wires
  • Oscilloscope x1

Software Preparation

Wiring Diagram

Connection 2

Connection description

  • AD9837 DAT to controller 11/MOSI
  • AD9837 CLK to controller 13/SCK
  • AD9837 FSC to controller pin 5 (ssPin in the code)
  • AD9837 VCC to controller 5V
  • AD9837 GND to controller GND
  • AD9837 AGND to Oscilloscope GND
  • AD9837 OUT to Oscilloscope Signal Input

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

/*
 * 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);
}

Result

Result 6

Was this article helpful?

TOP