Fork me on GitHub

Project Notes

#148 AD9833 Basic Demo Cycle

Run a basic waveform demo with an AD9833 module

The Build


I bought an AD9833 module from a seller on aliexpress with the intention of using it to build a function generator to add to my collection of test gear.

This project is a first test to explore:

  • the SPI protocol it supports
  • different waveforms it can produce
  • controlling the frequency


  • once you get the SPI configuration correct, it works extremely well, and is very easy to control.
  • accuracy at frequencies under 1MHz or so is very good
  • accuracy over 1MHz inconclusive .. I need to do some more testing

Module Interface

Here’s the module, with pins attached (with my imperfect soldering, so don’t blame the manufacturer!):

module front

module rear

The labeling of the pins is a bit unusual. Here’s the pin definition, and how they connect to an Arduino Uno for hardware SPI:

Pin Usage Arduino SPI Pin
VCC 2.3V to 5.5V  
DGND digital ground  
SCLK SPI clock 13 SCK
FSYNC SPI slave select (SS) 10 SS
AGND analog ground  
OUT output signal  

NB: the “analog ground” is internally linked to “digital ground” according to the circuit diagram for the module.

SPI Specifics

The module operates in SPI_MODE2 with MSBFIRST:

  • data shifted on falling edge
  • FSYNC pin is active low,
  • accepts the most significant bit (MSB) of each transfer first.
  • The SCLK pin is also specified to be kept high when not in use

Waveform demo

The BasicDemoCycle.ino script is a simple non-interactive demo that runs through the different waveforms.

It uses the new SPI.beginTransaction/SPI.endTransaction syntax, although since the script only works with one SPI device, it is redundant to wrap each command sequence in a transaction. But it is a good test of the “right way to do it”. NB: many other scripts found on the net pre-date this syntax.

It is running at very low frequencies in order to produce a visual demo. It sends the measure waveform to the serial port. LEAP#090 PlotNValues (a simple Processing sketch) reads the data from the serial port and plots the output value over time, with some coloration effects thrown in for good measure.

Here’s a sample trace. It shows a few cycles of each waveform. From the left:

  • sine wave
  • square wave (normal cycle time)
  • triangle wave
  • square wave (halved cycle time i.e. twice as fast)
  • output off

Note that square waves are rail-to-rail, since they bypass the DAC. Other waveforms peak at 0.65V per the datasheet.

processing trace

Frequency Accuracy?

A few quick measurements with a frequency counter gave very good results under a few MHz. But when I started pushing into the 6-12.5MHz realm, accuracy appeared to drop off markedly.

This may simply be the influence of running the module on a breadboard. I should try it on a PCB.

For now, here are some results (AC-coupled scope traces) with a sinusoid waveform in the breadboard layout.

At 1MHz, still a decent output:

scope_1MHz trace

By 8MHz, the waveform is quite distorted and unstable but still on frequency:

scope_8MHz trace

By 12MHz, it has devolved to a heavily-modulated mess:

scope_12MHz trace


NB: I created a custom Fritzing Part available here for these diagrams.


The Schematic

Running at 300kHz, pretty accurate!

The Build

Credits and References

Project Source on GitHub Project Gallery Return to the LEAP Catalog

This page is a web-friendly rendering of my project notes shared in the LEAP GitHub repository.

LEAP is just my personal collection of projects. Two main themes have emerged in recent years, sometimes combined:

  • electronics - usually involving an Arduino or other microprocessor in one way or another. Some are full-blown projects, while many are trivial breadboard experiments, intended to learn and explore something interesting
  • scale modelling - I caught the bug after deciding to build a Harrier during covid to demonstrate an electronic jet engine simulation. Let the fun begin..
To be honest, I haven't quite figured out if these two interests belong in the same GitHub repo or not. But for now - they are all here!

Projects are often inspired by things found wild on the net, or ideas from the many great electronics and scale modelling podcasts and YouTube channels. Feel free to borrow liberally, and if you spot any issues do let me know (or send a PR!). See the individual projects for credits where due.