# Driving a speaker directly through an audio DAC?

I have a project where I'll need to generate some sound waves. In case it matters, the microcontroller I'll be using is an STM32L476RG which have an internal DAC. The question I have is related with the output power/sound I'll get. I'm not sure if driving the speaker directly through the DAC will give me proper volume.

1) What is the main limiting factor of output power / high volume? Is it the speaker?

2) How do I know if the DAC is enough to drive the speaker or if I need an external amplifier? How does the math works on this?

3) I'll be using sampled PCM data contained in a WAV file. Is there any advantage/disadvantage of using a codec (I2S) instead of DAC(+power amplifier)?

-
Are you sure it has an on-chip DAC? I just opened the datasheet and couldn't find it listed as a peripheral. – Steve G Feb 5 at 21:40
@SteveG you are absolutely right, thanks for pointing that out. I'll be using STM32L476RG instead. – msr Feb 8 at 20:20

If you're going to be using just the STM to drive a speaker, the main limiting factor is the current handling capability of the pins of the microcontroller.

1. You didn't mention what power you want coming out of the speaker, but let's take a look at what the microcontroller can provide. Its working voltage range is 1.7 V to 3.6 V. According to absolute maximum ratings, the maximum current for any pin is 25 mA. So rough calculation is 3.6 V times 25 mA is 90 mW. This is the point where you can expect that your pin is going to burn out. Do note that to be able to reach this rating, you'd need a special high-impedance loudspeaker. This pretty much means that for any usable power level with a loudspeaker, you'd need an external amplifier. It might be OK for headphones though.

2. How does the math work? Well to put it simply, you have a speaker with its nominal impedance. You also have the voltage and current ratings for the amplifier or DAC. You would also need to take a look at the efficiency graphs in the datasheet to see how well would the amplifier work. In general, you're expected to use DAC only to provide a signal and then use an amplifier to drive the transducer. There are some DACs with integrated amplifiers though.

3. In general, DAC is a component inside of a codec. Usually, a codec will have for example needed circuitry for a microphone input, have controllable gain, have some filtering inside of it and so on. A DAC will just to the digital to analog conversion.

As noted in the comments, you'd need to check if your microcontroller actually has a DAC inside of it. I can't see it on the datasheet. Are you maybe using a development board with this micro on it? In that case, the board might have its own DAC connected to the micro.

-
DAC output pins usually have far less current source/sink capability than GPIO pins. I looked at a STM32L063x8 (it just happened to be the first ST part with a DAC that I came across). Even with its DAC output buffer turned on the lowest load it can drive is 5k Ohm. – Steve G Feb 5 at 22:10
@Steve G Yeah, that's right, but the issue here is that the f401re doesn't even have DAC pins to look up for. – AndrejaKo Feb 5 at 22:31
Thanks for pointing that, I'll be using a STM32L476RG instead, which actually has a DAC inside. – msr Feb 8 at 20:23

The DAC is a low voltage very low current device .If all you are after is room filling volume then a complimentry Emitter Follower would be simple easy and cheap.Distortion will be very low .If you want extremely low distortion then you could do a cascode follower .Whether you run class A AB or B depends on the relative importance for you of power drain Vs Distortion .If you need lots of power like many watts you will need voltage amplification as well as the aforementioned current amplification .This means a fully blown power Amp.

-