Go Down

Topic: Very low frequency DAC - PWM or dedicated IC? (Read 2622 times) previous topic - next topic

rj77

Nov 15, 2016, 09:31 pm Last Edit: Nov 15, 2016, 09:57 pm by rj77
Hi, I want to be able to generate signals (sinusoids mainly) at very low frequencies ie DC -> 10hz -> 100hz. So far I have just used 8 bit PWM from an Arduino Nano and it isn't too bad.

But now I want to create a signal which is 10-12 bit and most importantly, the lowest noise possible for under $100 (cheaper is nice of course). I want it to be as silky smooth as I can get it :)

How can I achieve this? Is there an audio DAC that can operate nicely at low frequencies such as 5hz? Or am I just better off with PWM and some elaborate filtering?

Thanks very much for any tips

CrossRoads

Can run a DAC at whatever frequency you want.
For example, you can easily use this 12-bit DAC and send it data at 500 Hz, low pass filter it at 250Hz, and your 100Hz should be pretty clean if you physically separate the analog and digital signals to help keep digital noise out of the analog.
http://www.digikey.com/product-detail/en/microchip-technology/MCP4921-E-P/MCP4921-E-P-ND/716280
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.

rj77

Can run a DAC at whatever frequency you want.
For example, you can easily use this 12-bit DAC and send it data at 500 Hz, low pass filter it at 250Hz, and your 100Hz should be pretty clean if you physically separate the analog and digital signals to help keep digital noise out of the analog.
http://www.digikey.com/product-detail/en/microchip-technology/MCP4921-E-P/MCP4921-E-P-ND/716280
Thanks very much.  Could you help me to understand how this is superior to a PWM approach? Looking at eg the sparkfun dac which is a breakout of the mcp4725, it appears have to have quite broad spectrum noise. I am (probably unrealistically!) looking to produce a +/-1V sinusoid with only nV noise in the 1-100Hz band. Is this feasible?

And what sort of LPF would you advise for superior results?

Grumpy_Mike

Quote
I am (probably unrealistically!) looking to produce a +/-1V sinusoid with only nV noise in the 1-100Hz band. Is this feasible?
No.


Grumpy_Mike

You can't do better than the resolution of the A/D. On top of that you are in a digital environment so you need to have proper grounding and good PCB layout to achieve even the A/D resolution.

DVDdoug

Quote
What's the best I can hope for?
I have no idea, but it would depend on your filtering.    Do you understand what PWM is?  

Do you understand the limits of 8 bits?  With 256 steps your quantization noise is 1/256 (before filtering) and that's not even in the same universe as 1nV out of 1V.    And, that's with a normal DAC.   PWM will be worse.

rj77

I have no idea, but it would depend on your filtering.    Do you understand what PWM is?   

Do you understand the limits of 8 bits?  With 256 steps your quantization noise is 1/256 (before filtering) and that's not even in the same universe as 1nV out of 1V.    And, that's with a normal DAC.   PWM will be worse.
OK so if I used a DAC, what would you suggest in terms of filtering? Thanks

charliesixpack

A 12 bit DAC will get you a lsb of 2^-12 of peak voltage.  The quantization noise will be +/-.5 lsb and will be uniformly distributed giving you an rms quantization noise of 35 nV for a 1V peak output (rms of a uniform distributed variable is 1/sqrt(12) of peak).

But have you thought about how you will produce the sine wave?  If you use direct digital synthesis you have the problem of the quantization noise of your sine table which has discrete values.  You will need a table storing samples larger than a byte and you will need a really big number of samples unless you interpolate between samples.  If you use an unstable filter to generate the sine wave, the phase might drift.

pjrc

#9
Nov 18, 2016, 01:39 pm Last Edit: Nov 18, 2016, 02:30 pm by Paul Stoffregen
PWM is horrible.  Even if well filtered, the signal level is still derived from your (presumably noisy) digital power supply.

A quality DAC will give you true analog voltage, hopefully derived from a stable low-noise reference voltage.  There's still a matter of quantization.  Real DACs also have non-ideal performance like differential non-linearity (the steps aren't all perfectly the same voltage difference) and integral non-linearity (their voltage response from 0 to max isn't perfectly ideal straight line).  But many excellent DACs exist on the market that get these errors very low, well below -90 dB.  The very best DACs achieve about -120 dB noise+distortion performance (which is roughly 1 uV error on a 1V scale).  Some microcontrollers have pretty decent 12 bit DACs built in, but at best you could expect errors about -60 to -70 dB.

All digital audio synthesis also can suffer from timing jitter.  Even if your DAC is perfect, if you output the samples at the wrong times, the result is imperfection added to the final result.  If your output is generated by interrupt-driven software, or even worse by simple polling code, interrupt latency can lead to quite a lot of jitter.  Generally you need to use a hardware-based approach to control the timing of the sample rate if you want really good quality results.  For the highest quality levels, you might also be concerned about the quality of your system clock.

There is a trick call dithering, commonly used with audio DACs, which improves resolution at lower frequencies.  As your low frequency waveform slowly transitions from one DAC step to the next, you rapidly output dither patters alternating between those steps.  With low-pass filtering, the result is higher resolution than you could have achieved.

DACs are also commonly used with oversampling techniques.  If you generate data much, much faster than necessary (and your DAC has the analog bandwidth), then you can greatly lessen the need for analog filtering to remove the ultrasonic content from the rapid steps between DAC voltage levels.

Of course analog filters add noise (thermal noise in resistors & opamps) and distortion (usually due to non-ideal characteristics in their capacitors).

On the synthesis of a high purity sine wave, you might wish to take a look at this code I wrote some time ago:

https://github.com/PaulStoffregen/Audio/blob/master/synth_sine.cpp#L75

It synthesizes a sine wave using Taylor series approximation.  The phase angle is a 32 bit unsigned integer and the output is 32 bit amplitude, where at least 25 bits match to an ideal sine wave.  I'm pretty sure this sine wave is better than can be reproduced by any DAC that exists with today's technology.

You can also find code in that file which generates pretty good sine waves from a modestly sized table of 16 bit data, using linear interpolation between the table entries.

rj77

Thanks very much to both
Paul, that's really helpful, much appreciated. The code looks great. Can you suggest any DACs in particular that would be suitable to use in conjunction?
Cheers
 

pjrc

That particular hires sine code was intended for testing the CS4272 DAC on William Hollender's Super Audio Board.

The CS4272 DAC is probably overkill for any application that isn't studio quality broadcasting or "audiophile budget".  While the DAC itself isn't terribly expensive, as you can see from William's circuit board, quite a lot of extravagant support circuitry is required to have any hope of actually achieving such incredible performance.

Simpler chips like SGTL5000 or WM8731 are normally used.

pjrc

It's probably also worth noting that Arduino Nano is too slow to compute that Taylor series approximation at 44.1 kHz or faster audio sample rates, while also sending the data to a DAC without the benefit of built-in I2S communication hardware.  To achieve this level of performance, you're going to need a more powerful board.

MarkT

CORDIC sine calculation can be optimized for generating a slow sinewave by saving state from the
previous lookup.

Alas most audio DACs have high-pass digital filters built in and are hard to drive (48kSPS with 2 24 bit
samples per sampletime).

I don't know of any true audio-quality DDS chips, they are mainly for RF modulation, but I think some
are 14 bit which is pretty good.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up