Go Down

### Topic: DAC (Read 4715 times)previous topic - next topic

#### baum

##### Feb 04, 2011, 02:07 am

Now I want to make a sine wave. Is there any equation I can easily implement to create a 5V peak to peak sine wave? I don't really care much about the frequency, and I want to get as close to a "true" sine wave without to caps, just the arduino and DAC.

#1
##### Feb 04, 2011, 02:44 am
Isn't there a sin function in the reference section?
for x=0 to 360 {
output = sin(x), output will be -1 to 1, offset/scale as needed to make your DAC happy
ex, add 1 to output such that output is 0 to 2, and mutiply by 2.5
send to DAC
x=x+1 (or .5, or ,1, or ...)
}
repeat as needed
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#2
Thanks!

#### weirdo557

#3
##### Feb 07, 2011, 09:25 am
watch out! sin() doesnt take input in degrees, it uses radians. convert them first!

#### Grumpy_Mike

#4
##### Feb 07, 2011, 10:39 pm
Also it takes quite a time so the frequency won't be very high, you are better off with a look up table.

#### baum

#5
##### Feb 07, 2011, 10:45 pm
So I could calculate 16384 values for my 14-bit resolution DAC, store them in a very large int array, and then just read it?

#### Grumpy_Mike

#6
##### Feb 07, 2011, 10:47 pm
Wrong way round. A look up table normally consists of say 512 samples, each one has a 14 bit resolution.

#### baum

#7
##### Feb 07, 2011, 10:47 pm
Nevermind-- just realized that comes out to about 64KB! using floating point.

Some help? I basically want a primitive function generator with the highest frequency range and the greatest range.

#### billroy

#8
##### Feb 07, 2011, 10:53 pm
Searching for "Arduino DDS" or Direct Digital Synthesis will yield a trove of threads that do approximately what you want.

-br
http://bitlash.net
http://entropymouse.com

#### baum

#9
##### Feb 07, 2011, 11:46 pm
But I want to use a DAC, and I don't have 4.7mH inductors.

Store a lookup table in Memory, consisting of a some (?) values pre-calculated

Loop these values, with delay on each loop setting freq.

i.e. a delay of 10usecs on each iteration will have a higher frequency than one with 100u secs.

How many lookup values should I have?

#### cr0sh

#10
##### Feb 08, 2011, 12:09 am

But I want to use a DAC, and I don't have 4.7mH inductors.

Store a lookup table in Memory, consisting of a some (?) values pre-calculated
Loop these values, with delay on each loop setting freq.

i.e. a delay of 10usecs on each iteration will have a higher frequency than one with 100u secs.

How many lookup values should I have?

Remember that if the wave is of a regularly repeating nature, of equal amplitude on both sides (like a standard sine wave), you can get by with a look-up table of only one-quarter of the wave, then just mirror/flip this table as needed to generate a complete waveform (to reduce memory needs)...
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

#### baum

#11
##### Feb 08, 2011, 12:14 am
OK. so my 14-bit DAC should operate at max with a lookup table of 1024 values?

1024 for bottom left, another 1024 for top left, 1024 for top right, 1024 for bottom right.

Edit: 4096/4=1024 values, right?

DOH! its 12-bit resolution [they need a "DOH!" smiley.]

#### pjchant

#12
##### Feb 13, 2011, 04:55 pm

Nevermind-- just realized that comes out to about 64KB! using floating point.

You could save some space by only storing the first 1/4 of the sine.  Store data for the first quarter from 0 to 1.0.  Read the table from 0-90 deg forwards.  Then from 90-180 deg read the stored data back "backwards".  Repeat for 180-360, but swap the sign.

Still 16KB though!

#### Grumpy_Mike

#13
##### Feb 13, 2011, 05:30 pm
Quote
OK. so my 14-bit DAC should operate at max with a lookup table of 1024 values?

You are mixing up the amplitude resolution (based on the resolution of your D/A) which is the size of the numeric entries in the look up table with time resolution which is the number of entries in your look up table.
A look up table of 128 entries will be just fine as most of the time you will not be outputting every entry because the size of increment of the address gives you the frequency of the final note. Not that this increment can be fractional and you only need use the integer part of the address.

#### jluciani

#14
##### Feb 27, 2011, 02:48 pm
How "true" depends on the resolution and the sampling frequency.

I have a sine wave example at http://wiblocks.luciani.org/docs/app-notes/nb1a-nco.html
The articles referenced at the bottom of the page discuss THD trade-offs.

(* jcl *)
www: http://www.wiblocks.com

Go Up

Please enter a valid email to subscribe