I’ve picked up some cheap AD9833 based signal generator boards which look particularly interesting as they are programmable frequency generators capable of generating a sine, square or triangle wave at frequencies up to 12.5MHz and are controlled using the SPI bus from the Arduino.
- In part 2, I add some simple controls.
- In this part, I add MIDI.
- Finally, in this part I stack several of these modules up for a multi-oscillator system.
Warning! I strongly recommend using an old or second hand keyboard for your MIDI experiments. I am not responsible for any damage to expensive instruments!
These are the key Arduino tutorials for the main concepts used in this project:
If you are new to Arduino, see the Getting Started pages.
- Arduino Uno
- AD9833 signal generator module
- Amplification/speaker for output
- Breadboard and jumper wires
I don’t have a graphic for the AD9833 module, but mine has the connections listed above and looks like the one in the following photo.
It requires the following connections to the Arduino:
- VCC to 5V
- GND to GND
- SDATA to MOSI (D11)
- SCLK to CLK (D13)
- FSYNC to an Arduino digital pin (D10)
And AGND and OUT are the waveform output, a DC-biased signal in the range 0.038 to 0.65 V according to the datasheet, which is adequate for an audio signal.
A note of caution – in my testing, when requesting a square wave, I seem to get a full 0 to 4.75V peak waveform… usual caveat applies – be cautious of what you use for testing! Don’t plug it into any expensive equipment!
MajicDesigns has produced a library for interfacing with the AD9833, which can be obtained from the Arduino Library manager if you look for MD_AD9833. To use the example test program also requires the MD_cmdProcessor library from the same source.
The code uses the standard Arduino SPI hardware pins by default so it should run with the above connections “as is”. It is possible to change that and use a “software SPI” implementation and a different set of pins if required.
The test program provides a command interface using the serial monitor where you can set the frequency and other parameters of the board. This is the help text from the test program running.
[MD_AD9833 Tester] Ensure line ending set to newline. ? Help h Help f1 f Frequency 1 to f Hz f2 f Frequency 2 to f Hz p1 p Phase 1 set p tenths degree (1201=120.1) p2 p Phase 2 set p tenths degree (1201=120.1) of c Output Frequency source channel [c=1/2] op c Output Phase source channel [c=1/2] ow t Output Wave type [t=(o)ff/(s)ine/(t)ri/s(q)re] or h Reset AD9833 registers (hold if h=1)
In the photo below you can see the results of the following commands:
f1 440 Freq 1: 440.00 ow t Output wave: t
This looks like a nice little module and the library seems to make it easy to control. It would be nice now to build in some physical controls, such as a change mode button and a frequency control either from a potentiometer or even via MIDI.
I also spotted someone soldering an AD9833 module directly to an Arduino Nano creating quite a small package, so I might investigate that too and it looks, on initial reading, like it might be possible to hook up several of these modules to an Arduino too.