Using a MCU + DAC to produce a sine wave, basic questions - Page 1
Forum section: electronics / projects

author: akis
author_rank: Frequent Contributor
timestamp: October 05, 2014, 07:11:07 pm
content: Hello, I have not used a DAC before and I was thinking of using a DAC coupled on a MCU (an Arduino Nano, ATmega328P, 16MHz) to produce a sine wave.How many values should I send to the DAC per sinewave cycle?If the DAC is 16 bit, I could, in theory, send 16bit+16bit values to the DAC for every cycle, that would be a ridiculous 130,000 values per cycle. Considering that each "value" would require dozens of CPU instructions, serialising on the SPI and so on, it appears that for a simple sine wave of 1KHz, I would need a CPU running at many hundreds of MHz!So I should send fewer values per sinewave cycle. But how many do I need as minimum in order to produce a proper sine wave without artifacts?

author: tggzzz
author_rank: Super Contributor
timestamp: October 05, 2014, 07:17:27 pm
content: A good starting point would be to understand how DDS (direct digital synthesis) devices work, and why they work. There are many ICs available, e.g. the AD9851, and the theory is easy to find on the web.

author: dannyf
author_rank: Super Contributor
timestamp: October 05, 2014, 07:39:15 pm
content: QuoteThat would depend on your requirement. It would not be bad if you have 16 values per cycle; 64 or 128 points would be very good, most of the times.QuoteIf you go by 100 values per cycle, that would require 16 bits x 2 x 100 = 400 bytes, per cycle. Most spi can run at 10Mhz, so that would be 3Khz. Factoring in some over head and I think 1Khz is doable.Faster performance can be done via filtering pwm wave forms (best for fixed frequencies), or parallel dacs (r2r).Going DMA + parallel dac would be your best bet, short of using a dedicated dds / generator chip.

author: microbug
author_rank: Frequent Contributor
timestamp: October 05, 2014, 09:20:01 pm
content: AD9850 modules are very cheap on eBay. As far as I can tell, the chips on them are genuine.

author: Skimask
author_rank: Super Contributor
timestamp: October 05, 2014, 09:37:47 pm
content: Quote from: microbug on October 05, 2014, 09:20:01 pmYep, genuine enough anyways. I've got a dozen or so here, tried them all after I saw a previous thread talking about the AD9850. For ~$10, can't beat them.http://www.ebay.com/itm/AD9850-DDS-Signal-Generator-Module-for-Arduino-output-Brand-New-/390943463809?pt=LH_DefaultDomain_0&hash=item5b060bd981

author: tggzzz
author_rank: Super Contributor
timestamp: October 05, 2014, 09:46:18 pm
content: Quote from: dannyf on October 05, 2014, 07:39:15 pmTo use an engineering euphemism, in theory that would be "sub-optimal". (But in practice it might be satisfactory depending on the required maximum frequency and purity of the sinewave, and what hardware is available "for free".)Have a look at the data sheet for an AD9851, and you will see a circuit that gives a respectable sine wave output at (1Hz up to) 50MHz with "only" a 180MHz clock, i.e. a ratio of 3.5:1, nothing like 16:1 or 100:1!Filtering PWM is normally a bad starting point since it unnecessarily maximises the filtering problems. No low-power DACs use that method, although high current systems might.Whatever version of a DAC you use and however you get the output to the DAC, implementing a DDS in hardware or software is flexible, simple and the optimal way of calculating the amplitude of each sample.Be aware that clock jitter (=>DAC sample jitter) will significantly affect the purity of the sinewave.

author: akis
author_rank: Frequent Contributor
timestamp: October 06, 2014, 04:01:41 am
content: I did find them on ebay and bought a couple of these to try out:http://www.ebay.co.uk/itm/231202544286?_trksid=p2059210.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AITWhen it arrives I will try to link it to my Arduino Nano and see how it goes.

author: tggzzz
author_rank: Super Contributor
timestamp: October 06, 2014, 08:47:37 am
content: Quote from: akis on October 06, 2014, 04:01:41 amA little investigation might be in order.I bought a cheap Chinese 9851 DDS which was a simple implementation of one of the diagrams in the data sheet. There is a similar diagram in the 9850 data sheet, which your device might have implemented.I found a problem related to the square wave generation. When the comparator in the 9851 switched, a significant glitch appeared on the filtered analogue sinewave output. The solution was to modify the board so as to prevent the comparator switching. I can't remember the details, but I probably disconnected the comparator input from the sinewave and tied it to a rail.YMMV, obviously.

author: void_error
author_rank: Frequent Contributor
timestamp: October 06, 2014, 11:25:47 am
content: Quote from: akis on October 06, 2014, 04:01:41 amI wouldn't trust something 20x cheaper than the chip itself. There's probably a reason the AD9850 costs at least $15.Here's another DDS you can look at, it's about $10 in one-off quantities on TMEhttp://www.analog.com/static/imported-files/data_sheets/AD9835.pdfor this onehttp://www.analog.com/static/imported-files/data_sheets/AD9833.pdf

author: akis
author_rank: Frequent Contributor
timestamp: October 06, 2014, 12:37:15 pm
content: It could be that these chips are failed parts which some industrious employee has retrieved from the rubbish bins... Actually most electronics modules on ebay could very well be thus. But somehow they work else noone would be buying after a while.