6
\$\begingroup\$

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)?

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

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.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Steve G Feb 5 '16 at 22:10
  • 1
    \$\begingroup\$ @Steve G Yeah, that's right, but the issue here is that the f401re doesn't even have DAC pins to look up for. \$\endgroup\$ – AndrejaKo Feb 5 '16 at 22:31
  • 1
    \$\begingroup\$ Thanks for pointing that, I'll be using a STM32L476RG instead, which actually has a DAC inside. \$\endgroup\$ – rasgo Feb 8 '16 at 20:23
  • 1
    \$\begingroup\$ @SteveG: They often do, but some devices like Cypress' older PSOC chips (I don't know about newer ones) have some analog outputs that can source/sink 100mA even though digital outputs are limited to +/-20mA. \$\endgroup\$ – supercat Aug 24 '17 at 15:21
0
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Sorry, but this answer is, well, trash. An audio DAC will have typically 1 V rms output, and this is not remotely enough to drive a complementary emitter follower. The output will be at low volume with enormous distortion levels. \$\endgroup\$ – WhatRoughBeast Jan 1 '19 at 16:29
-1
\$\begingroup\$

Most important point to not destroy the STM32's DAC pins is adding a flyback diode in parallel to the speaker. When it's missing the reverse voltage of the speaker's coil will be higher than the -0.3V the DAC-pins are allowed in the maximum ratings.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.