Why use DAC when we have PWM?

One of the advantages cited for Arduino Due is that it has DAC. However, I am wondering is DAC really necessary when we can use PWM. Am I wrong?

2 Likes

PWM is a kind of "pseudo- DAC" since the voltage provided still hits the 5V everytime: it's just the average which gives the illusion of say 2v or 3.5v or whatever because of the duty cycle. So if your device can't handle 5v, the say 3.5v you give it from a DAC is actually 3.5v while from PWM it's still 5v, albeit in pulses.

2 Likes

The real answer is resolution.

If you want to have 16 bit PWM, you need to be able to count to 65335 very fast, the speed at which you can do this gives you the PWM Frequency for the given resolution -

An Arduino UNO can do 8-bit PWM (16,000,000/255) at 62,745 Hz, which is well outside the audio spectrum.

At 16 Bits (16,000,000/65535), this drops to 244 Hz well inside the audio spectrum and therefore not a practical solution for most applications.

Duane B

rcarduino.blogspot.com

The other problem with the PWM approach is, you have to use a low-pass filter to smooth
out the PWM signals, and you'll always have a bit of ripple on the analog output signal.

If all you need is essentially an unchanging [ie, DC] output voltage, then the ripple will
eventually decay out, but if the output analog needs to be changing, then you have a problem
of choosing low-pass filter characteristics that adequately filter the PWM transitions but still
give enough dynamic response to follow the signal changes. As Duane mentions, for this to
work well in general, you need very fast PWM frequencies, up into the Mhz range.

There are a lot of calculations involved, too much to go into here. Antialiasing, 3dB frequencies,
rolloff characteristics, dynamic response, amount of ripple allowable, on and on. A lot of
maths.