Direct Digital Synthesizer (DDS) (Part 1)

Part 12345678, 9

Direct Digital Synthesizer (DDS) is a type of frequency synthesizer used for creating arbitrary waveforms from a single, fixed-frequency reference clock. The principle of operation is fully and nicely expained here.

This post describes how to turn Arduino in a pretty attractive DDS with a few external components.


There are two options for generating the waveforms: the Digital to Analog Converter (DAC) could either use the Pulse Width Modulator (PWM) function (writeAnalog()) or build a R2R ladder. The first option requires the use of carefully choosen RLC filter, and not every body has a collection of inductors, while the R2R ladder option ‘only’ requires resistors. But these resistors must be high precision grade (1% or less): we will use this option. You may choose C1 value depending upon the target frequency (or frequency range); C1 shall be no more than 30 pF for achieving the highest frequency (so as to say 16 kHz) . If you are interested by the first option (PWM), have a look at this nice site.

Here is a suggestion for the hardware interface

Please note the two outputs. Ouput1 will deliver a 0 to 5 V signal while Ouput2 will deliver a 0 to 2.5 V signal. This second one shall be used as the input for a buffer Operational Amplifier (Op. Amp.); again, not all of us have rail to rail Op. Amps. in their drawers. A simple LM358 or equivalent will do the job perfectly. We will get back to this in the advanced designs.

The choice of PORTB0:5 was driven by the need for simplicity while setting bits: using PORTD2:7 requires a bit shift to leave PORTD0:1 (Serial comm port) in peace. We could have use PORTC0:5 too (Analog ports can be used as digital ports, read this)

I built a very simple R2R ladder which fits to Arduino shields and avoids long lasting cabling time.

See the ground pin which is free standing. When using PORTB, the ground comes next to the MSB pin. This how it looks like when snapped on a shield; the other advantage of using a preassembled module is that we leave the shield free from the R2R ladder components.

Part 2


  1. My Arduino says:

    I admire your postregarding Arduino. I am sure you have put a considerable amount of thought into writing it. 🙂

    Right now, I have a website which sells Arduino circuit boards and all of the related accessories. They are all imported from overseas.

    Finally, people in Malaysia can own an Arduino. In case you know a Malaysian friend, do inform them of this website.

    Thank you very much. I appreciate your kind effort. Stay in touch.

  2. JackAubrey says:

    Hello Didier

    I’m really interested in this R2R ladder which I plan to use to create a sound generator.
    I made a first test with only a 4 bits input and using an analog input to measure voltage. It gives great results even if I’m not using very precise resistors.
    My question is, is there a way to get an output from -2.5v to 2.5v instead of 0 to 5V?

  3. Didier says:

    Dam good question!
    There is an alternative.
    – If the target device ground is floating versus Arduino ground, just create a virtual ground and generate a 5V signal. Easy.
    – If the target device ground is wired to arduino ground, you will have to generate a -2.5V (at least) and buffer the output signal with an appropriate op amp (wired as an inverter).

    Here are a couple of hints:
    – You could use a pwm output to drive an inverter (Charge pump capacitor). Even with a weak throughput, you could achieve -3V. Or use a builtin DC-DC inverter. Or use a MAX232!
    – Prefer a rail to rail op amp for the output stage.

    I may design something like that in the next future.

  4. JackAubrey says:

    Thanks for this answer.

    – For the moment target device is a simple speaker, wired to Arduino ground.

    – speaking of op amp, I found this sketch which seems to fit what I want to do.

    It is said that if R1 = Rf and R2 = Rg then Vout = V2-V1.
    If V2 is the output of R2R ladder and V1 is set at 2.5V (using a voltage divider and Arduino 5V output) it shoud give me exactly what I want.

    – I’m going to pass on the MAX232.

    – If I understand well, rail to rail op amp is to be preferred in order to avoid saturation.

  5. Didier says:

    What you need is even simpler!
    Connect a rail to rail op amp wired in voltage follower mode. Attach the positive lead of 100uF capacitor to the op amp output and the negative lead to one speaker input. Connect the other input of the speaker to ground. That’s it!

    What’s the benefit of the rail to rail op amp?
    If this amplifier is wired in voltage follower mode and fed with 5V, a 0V input will generate a 0V output and a 5V input will generate a 5V output, while many older op amp will not be able to get down to 0V or will not be able to go up to 5V.

    Now, if the signal from the DDS does not exceed 2.5V, you can use a simple LM358 or so. This chip is able to get down to 0V and up to VCC minus 1.5V.

    Unless I miss something…

  6. JackAubrey says:

    I think I’m the one who is missing something! I’m just starting electronic and Arduino and it is my first personal project after some tutorials. It is a lot of fun but kind of slow!

    I studied op amp at school but I forgot a lot about it. I think I need to learn about those “buffer” before anything else in order to understand your solution.

    Thanks a lot for your help! I keep you informed of my progress on this matter. And I can’t wait to see what you mean when you say “I may design something like that in the next future”. Based on the things I have seen in your blog, I’m sure it’s going to be very interesting for me.

Leave a Reply

You must be logged in to post a comment.