This project adds MIDI receiving to the AD9833.
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:
- Arduino Input Pullup Serial
- Arduino Analog Read Serial
- Arduino SPI Library
- Arduino MD_AD9833 Library by MajicDesigns
- Arduino MIDI Library
If you are new to Arduino, see the Getting Started pages.
- Arduino Uno
- AD9833 signal generator module
- 1x Button switch
- MIDI receive module (see: Arduino MIDI Interfaces)
- Amplification/speaker for output
- Breadboard and jumper wires
This is essentially the same circuit as for the AD9833 Signal Generator – Part 2 but I’m not using the potentiometer (although that may come back later) and with the addition of a MIDI link to the RX pin.
Recall that the AD9833 itself 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)
The MIDI handling is the now quite familiar code as used many times before, but first encountered in the Arduino MIDI Tone Module, but instead of sending frequencies out to the tone() function the code is now sending them out to the AD9833.
I’ve retained the button handling (with a minor update) from the previous project so it is still possible to cycle between sine – triangle – square – square/2 – off using the button whilst playing it from a MIDI device.
There is a problem with the square wave handling! You can hear it happening in the video – sometimes on receiving the “note off” event the board is left outputting a tone, but it isn’t a tone that registers on my oscilloscope, which is odd. If I had to set a pitch, I’d say it is around 660-700Hz. It doesn’t happen all the time, just from time to time and doesn’t seem related to any specific note being played (or turned off).
I did wonder if part of the problem is that the AD9833 doesn’t seem to have a simple way to turn off the frequency generators, so I was sending in a frequency of zero which seems to work fine for the sine and triangle wave functions.
The square wave is a bit of an odd mode as it isn’t a DDS mode as such, it is basically turning off the DDS part of the chip and just outputting the most significant bit of the DAC counter. I guess this is why it goes full 0 to 5V rather than the more modest 0 to 0.6V for the generated waves.
The data sheet describes it as follows:
The MSB of the DAC data can be output from the AD9833. By setting the OPBITEN (D5) control bit to 1, the MSB of the DAC data is available at the VOUT pin. This is useful as a coarse clock source. This square wave can also be divided by 2 before being output. The DIV2 (D3) bit in the control register controls the frequency of this output from the VOUT pin.
The implication to me being that this is almost more of a “test” mode than a genuine function of the device.
I’ve tried a number of things to get a better “note off” but nothing seems to silence the intermittent tone from turning off the square wave. Tests so far:
- resetting the device on “note off” using the AD.reset() call.
- turning the output off using AD.setMode (MD_AD9833::MODE_OFF).
- adding a AD.clearFrequency() function to bypass the frequency calculation and simply output zero to the frequency registers.
None of these have stopped it yet. It really does seem like it isn’t easy to turn the synthesis off once it starts!
Still, the sine and triangle outputs are the most useful, so I might even disable the square wave outputs anyway unless I get some inspiration as to what is causing it. The fact that I can’t see it on the scope makes me wonder if it is some kind of very high frequency output – maybe the clock signal itself (25 MHz) that my amplifier is somehow interpreting as an audio signal… but I don’t have the equipment to check that out.
I’m still slightly puzzled over the square wave issue, but I’ll work on it. For a neat little module it is certainly giving me some trouble!
Next up will be to hook up several of these modules and maybe get a potentiometer to control the frequency difference between the two. Ideally I’d have several modules each acting as an oscillator, mirroring what was going on in software in the Arduino Mozzi Additive Synthesis project.
When it comes to oscillators like this – the more the merrier! I’ll see what I can get away with…
I expect I’m rapidly approaching the time when I should solder up a simple shield for them.