A simple arduino signal generator

I make a Arduino Signal Generator that build on protoshield.

The principle of this signal generator is like a 8bit DAC, so just need some resistors everyone can build it on Arduino . I make a prototype on the Arduino prototype shield :

The schematic is very sample .Note that one thing, the higher precision resistors you used , the better effect.

How to write the code ? On the contrary of using a ADC , the same 8bit for a voltage express, 0xFF means 5V(Depend on your I/0 voltage level) and 0×00 means 0V, VCC divided into 256 , each represents a voltage value.
For the sine wave , we could build a voltage table for the waveform , divided a cycle into 256 :

unsigned char sin_tab [256] = {
127,130,133,136,139,142,145,148,151,154,157,160,164,166,169,172,175,178,181,184,187,189,192,195,
197,200,202,205,207,210,212,214,217,219,221,223,225,227,229,231,232,234,236,237,239,240,242,243,
244,245,246,247,248,249,250,251,251,252,252,253,253,253,253,253,254,253,253,253,253,252,252,251,
251,250,249,249,248,247,246,245,243,242,241,239,238,236,235,233,231,230, 228,226,224,222,220,218,
215,213,211,209,206,204,201,199,196,193,191,188,185,182,180,177,174,171,168,165,162,159,156,153,
150,147,144,141,137,134,131,128,125,122,119,116,112,109,106,103,100,97,94,91,88,85,82,79,76,
73,71,68,65,62,60,57,54,52,49,47,44,42,40,38,35,33,31,29,27,25,23,22,20,18,17,15,14,
12,11,10,8,7,6,5,4,4,3,2,2,1,1,0,0,0,0,0,0,0,0,0,0,1,1,2,2,3,4,5,6,7,8,9,10,11,13,14,16,17,19,21,22,24,
26,28,30,32,34,36,39,41,43,46,48,51,53,56,58,61,64,66,69,72,75,78,81,84,87,89,93,96,
99,102,105,108,111,114,117,120,123,127};

Of cause , it can be divided it into 512,1024, the more subdivision the better effect.

void setup()
{
 DDRD =0xFF;  
}

void loop()
{ 
  for (int i=0;i<256;i++)
    PORTD=sin_tab[i]
}

void setup()
{
 DDRD =0xFF;  
}

void loop()
{ 
  for (int i=0;i<256;i++)
    PORTD=i;
}

void setup()
{
 DDRD =0xFF;  
}

void loop()
{ 
  PORTD=0xFF;
  delayMicroseconds(100);
  PORTD=0;
  delayMicroseconds(100);
}

:wink: Another Interesting waveform generated by this shield

More about this gadgets :
http://iteadstudio.com/application-note/arduino-signal-generator-build-on-protoshield
http://iteadstudio.com/iforum/viewtopic.php?f=18&t=19&p=34#p34

Very good tutorial.

Thanks

Hello, guys im a HAM radio user my call sign is YO3IGH and im looking for a way to generate 5 tones with a specific space between them 20ms and the tones with diferent frecvency value with the duration of 20ms aswell(EEA standard). This is caled 5tone signaling and is used in two way radios to identify radios, it wool be ideal to be able to decode them aswell but for now i wood be glad to be able to generate them. This is some info about the select five systems http://en.wikipedia.org/wiki/Selcall. Please help me if you know a way to do this or a similar project with Arduino. Thank you verry much :)

Good work ITead! I believe you just built an R/2R ladder. There are integrated chips that have all the resistors already laid out as the way you soldered. I've asked a similar question, here's the post: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1275426082

Richard gave me a link to an R/2R ladder sold at mouser.com Give it a try if you want to make your circuit more compact!

@JonnyRadu[ch65306] It's easy to make any frequency of square wave and triangular wave -- of cause in the frequency bands that AVR I/O can support.

But I still want to find a better way to make the sine wave without using table, it's hard to generate the specific frequency in this way.

@liudr ;) Just build it as a toy, in practical application this R/2R ladder chip will better .. like a standard 5tone generator :P

Thanks ITead :) I will try to build it, im new to Arduino and im not verry good with programing, the hardware part is not a problem for me but i have some isues with the darn libraries, and for instance in your code for this where do you define the outputs I see in the schematic you are using the Digital output pins D0 -D7 and D12, but in the code this is not set.

PORTD include from D0 to D7 . It's a I/O register.

And DDRD =0xFF means pinMode(0,OUTPUT) to pinMode(7,OUTPUT)

But I don't use the D12 for button now (in shield I use D10), it can used as a switch button for different waveform.

Thanks ITead i understand now, i got a litle progres with my project if you want to see this is the link http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1279653779