Thursday, February 6, 2014

What does my microcontroller's digital to analog converter output look like?

My microcontroller has couple of DACs (digital to analog converters). I decided to test what kind of tasks they're good for. For this I wrote a simple routine in C++ which outputs pure sine wave through the DAC. I updated the DAC in 60 KHz speed.

Lower frequency sine waves looked exactly as they should on my oscilloscope screen: beautiful sine waves. When I started to get closer to the 10 KHz frequency, the results looked more and more stair stepped. At 12.5 KHz the sine wave looked like this:


Each of those steps is exactly one sample long when the samplerate of the DAC is 60 KHz.

Obviously the results are less than desirable for regular audio signal generation, so I decided to test what would happen if I filtered the signal using a simple low-pass analog filter. I put two of these in series:


…and got this as my output:


(Note that I've zoomed out the oscilloscope's view so it shows about 4x more of the signal.)

Much better! But there is some obvious lower frequency swaying in the result. The sine wave moves noticeably up and down. It's like the aliasing/quantisation has added extra sine waves into the signal. It's time to switch the oscilloscope into the FFT view:


Yep. There are obvious large spikes up in the audio spectrum above the sine wave's frequency.

So it seems that the microcontroller's own DAC (with simple filtering) won't be enough for audio signal playback, but most certainly can be used for all kinds of control signals, such as envelopes, LFOs, and so on.

All in all, the microcontroller's DAC outputs will be highly useful for my groovebox's design.

No comments:

Post a Comment