Basic question: which board to use for audio DAC?

Hi! Total beginner here, apologies in advance:

We're needing a board to use as a (single channel) audio signal generator (and to interface with some buttons, a hall effect switch, and a rotary encoder).

I see that the Due and the Zero both have DACs. Would they be my best bet for such a project?

Are those DACs able to generate "line level" audio signals? I.e. audio that could be fed into the standard impedance of a "line level" audio input on an audio amplifier?

(If there are other Arduino boards I should be looking at, I'd appreciate the heads up. AFAIK some of the "pro" series have DACs, but we're looking to keep costs a little lower than that.)

Also, in terms of availability, is it pretty easy to get quantities on the order of 50-100 boards of the Zero or Due? I know the chip shortage is making things tough these days...

Thanks!

Could work, but I'd try high-speed PWM with low pass filter first. If you only want to generate signals in the human-audible range, I'd try that and use a "regular" arduino like a Mega328 or a blue/blackpill. Cheap as nails and almost certainly fast enough for what you're doing.

Even if the 1-bit DAC doesn't work for you, it's almost certainly far less expensive to use a Mega328 and an external DAC than a Due or Zero.

[edit] doing it with PWM depends on the audio range. I should have remembered this because I ran into this problem a few years ago and ended up having to use an external DAC. Mega328 did not have the clock rate to produce high enough resolution.

Audio is AC your DAC only produce DC.

Hi-fi, or Low-fi audio? Specs?

Hi @savel

The Due's 12-bit DACs aren't rail-to-rail, with a 3.3V reference you'll get a range between 0.55V and 2.75V.

The Zero's single 10-bit DAC is rail-to-rail and capable of up to 350,000 samples per second.

It might also be worth checking out SAMD51 boards, such as Adafruit's M4 Grand Central, Metro M4, Feather M4 and Itsy Bitsy M4. They're Arduino compatible and the microcontroller has two 12-bit, rail-to-rail DACs with a sample rate up to 1 million sample per second.

When using microcontroller DACs, it's best check the minimum resistive and maximum capacitive output loads in the datasheet, since they can be quite easily damaged.

Thanks all -- some more details: I'm consulting on a project that will scale to some degree so there are some strange constraints: I'm trying to find something that doesn't involve much assembly or soldering (which is why I have shied away from the PWM+filtering route, but I can do that if needed). Audio fidelity is not a big concern, no, but durability, ease/simplicity of assembly, and availability in the market are all important. It might be hard to convince them to use lesser-known boards + external DAC boards, etc., but I guess we'll do what we have to do.

Signal will be 0Hz to 10kHz, probably just a sine wave (but options would be good). As far as the output, I'm trying to get to "audio line level" though I profess ignorance on the electrical details of that; "suitable for driving the standard input impedance of a line level input jack on an audio amplifier".

@Paul_KD7HB -- are you saying that these DACs can't do 0-10kHz ? DC signals are what they are designed for only? Oh shoot, this seems to be saying that 170Hz is the max they can do [EDIT: oops, no, that 170 Hz limitation is just because of the time to read the analog pot].

So I thought "find a microcontroller with a bit of GPIO and a DAC" and that led me to the Zero and Due, but I see now that in this world "DAC" doesn't mean "usable for audio output" necessarily.

Maybe I should look at signal generator shields? Or suck it up and go the PWM route...

Hi @savel

Yes the DAC's output signals will manage 0 to 10kHz.

As @anon57585045 mentions, you'll need to consider what your requirements are, before deciding if a particular DAC will meet your needs.

Thanks @MartinL - I'll check out the M4's!

Re: output loads -- I'll try to do that homework (this is all a bit beyond my expertise)... but maybe it's safe to assume that an audio amplifier input would meet those requirements?

Probably not true... Note that your sample rate has to be at-least twice the signal rate (Nyquist sampling theory). You need at-least one sample for the top-half of the waveform and one for the bottom half, and that's assuming it's low-pass filtered to get a sine wave. So for 10kHz you'd have to write data at 20kHz or faster. You probably need at least 10X the signal frequency for more complex waveforms. The speed you can write depends on the processor speed and all of the things your program is doing (such as calculating the sine or using a sine look-up table.

I've never used either one of those but quickly checking the specs the Due has a dual 12-bit DAC (which would be good if you want stereo audio) the Zero has a single 10-bit DAC. The Due's clock is about twice that of the Zero and both are faster than a basic Arduino (Uno, etc.).

Line Level is not a problem. You can get 3V peak-to-peak which is about 1V RMS.

