Go Down

Topic: Advantages of DAC over PWM for synthesizer tone generation? (Read 2824 times) previous topic - next topic

jon_s

Adafruit offers a new 12-bit DAC breakout that operates over I2C:
http://www.adafruit.com/products/935

I imagine this might be an easier way to output synthesized sound than using PWM output filtered in hardware, no? What are the advantages/disadvantages?

It looks like the I2C interface can operate 100kbps on the standard (arduino-capable) mode -- what does that mean in terms of output frequency range?

Thanks for any help!

Grumpy_Mike

Quote
this might be an easier way to output synthesized sound than using PWM output filtered in hardware,

Yes that is right.

Quote
It looks like the I2C interface can operate 100kbps on the standard (arduino-capable) mode -- what does that mean in terms of output frequency range?

It takes about 10 bits to transfer a byte, two bytes per sample and you only get 5K samples a second, that translates into a maximum frequency of 2.5KHz, so not fast enough.
You can get I2C devices that run faster, 400Kbps and 1Mbps, but you will need a faster library to run at this speed, like this one:-
http://dsscircuits.com/articles/arduino-i2c-master-library.html

With PWM you have to work with either an ultrasonic frequency or with a good tight filter.

DVDdoug

Quote
It looks like the I2C interface can operate 100kbps on the standard (arduino-capable) mode -- what does that mean in terms of output frequency range?
I don't understand the limitations of PWM, but regular DACs work with PCM.

With PCM, you sample the "height" of the waveform at regular intervals at a pre-determined bit depth.    Audio CDs are sampled at 44.1kHz (44,100 times per second) at 16-bits x 2 channels.    That tells you how much data you need to transmit...  If you multiply to find the bitrate (number of bits per second) that works-out to 1411 kbps for CDs.  (The Nyqyust theory says you need at least 2 samples per cycle, so with a 44.1kHz sample rate, the audio bandwidth is limited to 22,050Hz.)

Depending on your application, you might need a buffer so that your CPU can go-off and do some other processing.  But in that case, you need a transmission channel that can transfer in bursts faster than the required/calculated average bitrate.

MarkT

A DAC (with a parallel interface) can be given a new sample every few instructions, the sample can be 8, 10, 12 bits or whatever.  Upto several 100,000 samples per second is reasonably straightforward.

With PWM you get a sample every cycle of the PWM and the cycletime is 2^(sample size). 

So for 8 bit output at 10,000 samples per second you need 2,560,000Hz clock for the PWM.  Moving to 16 bit samples would need 655MHz clock, 16 bit samples at 48kHz would need over 3GHz clock.

So for large numbers of bits per sample PWM gets unwieldy.  However a parallel DAC is also unwieldy for the Arduino as it doesn't have lots of spare pins to use.  For a synthesizer I expect at least 12 bits is a requirement.

SPI is thus perhaps the best interface for a DAC on the Arduino since the hardware runs to 8Mb/s max and is easy to drive.

If you are happy for only 8 bit accuracy then PWM is reasonable alternative.  An R-2R ladder is also attractive (less low-pass filtering needed, but 8 pins used up).

For real-world audio ADCs and DACs these days sigma-delta converters rule - usually using the I2S bus or similar which is a bit beyond the capabilities of the ATmega processors to drive alas.
[ I won't respond to messages, use the forum please ]

Tuttut

Hi, one important advantage of a DAC over PWM is that you can filter the supply of the DAC from digital noise generated by the rest of the circuit. Therefore if you want good noise performance it is often easier to use a DAC. Some time ago I've build a synthesizer with the MCP4922 or MCP4921 which gave 12-Bit audio quality. Now I know that you can also get good results just by combining two 8-Bit-PWM-Outputs to one 16-Bit-Analog-Output. This can be done very cheap using only a few resistors.

And if you even wonder how CD-quality DACs nowadays work: Not with PWM and 3 GHz but also just with 1 Bit that is clocked often in a region of 10-20 MHz. The magic is not using a counting-ramp like PWM does but using a more intelligent solution called Delta-Sigma-Modulation that could be seen as some kind of dithering.


Go Up