Go Down

Topic: DAC (Read 2 times) previous topic - next topic

baum

I have asked about DACs before, but it was about I2C addressing.

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.

CrossRoads

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. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

baum


weirdo557

watch out! sin() doesnt take input in degrees, it uses radians. convert them first!

Grumpy_Mike

Also it takes quite a time so the frequency won't be very high, you are better off with a look up table.

baum

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

Wrong way round. A look up table normally consists of say 512 samples, each one has a 14 bit resolution.

baum

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

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

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

How about this:

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


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

How about this:

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

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 :P :P :P :P :P [they need a "DOH!" smiley.]

pjchant


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

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

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 *)

Go Up