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

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

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

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

Result

Result 5

Was this article helpful?

TOP