AVR controlled DDS generator software writing

During my spare time, I am developing the program for the AVR controlled DDS generator. I decided to write software using the WinAVR tool-set. How far ahead I have moved with this?

I have implemented:

  • Menu system;
  • Reading previous generator configuration from EEPROM;
  • Setting signal mode;
  • Storing last generator configuration to EEPROM to be loaded after reset;
  • Four types of signal output (square, sawtooth, triangle, and sine wave);

Things I still need to do:

  • Ability to change signal frequency;
  • Implement other signals (listed below);
  • Make program clean-up;

Signals in AVR controlled generator:

  • 0 – OUT_|¯|_ – square wave;
  • 1 – OUT|/|/| – sawtooth;
  • 2 – OUT|\|\| – reverse sawtooth();
  • 3 – OUT/\/\/\ – triangle);
  • 4 – OUT~~~~ – sine wave);
  • 5 – OUT-NOISE – noise signal();
  • 20 – PWM-OCC – timer output compare mode();
  • 21 – PWM-SINMDS sine wave modulated PWM();
  • 22 – PWMSQSMDS – sine wave modulated PWM. PWM positive, SQ negative polarity();
  • 23 – PWM-CMDS – custom PWM. Will be possible to set custom duty cycle();

Signal generation

Square, sawtooth, triangle, and sine waves are generated by reading values from flash memory. The fragment of the sine wave is as follows:

//signals saved in flash memory
const uint8_t sinewave[] PROGMEM= //256 values

The same is with square, sawtooth, and triangle. Each wave is stored using a 256 value table.

A signal is generated using a simple function:

void signalOUT(const uint8_t *signal)
uint8_t i;

Using this function, the maximum generated signal frequency was 6,25kHz. This means that one signal period consists of 256 values from the signal table. The crystal frequency is 16MHz. One value from the table requires 16000000/(6250*256)=10 clock cycles.

Changing the frequency of those signals should be easy. Just insert inside loop delay function regarding selected frequency. This I will do later.

I still don’t know if it is worse to try to increase the maximum frequency of the signal. Now it is 6,25kHz and takes 10 clock cycles for one byte from 256 to output. If I reached 5 cycles, that would be double frequency 12,5kHz.

In another hand, if higher frequencies are needed there will be a possibility to use a timer signal generator on output compare mode, but only square waves.

Now I am going to focus on implementing what I have planned and then think about optimization.

Bellow are signal pictures I have got at frequency 6,25kHz(picture quality is poor – I need to get a tripod for my camera):




Sine wave

The source code of the current program is here: AVR controlled DDS generator software

Full documentation is on its way.


  1. interesting… i have made some changes for me on this code.
    maybee you are intrested in..
    how do you want to change the frequency of the output?

  2. I am comming with an improved code where I use DDS algoritm (use accumulator variable) where I can change frequency very easely by changing this value. This algorithm in this article is first one to test my hardware. I hope to finish this project very soon and publish it here.

Leave a Reply