0
\$\begingroup\$

I'm trying to connect a speaker to an STM32. The purpose is to create sound using the DAC. The speaker I'm talking about is 0.5 W and 8 Ω. Tell me if I'm right: based on this the current will be 0.15 A while the max. current through an I/O pin of the STM32 (sink/source) is 25 mA.

enter image description here

So, it would better to buffer it. Am I right? Main questions:

  1. What about a BJT buffer, e.g. something like this or this?
  2. Should I put in a resistor of around 13 Ω in series and a diode in parallel with the speaker?

Edit 1: As it's mentioned in the datasheet of STM32F103, there is a buffer for DAC but I'm not sure if it could tolerate the current consumption of my speaker.

enter image description here

\$\endgroup\$
15
  • 2
    \$\begingroup\$ Please mention the limitation of not using chips in the question then. Otherwise every answer will explain to just use an amplifier, either a single-chip amplifier or op-amp as part of a solution. Also, please specify if you can build a proper amp with BJTs and what power supply voltages there are present to build an amplifier and drive the speaker. Also what kind of DAC? Do you use STM32 DAC analog output? PWM output? Multiple pins with R2R DAC? A DAC chip? \$\endgroup\$
    – Justme
    Commented Mar 31 at 7:41
  • \$\begingroup\$ @Justme Finding such chips in my location is not that much easy and ordering from website such as digikey and aliexpress take too much time and money. I think finding these chips is possible over here: pam8302, xpt8871, HXJ8002, XY-SP5W. Could one of these be suitable for our job? It seems PAM8403 is also availble but it's stereo. Can we use it for our porpuse? I would prefer use 3.3v as supply. Yeah, I'm supposed to use STM32 DAC. \$\endgroup\$
    – Roh
    Commented Mar 31 at 12:03
  • 1
    \$\begingroup\$ any amp chip is simpler and better to get working than one-transistor amp. Multi-transistor amp is better and even more complex than single transistor amp. \$\endgroup\$
    – Justme
    Commented Mar 31 at 12:31
  • \$\begingroup\$ To get 0.5 watts into an 8 ohm speaker requires a signal (sinewave assumed) that is 5.66 volts p-p. This either requires a power rail of 6 volts or more or a bridge amplifier running from a supply of 3 volts or more. Do you want quality or a dirty sound? What frequency response do you want i.e. audio or something different? \$\endgroup\$
    – Andy aka
    Commented Mar 31 at 12:54
  • 1
    \$\begingroup\$ @Roh The PAM8302 looks like the perfect chip for the job. Certainly will work far better (and far more easily) than a single-transistor amplifier. More efficient, too, as a bonus (due to being class D). \$\endgroup\$
    – Hearth
    Commented Mar 31 at 18:07

3 Answers 3

2
\$\begingroup\$

This is the simplest BJT solution I can think of, that won't sound horrible:

schematic

simulate this circuit – Schematic created using CircuitLab

It won't sound great either, and it's not efficient at all, but you'll get a few tens of milliwatts of power into the speaker.

\$\endgroup\$
2
\$\begingroup\$

Asymmetrical BJT buffer will be difficult to keep in balance, and this kind of solution is maybe 40-years old. I would recommend a singe IC H-bridge Class-D amplifier like PAM8301 (or its new versions). Check Digi-Key for 1-ch mono amplifier with 0.5W-2W output into 8 Ohms and 5-V power supply, you will have about 300 options.

However, if you are really limited to use BJT, here is the minimal temperature-stable basic design (from a pretty good tutorial) enter image description here

For your application (+5V) and 8 Ohm speaker (4-Ohms will be better) you might find a complimentary transistor pair with ~600mA max current (like 2N4401/4403 pair, or BCP53/56), and this AB-class amp will do a decent job.

\$\endgroup\$
3
  • \$\begingroup\$ So again suggest to use an IC? \$\endgroup\$
    – Roh
    Commented Mar 31 at 6:35
  • \$\begingroup\$ AliExpress does sell similar stuff. But if you really limited to BJT, you need to use DC blocking capacitor when connecting the speaker to avoid DC bias, sound quality will be bad in any case. \$\endgroup\$ Commented Mar 31 at 6:58
  • \$\begingroup\$ I think finding these chips is possible over here: pam8302, xpt8871, HXJ8002, XY-SP5W. Could one of these be suitable for our job? It seems PAM8403 is also availble but it's stereo. Can we use it for our porpuse? \$\endgroup\$
    – Roh
    Commented Mar 31 at 12:04
0
\$\begingroup\$

The voltage produced by the STM32 is enough to drive a speaker but the current is not. You could use a class AB push pull BJT emitter follower or even a BJT diamond follower which will give low distortion. Otherwise there are lots of audio amplifier ICs so you should be able to find one that would work.

\$\endgroup\$
1
  • \$\begingroup\$ I don't want to use any IC. Prefer to use BJT. \$\endgroup\$
    – Roh
    Commented Mar 31 at 6:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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