cancel
Showing results for 
Search instead for 
Did you mean: 

Using DAC output for class D audio amplifier

Oleksandr Leskiv
Associate II

I'm wondering what would be an ideal circuit to connect a very simple 2-4W class D audio amplifier to a DAC output of an STM32 MCU.

My goal is to be able to play some WAV files using build-in DAC of STM32F051.

I found an amplifier TDA2822G-S08-R, took it's example bridge schematic (attaching it), connected INPUT 1 to DAC output, and a 4Ohm speaker to OUTPUT1/OUTPUT2.

In general - schematic works - I can hear my WAV files playing with reasonably good quality.

However, the amplifier is heating up like crazy instantly (I can't touch it anymore) - and also I'm hearing some high pitched noice, even when using batteries only.

That brings me to an edge, because there's too many unknown to me variables, like:

1) I know that amplifiers usually like to accept differential outputs (symetrically below & up the ground) - but it doesn't seem like I can achieve it with simple STM32 DAC (which goes above the ground only).

2) I'm not sure what voltage is usually supposed to be minimum/maximum for an audio amplifier. STM32 DAC outputs audio from 0 to 3.3V - maybe that is too much (and that's why amp heats up), but how can I fix it without sacrificing quality?

9 REPLIES 9
LCE
Principal

Watts create heat...

Check the amp's datasheet, it should show an input range, probably depending on its supply voltage, maybe something like "0.5V up to (VDD - 0.5V)"

Anyway, why go from digital to analog (STM DAC) then digital - analog again?

Is that a 12bit DAC on that STM32?

Instead you could use an I2S / SAI peripheral on the STM32 and connect a class D amp with I2S input.

Sound quality will probably much better (okay, with a crappy mini speaker 12 bit DAC is good enough...), and you don't have the analog path inbetween.

LCE
Principal

And check how you can rid of or dissipate the heat. On a PCB you need lots of copper, sometime a little heatsink is necessary.

Oleksandr Leskiv
Associate II

Here are some datasheets for TDA2822:

https://www.st.com/resource/en/datasheet/tda2822d.pdf

https://pdf1.alldatasheet.com/datasheet-pdf/view/454040/UTC/TDA2822G-S08-R.html

I can't find any charasteristics on the input voltage restrictions. Maybe you can help me find it?

Answering your question would I go with digital analog instead of I2S driven amplifier - mainly the cost.

Most of the amplifiers/drivers with digital input start at a too high cost & usually have too much unnecessary functions & power, and my goal is to drive, as you say, crappy speaker with under $10 PCB.

There's also plenty of cooper on my PCB, yet, I'm not sure that so-8 package is really suitable to disappate heat with it..

MasterT
Lead
  1. TDA2822G is Not a D-amplifier. Regular AB class.
  2. Input voltage range you could calculate based on Gain (39dB = ~x100), so input AC peak-to-peak expected at the input about 33 millivolts, maybe 50 mV if 5V power used. Put a resistive divider /100.
Oleksandr Leskiv
Associate II

@MasterT​ 

Ok, I did not know this relation between Gain & Input voltage. And I must have overlooked an amplifier class at some point.

Now that makes so much sense why this amplifier completely freaked out when I haven't multiplied each sample's value by ~3-10/100 (which is probably reduced 3.3V DAC output to nearly 30-50mv).

Thanks you a lot!!!

Can you please advice me on what charasteristics should I look then for a suitable amplifier though?

Dac it 3.3V, I can provide amplifier with either 3.3v or 5v.

And I want it to drive 4Ohm (maybe 8Ohm) speaker at 2W.

I would really appreciate some help on this :folded_hands::folded_hands::folded_hands:

MasterT
Lead

You can't multiply samples send to DAC, since you will lost 6-7 bits out of 12, and get not acceptable audio quality at the end. The options are resistive divider - DAC would output 3.3V peak-to-peak as close as possible, and resistors would attenuate down to appropriate magnitude. Digital potentiometer is another option, MCP4151 or like that.

Can't recommend on amplifier, it's greatly depends on market at your location on the planet.

Oleksandr Leskiv
Associate II

Thanks!

Yes, I understand that sample division is not a long-term solution.

I've also tried reducing the file volume itself and it worked out slightly better, but that still doesn't fix the issue completely.

In case anyone wonders around here & has the same questions as I did, here is really good video:

https://www.youtube.com/watch?v=H_zqFxb8hZY

Basically in order to figure out what voltage should you get from your DAC after resistor division, you should follow these steps:

1) Find in datasheet out what the wattage is of your amplifier for a specific load.

2) Using formula V = sqrt(P*R) get a sence of what is the maximum voltage output of you amplifier.

3) Find in datasheet what the "closed loop gain" is of your amplifier (in db).

4) Convert gain from step 3 to voltage gain, using formula 10^({gain}/20).

5) Divide output voltage from step 2 by the voltage gain - and here's your desired input voltage.

So for example, my amplifier gives 700mw for a 8ohm load, and it's gain is 39db.

1) 700mw, 8ohm

2) V = sqrt(0.7*8) = 2.36V

3) 39db.

4) voltage gain = 10^(39/20) = 89.

5) input voltage = 2.36/89 ~= 0.026V ~= 26mV

So if my DAC outputs 3.3V I should use a resistor divider of approximately 127.

@MasterT​ can you also advice if it's safe to assume that the resistance between "IN" and ground in this schematic is only determined by the R1 (10kOhm)? Or is there's any other significant resistance between IN & ground inside the IC itself? Is there's a way to figure that out?0693W00000QN7SRQA1.png

If the resistance between "IN" and ground IS 10kOhm, I suspect I can put a 1mOhm resistor between "IN" and DAC output, and that would lower the input voltage by a factor of around 100 and that would be sufficient solution for my case.

MasterT
Lead

Have you seen this line in datasheet:

Ri Input resistance f = 1 kHz 100 kΩ

You don't need to calculate divider precisely, since Gain is "typical" , that means +-20% or even worse is "normal" .

Oleksandr Leskiv
Associate II

Yes, I saw it, but I was not sure if that was it.

Nevertheless, 100kΩ in parallel with 10kΩ is still almost 10kΩ (~9.1) :)

Anyways, thank you so much for giving me a direction in this question, I could see what the problem was and how can I move forward into inverstigating this issue.

Cheers