## Setting gain... figuring out the numbers? Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Setting gain... figuring out the numbers?

I'm working on a smaller version of the WaveShield that would piggyback on an Arduino Nano in a similar manner to a full shield.

I'm doing OK on it (I Think.. LOL) but I have been having trouble figuring out the right value components to set the gain where it should be on the audio section.

The components involved:
MCP4921E/SN (Essentially the same as the DAC used on the full size WS but in SMD size.)

TPA0211DGN (2W BTL Amp.. should be a nice volume boost over the WS's .3W output.)
http://focus.ti.com/general/docs/lit/ge ... leType=pdf

Headphone jack (Not that involved in the gain setting but it's being used to switch between BTL and SE output modes.)
A potentiometer, eventually once I get the base gain set.

OK... on to the gain questions....

The DAC lists "Output swing" as "0.010 to VDD – 0.040" so running at 5V for VDD means a total swing of 4.5v?

The BTL Amp datasheet states "Plugging 2 × VO(PP) into the power equation, where voltage is squared, yields 4× the output power from the same supply rail and load impedance."
But I can't find anything saying exactly what VO(PP) actually IS. They show the equation but never the result as a numerical value so I can't even back track the math. Is it safe to assume that VO(PP) is simply 2x the VDD? In this case that would be 10V?

If the voltage swing of the amp maxes out at 10V PP, and I have 4.5V PP coming in I want a gain of 2.22 V/V for "Max output" right? (And then a voltage divider using a POT to attenuate it from there.)

Last question... would it be better to "overdrive" the gain just a tad.... say 2.5 V/V so that while all the way up would be somewhat distorted you could "trim" the volume pot back down to be sure you were getting the max available, or should I just follow the numbers?

Thanks in advance for any help, it is appreciated!

Troy
TroyO

Posts: 26
Joined: Fri Nov 20, 2009 2:18 pm

Re: Setting gain... figuring out the numbers?

TroyO wrote:The DAC lists "Output swing" as "0.010 to VDD – 0.040" so running at 5V for VDD means a total swing of 4.5v?
4.95V Watch the decimal...

TroyO wrote:The BTL Amp datasheet states "Plugging 2 × VO(PP) into the power equation, where voltage is squared, yields 4× the output power from the same supply rail and load impedance." But I can't find anything saying exactly what VO(PP) actually IS.
"voltage out, peak to peak"

TroyO wrote:If the voltage swing of the amp maxes out at 10V PP, and I have 4.5V PP coming in I want a gain of 2.22 V/V for "Max output" right? (And then a voltage divider using a POT to attenuate it from there.)
Or you could attenuate the input

TroyO wrote:Last question... would it be better to "overdrive" the gain just a tad.... say 2.5 V/V so that while all the way up would be somewhat distorted you could "trim" the volume pot back down to be sure you were getting the max available, or should I just follow the numbers?
It's a free country

zener

Posts: 4558
Joined: Sat Feb 21, 2009 2:38 am

Re: Setting gain... figuring out the numbers?

4.95V Watch the decimal...

`Doh! Thanks!

"voltage out, peak to peak"

Maybe I need to phrase it better... I can't find in the datasheet a "Swing value" or what the max peak to peak output voltage of the device is. Hmmm, with a 4 Ohm load, and a 2 Watt rated output I'd think 8V was the max output voltage swing... but I can't seem to find in the datasheet where I can validate my assumption. I was hoping someone could point me to where in the datasheet it's listed, and/or confirm that it really just doesn't tell you that info.

Or you could attenuate the input

Opps... actually that's what I meant to do, I will also be adding in the low pass filter as used in the WaveShield schematic.

It's a free country

True enough.... there's a lot of "Rule of thumb" things with electronics, I was just wondering if the common practice is to leave some trim room on audio circuits or go exactly by the numbers?

I think I'm on the right track with the 8V(PP) as a max, and with the corrected VOUT of 4.95V I would be looking for a gain of ~1.61 so I would have been way off. To cover the slight extra gain boost I think I'll go with 1.75 V/V as my max gain set point.

Do you think i am on the right track?

Thanks for the help!
TroyO

Posts: 26
Joined: Fri Nov 20, 2009 2:18 pm

Re: Setting gain... figuring out the numbers?

The gain of an amp depends on its load, so I guess that means the output swing depends on the load also. That is probably why they provide you with the formulas but no particular value.

As for your last question, I don't know what standard practice is. Your approach sounds reasonable. Sometimes an amp maker doesn't know what preamp will be connected to it. Or what load either. You may want to consider some output protection depending on your application.

zener

Posts: 4558
Joined: Sat Feb 21, 2009 2:38 am

Re: Setting gain... figuring out the numbers?

Zener wrote:The gain of an amp depends on its load

Do you mean open-loop gain? Yes. If you are not worried about DC precision applications, which this is not, then it can be ignored especially in closed loop operation.

TroyO wrote:Maybe I need to phrase it better... I can't find in the datasheet a "Swing value" or what the max peak to peak output voltage of the device is. Hmmm, with a 4 Ohm load, and a 2 Watt rated output I'd think 8V was the max output voltage swing... but I can't seem to find in the datasheet where I can validate my assumption. I was hoping someone could point me to where in the datasheet it's listed, and/or confirm that it really just doesn't tell you that info.

Audio power amplifier datasheets do not often state the headroom requirement; rather, they will state a given output power on a particular Vcc and load. You are correct in your assumption from pg. 4 of the datasheet, but be careful of your units. A output voltage of 8Vpp is required to produce 2W into 4Ω. It is 8Vpp on a 5V supply because the output is an H-bridge (BTL).

Personally I use peak voltages - it is easier for me to do the math. (Vp^2)/(2*Rload)

Opps... actually that's what I meant to do, I will also be adding in the low pass filter as used in the WaveShield schematic.

If you are going to change the input resistor to a pot then that will provide you with an inexpensive way to change the gain. Just take into account the critical frequency of the input high pass filter. If you change the input resistance then you change the -3dB point . Also keep in mind the dynamic load it presents on the DAC - probably not a big deal.

True enough.... there's a lot of "Rule of thumb" things with electronics, I was just wondering if the common practice is to leave some trim room on audio circuits or go exactly by the numbers?

In consumer electronics, no. It is often a fixed gain, or an amplifier with an AGC or programmable pins. For your case it's A-Ok.

ImaginaryAxis

Posts: 267
Joined: Sat Nov 13, 2010 3:16 pm
Location: Phoenix, AZ

Re: Setting gain... figuring out the numbers?

I was planning to steal the low pass filter and POT arrangement from the regular waveshield and just interface the output for the amp I chose, picking the RIn and Cin values to high pass at ~80 Hz. I figure a low pass and a high pass will make a "bandpass" filter that should keep out as much noise as possible. (I Think)

It also should increase the perceptive volume... more power in the range that a small speaker can actually make.

Below I circled the part of the WS schematic I am looking at...

audiovolume.jpg (13.52 KiB) Viewed 3384 times
TroyO

Posts: 26
Joined: Fri Nov 20, 2009 2:18 pm

Re: Setting gain... figuring out the numbers?

Ok, I had to go pull the full schematic.

I assume most audio amplifiers are AC coupled. The usually are in consumer and portable applications. A few comments/observations for the Waveshield:

1) DACA, I assume, is biased to VDD/2 or +2.5V and is DC coupled to the non-inverting inputs of the TL072 amplifiers. There is a attenuated low pass filter: voltage divider from R7 and the POT plus the low pass filter from C8 here. The "issue", for the lack of a better term, is by changing the wiper position on the pot, the DC bias of the TL072 changes. They should always be biased to VDD/2 for maximum dynamic range.

2)The filter's critical frequency is not 11kHz - at least not when the POT is taken into consideration. The pole, or -3dB point, will change when the wiper position changes. It is also not a good idea to design a filter the the Nyquist rate at fs/2. If fs = 22kHz you do not design a filter with a critical frequency of 11kHz because your dynamic range will suck. Again, that is really for precision so I guess it is ok here.

3) The TL072 really should not be in parallel. This is an oft-used trick to boost the current capability of an amplifier. I can understand why since it is a quad package being used, but some considerations should be taken into account. When driving op-amps in parallel the output referred voltage offset will not be equal and one amplifier will drive more current into the other. Which one takes the heat depends on the polarity of the offset. It is like driving batteries or two voltage sources in parallel - they get hot! Generally, the configuration is master-slave with load sharing resistors in series with the output to help share the current equally. Slew rate matching and phase margin are important especially with reactive loads and is difficult to do. Replacing this with an audio power amplifier, like the TPA0211, eliminates this problem.

I am being anal retentive, and the Waveshield design gets the job done so end of story. Either that it is late and I didn't read the schematic right. Food for thought really.

For your design with the TPA0211 be sure to use an input coupling capacitor. The advantage of BTL operation is to eliminate the need for an output coupling capacitor to the load. If you DC couple the inputs you need to ensure the DC bias is the same as the TPA0211. If not then you run the risk of operating out of linear range of the amplifier.

ImaginaryAxis

Posts: 267
Joined: Sat Nov 13, 2010 3:16 pm
Location: Phoenix, AZ

Re: Setting gain... figuring out the numbers?

I thing I get most of that... LOL, although maybe not all.

1) Since I will be going through a cap does it really matter if the bias if off a little as the wiper position changes? Hmm, I guess you still lose some hearoom that way.... I'll do more research on attenuation/gain control circuits. Key here will also be component count and physical size. I'm trying to make is as small as is feasible in a hand soldered format.

2) What freq would you use... 22k? As long as that's not letting in circuit noise it wouldn't hurt for my purposes. Or would 16k be a better mid-range compromise?

3) Moot since I will be using an amp... but interesting. I've also seen people piggyback chips to increase current. I also file that under "Dirty tricks that work but aren't the "right" thing to do."

Thanks for the input.... something I'm finding out about electronics is there are a lot of compromises and no matter how long you look at a circuit there's always several other angles to consider... LOL.
TroyO

Posts: 26
Joined: Fri Nov 20, 2009 2:18 pm

Re: Setting gain... figuring out the numbers?

The critical frequency with the pot is actually close to 11kHz, so not too much of a worry.

If you can oversample with the DAC, I would do that and increase the critical frequency of the low pass filter to say 22kHz. The audio range is 20Hz to 20kHz, arguably the range you would be interested in is 1kHz to 5kHz as this is the range that human hearing is most sensitive to changes in volume. It depends on your end application. The trade off is speech vs. (decent) audio reproduction. If you are not looking for snooty audiophile performance, leave it the way it is.

ImaginaryAxis

Posts: 267
Joined: Sat Nov 13, 2010 3:16 pm
Location: Phoenix, AZ

Re: Setting gain... figuring out the numbers?

No snooty audiophiles here... hell, I spent way to many years playing bass in a rock band for it to do me any good anyway, LOL.

I foresee the likely applications to be for Halloween props, or maybe museum "Talking heads" or maybe a screaming football or something. Marginally decent audio will be fine, I think.

Haha, I had written up a whole thing about the values I picked and why I picked them when I realized.... 8V into 4 Ohms *isn't* 2 watts, its 2 *amps*... or 16 Watts! 'Doh! Back to the ummm... figuring board. I now have a handle (I Think) on most of the calcs so it should be pretty quick.
TroyO

Posts: 26
Joined: Fri Nov 20, 2009 2:18 pm

Re: Setting gain... figuring out the numbers?

I found a great resource for the info I need.. it has a step by step explanation and examples to work from.

Linked here for future reference, useful info for many I would think!

http://www.ti.com/litv/pdf/sloa105a
TroyO

Posts: 26
Joined: Fri Nov 20, 2009 2:18 pm

Re: Setting gain... figuring out the numbers?

It is a good app note for those who do not want to derive the gain by circuit analysis.

The only thing they neglect is that for fully differential amplifiers if one of the inputs is not required - say for single-ended DACs, the other input still needs to be AC coupled to ground. Simply grounding the resistor will unbalanced the common-mode feedback circuit -- which is internal and not shown.

No problem with the TPA0211 though it is an SE to BTL amplifier.

ImaginaryAxis

Posts: 267
Joined: Sat Nov 13, 2010 3:16 pm
Location: Phoenix, AZ

Re: Setting gain... figuring out the numbers?

OK, I am following a lot better... the step by step helps.

Haha... what I *don't* get is why opening the scientific view in Windows calc gets rid of the Sqrt button. Ohh well, designed by a company that thinks it makes sense to hit "Start" to shut down.

Here's what I've calculated so far... I think it's right, LOL.

1.75V RMS from 4.95V(PP) DAC Output

2.83Vrms Out for 4 Ohms @ 2W (1.62 V/V Gain) (Interesting... it's mighty close to what I came up with before by doing it the "wrong way")

3.16Vrms Out for 8 Ohms @ 1.25W (1.81 V/V Gain)

I was hoping that 8 Ohm/4 Ohm woul work out about the same, but not quite. I think I will split the difference at 1.72 V/V Gain. It will be slightly hot at 4 Ohms, and a little under max at 8 Ohms. Should be OK for either and they are both common random speaker values. So, closest resistor is 72.5k... if I have it right. (1.724 V/V)

Just about what I had figured out the wrong way before, LOL. Ohh well... I learned a lot.

BTW, SE inputs on fully diff amps are covered in the datasheets... or at least it was on the TPA6211 which was my first candidate.

Ohh, another question.... the datasheet lists the resistor equation for gain calculation as:
AV = –125 k / RI

I have been ignoring the negative resistor value.... since I can't seem to locate a -72.5k resistor. (Wouln't that be a battery, I guess? ;-) Am I missing something there?
TroyO

Posts: 26
Joined: Fri Nov 20, 2009 2:18 pm

Re: Setting gain... figuring out the numbers?

TroyO wrote:OK, I am following a lot better... the step by step helps.
1.75V RMS from 4.95V(PP) DAC Output
2.83Vrms Out for 4 Ohms @ 2W (1.62 V/V Gain) (Interesting... it's mighty close to what I came up with before by doing it the "wrong way")
3.16Vrms Out for 8 Ohms @ 1.25W (1.81 V/V Gain)

What is the DC supply voltage of the DAC and TPA0211? 5V? I foresee a problem if this is true.

Ohh, another question.... the datasheet lists the resistor equation for gain calculation as:
AV = –125 k / RI
I have been ignoring the negative resistor value.... since I can't seem to locate a -72.5k resistor. (Wouln't that be a battery, I guess? ;-) Am I missing something there?

The internal architecture of the TPA0211 is an inverting amplifier - from an AC perspective. The negative value simply means the output will be 180° out of phase with the input.

ImaginaryAxis

Posts: 267
Joined: Sat Nov 13, 2010 3:16 pm
Location: Phoenix, AZ

Re: Setting gain... figuring out the numbers?

Yes, both devices run on 5V, although the DAC could be run on 3V. Or the ouput referenced to 3V, or really to any value from GND to VDD.

What problem is lurking in the weeds for me?
TroyO

Posts: 26
Joined: Fri Nov 20, 2009 2:18 pm

Please be positive and constructive with your questions and comments.