But since the chips can't put-out the negative-half of the AC audio signal you'll have to bias the output (add 1.65V). A capacitor on the output can block the DC making a normal AC audio signal. That's very common with audio circuits. (The capacitor along with the load resistance makes high-pass filter and since DC is zero Hz, it gets filtered out.)

1 Like

How are you going to generate the DAC values? What does the audio consist of? Also still waiting for an answer on specs...

Thanks! Yes I edited my previous post -- the 170 Hz limit was just due to them sampling the analog inputs, not the DAC.

On that issue; my device will need to sample a couple buttons, listen for changes from a rotary encoder, etc, but otherwise will just be spitting out the signal... are those things handled on an interrupt model, and thus won't interfere with my audio output?

Ah, hmmm, right... I get the point of the biasing but wouldn't I want to subtract 1.65V, not add? And biasing sounds like it might involve some extra circuitry, yeah?

And are you suggesting I add a cap just for the sake of blocking DC (as a precaution?) or is it going to do more than that? E.g. magically transform 0-3.3V into a proper audio signal somehow?

I appreciate all the guidance.

Yes, what is proper? Time to define it.

This is an excellent question that I should have asked right away. If you "just" need fixed tones output, there are Direct Digital Synthesis methods that can do this quite easily with just one digital pin. If you need to generate high resolution music on the fly, then you'll probably want an external DAC.

The main specs are frequency response and signal to noise ratio.

By the way, you can get an STM32H4xx "black pill" board with an on chip DAC for about USD$6.

Haven't gotten that far yet. I am totally new to arduino, but was assuming there was a sin() function somewhere...? The frequency will be driven by a knob (which I am probably-incorrectly referring to as a rotary encoder) that the code would check to switch between frequencies.

Likely just sine tones, possibly other simple waveforms.

0 Hz to 10kHz output is needed, and as far as more specs are concerned I don't even know how to properly characterize it besides "I am feeding a 'standard' line level input of an audio amplifier and want it to work". AFAIK they have input impedances on the order of >=10kOhm and expect peak voltages on the order of +/- 3.4V. There is some latitude here (e.g. I don't need to achieve max saturation of the input or anything, as long as reasonable SNR is maintained it could be a quieter signal.) Fidelity is not a big concern; this just needs to drive some simple signals. If there is some inaudible distortion or whatever it's not a big deal.

Really? You need sub audio?

The black pill board I mentioned could easily handle what you describe. All you would need, is a quantization filter (low pass) after the DAC output.

Real time sine waves are easy to do with a look up table.

I'm going with the concept that you want it to be cheap.

I forgot to ask, this is an important one as this application is somewhat unique... what is your level of programming and hardware experience and skill?

So the sigen is driving an amp which is driving an 8-Ohm vibration driver... realistically I probably don't need the subsonics, no. The signal will probably just be sine tones, but having the option for some other shapes would be nice.

So SNR is probably not a significant concern, and fidelity is not much of a concern, etc.

@anon57585045 thanks for considering the cost; as long as it's under like $100 we're probably OK. The bigger constraints are availability (now and in the future) and not having to do much assembly/soldering/circuit design. And making it easy on me in terms of programming would be nice, too. I started by looking for audio shields with 1/8" output jacks but they seem to all be built for playing files from SD cards and the like?

So the low pass filter after the DAC: by removing the DC offset does that change the 0-3.3V into +/- 1.65V?

Do you have a link for the STM32H4* ? I'm having trouble finding anything...

Is it necessary to use a look-up table for sine waves? You can't just do the equivalent of sin(t*f)? (This is my first foray into microcontrollers, so I have a strong "programmer" bias going on here...)

Sure you can generate functions on the fly. But floating point math is much slower on an MCU than it is on a PC which invariably has a hardware floating point coprocessor.

However, as an excitation driver, you don't need very fancy DAC hardware or filtering. The main issue would be achieving the 10kHz spec. It's possible you could use some DDS ideas as mentioned above, and simplify the hardware a lot.

So DDS is basically the same thing as PWM'ing a digital output pin through a filter? It's tempting in the simplicity for sure, except for the additional filtering components I'd need to consider.

I'm just having trouble reconciling the idea that the audio input of the amp expects positive and negative voltage excursion and I'm outputting positive voltages from the board, as @DVDdoug mentioned... isn't that something I need to sort out?

Hi @savel

Biasing the DAC output is done in software.

For example, if you're using a 12-bit DAC this gives you 2^12 = 4096, providing 0 to 4095 steps in output voltage from 0 to +3.3V, (assuming that this is the microcontroller's reference voltage). Half of 3.3V is 1.65V, therefore biasing just means adding 2048 (4096 / 2) to the equation generating the output waveform in your program. A 10-bit DAC on the other hand, would require a bias value of 512.

1 Like