Maker Pro
Maker Pro

Op-amps and transistors for audio

MrD

Mar 11, 2014
9
Joined
Mar 11, 2014
Messages
9
Hi, I'd like some advice on a circuit I'm designing for audio output.

I'm making a simple game system from PIC chip. For the audio side, I'm going to be using four of the GPIOs as a basic four-channel mono sound generator. The PIC will have a whole bunch of accurate hardware timers in it so I figure that if I set up four channels with a timer and GPIO pin each, I can write a service routine for each timer that flips the given GPIO bit when the timer expires. This means I will get four channel square wave output for next to no computation cost.

Because these are GPIO, they're going to be 0V to whatever high voltage is (CMOS high so it's 2.6V ish according to the datasheet). These are supposed to be logic data CMOS pins so obviously I want to source or sink as little current as possible and so I definitely need to buffer them before sending it to a speaker.

I need to sum the output voltages and output the result to a speaker or mounted audio jack socket to get my sound out. I have a box of 4 ohm, 10 ohm loose loudspeakers that can go on the end, but I don't know what amplifier circuit to use. The objective is to do this as simply, safely, cheaply and awesomely as possible. Audio quality isn't going to be great no matter what so it's not a big priority; it'll sound like a Master System at best (and I've programmed MS sound before, it's not pleasant). My idea is to build a little one or two transistor buffer stage to the side (or whatever's reasonable) that means I can clip on the speaker and not worry about damaging the MCU. I'm running this from 3.3V on 3 x batteries.

This image is the circuit I have in mind.

2014_03_10_21_00_41_1024x768.png


On the left are the GPIO pins A through D, connected into a resistor summing junction. It's a big voltage divider. I can pick the values of R and Rg to scale the maximum result voltage at 'all pins HIGH at once' to whatever range I want between 0V and 2.6V max. (Output impedance is given by R/4 // Rg.) This part is pretty much settled. The selection of the output impedance and voltage scale are the parameters that need to be chosen, they'll need to be selected to fit along with the amplifier stage on the right.

On the right is an emitter follower (the most basic transistor buffer I think). For a circuit like this (or any other transistor amp stage) I need to calculate the R and C values to set the base bias voltage, voltage gain factor and power draw to whatever is 'appropriate' and it's done: high input impedance for the GPIOs but low output impedance and high power for the speaker... but I don't know what voltage gain I should be aiming for for these loudspeaker components, or what voltage scale to aim for. I've been reading the Art of Electronics and all that over and over, but I'm afraid it's all going over my head.

Alternatively, an op-amp could be used on the right, set to straight-forward buffering to reproduce the signal exactly (with a decoupling capacitor in series to the speakers to prevent them getting DC?). This might be the way to go, but I would still need to know whether the output is suitable for driving a loudspeaker. I might need to combine an op-amp in buffer mode with a transistor to provide the appropriate drive. (Similar to this, op-amp output into the transistor base, inverting input op-amp feedback from transistor result. http://i.stack.imgur.com/KetKx.png)

Please let me know if I'm onto the right track, and recommend any circuits and components you think will help.

Many thanks.
 
Last edited:

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
You need to remove the output cap and the top base resistors. Other wise with the low output impedance of the speaker you with only get the rising edge of the input signal and a fair amount of ringing. Capacitors block d.c so you will only get the portion of signal as it goes from 0V to the VH output. Make the bottom base resistor large so you have a large RC time constant of the high pass filter created on the input.

Now here is the bit I don't understand. Summing means adding together and this would normally be done with analogue levels and not digital outputs. Are you on about toggling say A with a square wave and the reducing this level by switching in the different resistors? This is just voltage division.


Adam
 

MrD

Mar 11, 2014
9
Joined
Mar 11, 2014
Messages
9
Yes the left part is a voltage divider. I'm treating the four inputs as if they were four square wave analogue inputs, and if I was going to put this into the non-inverting input of an op-amp instead of an emitter follower, it would be called a summing junction. They're equivalent terms as far as I know.

The question is, is an emitter follower the correct thing to use at all?

The input cap is so that the output of my square wave stuff appears like a small AC voltage centred around ground. The biasing stuff is so that this AC coupled signal is always pushed into the transistor's active range.

The RC high-pass filter created on the input uses the C of the input capacitor and the R impedance looking into the next section: the top bias resistor, the bottom bias resistor and the transistor base all in parallel. I should bias the voltage at the base to 1/2 Vsupply so I get maximum swing range of the input voltage within the transistor's active range. So given that (Rtop // Rbottom) << (Beta*Remitter) so that the biasing divider is stiff enough, and Vbase = Vsupply * (Rbottom / (Rtop + Rbottom)), all of those values are more or less fixed based on the (expected) Beta of the transistor, the quiescent current and the supply voltage.

It would be easier to pick the input capacitor's value so that the -3dB falloff point is lower than the audible range (say 20Hz). Cin = 1/(2 * pi * 20Hz * (Rtop // Rbottom))).

Why do I need to remove the output cap? I'm afraid I don't understand that part.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
12,882
Joined
Nov 17, 2011
Messages
12,882
You need to remove the output cap and the top base resistors
Allow me to disagree: Without the caps the speaker will see a DC component which is not good for the speaker. The base voltaeg divider is required to set tthe operating point of the amplifier. This is a typical common collector amplifier (also calle demittter follower amplifier).

summing digital signals like this will work, only the result is an anlog signal, see simulation:
attachment.php
 

Attachments

  • adder.png
    adder.png
    64.1 KB · Views: 341
Last edited:

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Hi Harald
I am pretty sure the 4R loud speaker load on the output will discharge the output capacitor very quickly and remove the d.c he wants on the output. Then you would need to remove the top resistor otherwise the transistor will be on all the time. If this is not feasible then I am pretty sure the circuit will not work very well with an output capacitor. Oh you need to keep the input cap as I mentioned. I'll simulate it tonight to show what I mean and then you can let me know if I am missing something.
Cheers
Adam

Thanks
Adam
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Here is what I think could happen to the input signal. I have just taken some rough values to show you. The three scope traces are at 500Hz, 1k and 2K. The input was a 5V square wave
Thanks
Adam
 

Attachments

  • square_amp.PNG
    square_amp.PNG
    6.1 KB · Views: 131
  • 500Hz.PNG
    500Hz.PNG
    5.3 KB · Views: 117
  • 1K.PNG
    1K.PNG
    6.2 KB · Views: 129
  • 2K.PNG
    2K.PNG
    6.7 KB · Views: 142

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Allow me to disagree: Without the caps the speaker will see a DC component which is not good for the speaker. The base voltaeg divider is required to set tthe operating point of the amplifier. This is a typical common collector amplifier (also calle demittter follower amplifier).

summing digital signals like this will work, only the result is an anlog signal, see simulation:
attachment.php

Hi Harald
Done the same simulation and have attached the output. What is it doing? Is it adding the pulse widths? How could you use this signal? what did you mean by analogue signal.
Thanks
Adam
 

Attachments

  • Capture10.PNG
    Capture10.PNG
    10.2 KB · Views: 121

Harald Kapp

Moderator
Moderator
Nov 17, 2011
12,882
Joined
Nov 17, 2011
Messages
12,882
I understand that the op wants to generate different frequencies on different pins of the controller.He then wants to sum the signals to generate a mono signal that contains the mix of frequencies and send it to a speaker.

By adding the signals in the way shown, the resulting (red) signal is no longer digital, since it contains intermediate voltages (between logic low and high). When more sources are used (the op sketched 4), you will get even more intermediate voltages. That is in effect an analog signal with discrete voltage steps, but nevertheless analog.

Here's what the capacitor does:
attachment.php

After the circuit has settlef, you clearly see that the output of the dicider (red) has a DC component. It never goes below 0V. The output of the capacitor (light blue) is centered around 0V. It has no Dc component.
This is what the cpacitor at the input of the transistor amplifier would do. This signal is then amplified and sent to the speaker. Since the transistor amplifier itslef generates a DC component on the signal due to its operating point, you nedd a capacitor at the output, too.

When you Google "transistor amplifier circuit", you'll find that coupling capacitors used this way are common.

In your simulation you use an inductor as load. Does it include the ohmic resistance? It should, otherwise it's nnot realistic.
 

Attachments

  • adder_2.png
    adder_2.png
    67 KB · Views: 273

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
Hello MrD and welcome to Electronics Point :)

You're on the right track. But if you use an emitter follower to drive a speaker, you have to make the emitter resistor a fairly low value, to get a low output impedance. Since the emitter should be biased at around 1.3V (for a 3.3V supply voltage), that resistor will waste significant current, which I guess you don't want in a battery powered circuit.

Other discrete approaches will limit the output voltage swing so I suggest a small audio power amplifier IC. These are available with complementary outputs to drive a speaker in "bridge-tied load" configuration, which gives up to four times the output power (for a given power supply voltage and load resistance) compared to a single-ended output.

Digikey (http://www.digikey.com) have a good selection guide - go to their Product Index, Integrated Circuits (ICs), then Linear - Amplifiers - Audio, and use the filter to select the output type, power supply voltage range, etc that you're interested in.

All of the suitable devices are in surface mount packages - they're designed for use in mobile phones and similar portable items, after all - and many of these are in BGA and no-lead packages, which can't really be hand-soldered. Use the package columns to remove any package name ending in N or with BGA in it.

Here are a few that may be suitable:

Texas Instruments LM4990: http://www.digikey.com/product-detail/en/LM4990MM/NOPB/LM4990MM/NOPBCT-ND USD 1.85
Delivers 2W into 4 ohms (at 5V supply); quiescent current 3 mA typical, 7 mA maximum. At 3.3V it can only deliver about 0.75W into 4 ohms. If you're regulating your battery supply down to 3.3V, you could power it directly from the batteries and get a bit more power out of it.

ISSI IS31AP4991: http://www.digikey.com/product-detail/en/IS31AP4991-GRLS2-TR/706-1164-1-ND USD 0.27
At 3.3V supply voltage, can deliver about 0.5W into an 8 ohm load. Is not specified to drive a 4 ohm load.

ON Semiconductor NCS2211: http://www.digikey.com/product-detail/en/NCS2211DR2G/NCS2211DR2GOSCT-ND USD 0.82
Can deliver 1.5W into a 4 ohm speaker at 5V supply. Output power at lower supply voltages is not given in the data sheet.

Texas Instruments TPA6211A: http://www.digikey.com/product-detail/en/TPA6211A1DGNR/296-26889-1-ND USD 1.06
Can deliver about 0.9W into 4 ohms at 3.3V supply.

All of these amplifiers can be driven from your combined four channel audio signal. You'll need to attenuate it quite a lot, with a series resistor and a volume control potentiometer.
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Thanks Harald.
Yes I did use 4R as the speaker resistance. I must be doing something wrong then. If you have five minutes can you simulate it as he has it and use a 4R loud speaker, including inductance as your load and see what you come up with. Strange thing is it works ok with a sine wave?.
Adam
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
12,882
Joined
Nov 17, 2011
Messages
12,882
Adam,
I don't have the simulation files at hand - will have to wait till next week.


Btw: Kris has a valid argument about the suitability of such an amplifier for driving a speaker.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
12,882
Joined
Nov 17, 2011
Messages
12,882
Adam:

What the heck. I just build the simulation from scratch. You're not doing anything wrong. The inductor causes some ringig. Replace the inductor by a "pure" resistor. Make it 1k and set simulation time to 1000ms. You will see, that the output voltage will average near 0V with an RMS of ~2V after abut 600ms. This is when the capacitors are charged to the full DC component.

attachment.php


Have a nice weekend - I'l be off for now

Haarld
 

Attachments

  • bla.png
    bla.png
    74.4 KB · Views: 263

MrD

Mar 11, 2014
9
Joined
Mar 11, 2014
Messages
9
Thank you KrisBlueNZ, and everyone else. Much obliged.

I've had a look at some of these single-chip power-driving amps, and they seem perfect for the job. There are some which have a single input (rather than op-amp style inverting/non-inverting), like the TBA820M. Is it okay link the output of my produced audio signal (attenuated appropriately) through a capacitor to the input of a single input amp chip like that?
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
I've had a look at some of these single-chip power-driving amps, and they seem perfect for the job.
Great!
There are some which have a single input (rather than op-amp style inverting/non-inverting), like the TBA820M. Is it okay link the output of my produced audio signal (attenuated appropriately) through a capacitor to the input of a single input amp chip like that?
Yes. The ones with a single input are the simplest to use because you don't need any feedback or biasing components. You may need a DC blocking capacitor between the wiper of your volume potentiometer and the input pin. BTW, use a logarithmic potentiometer for the volume control, not linear.
 

MrD

Mar 11, 2014
9
Joined
Mar 11, 2014
Messages
9
I've built my audio board with the TBA820M now, using the schematic from everyday practical electronics. Thanks for your help. The logarithmic pot was a good idea, though it appears that the way I've wired it I get the correct volume increase when I turn the knob anticlockwise.

Am I correct in saying a log pot has curves like this?
pots.png


Using the pot as a potential divider, the out voltage is proportional to the resistance between M and with the L or R terminals depending on how you wire it.

The curve I want is the resistance L to M on the bottom graph: increasing quickly at the start then flattening at the end over a clockwise turn.

Because I used an ordinary log pot, I'm currently using the resistance M to R on the log graph so I get the same curve shape but flipped horizontally.

Would I have had to get a 'reverse log' pot to make it so that a clockwise turn increased the volume? I clearly can't swap the three terminals of the log pot because the end result would be totally wrong, if I'm visualising it correctly.

It's hardly a big deal, I'd just like a little confirmation that my assumptions make sense. :)

It seems to me that the reverse log curve is more useful than the regular log curve for a volume knob type uses. I've read online there are ways to make psuedo-log pots in any configuration by using a linear pot and putting a resistor in parallel (so it the output voltage would actually resemble the graph of a reciprocal curve), is that what's usually done?
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
The TBA820M is a fairly old device. Its output power at 3.5V into 4 ohms is typically 0.25W. One of the ones I suggested would be a lot louder. The TI TPA6211A produces typically 0.9W into 4 ohms at 3.3V.

Re your graphs for log and reverse log potentiometers, you're probably right; it's hard to be sure because left and right terminals aren't clearly defined. I can tell you that at the anticlockwise end of rotation, the resistive track in a log pot has a relatively small amount of resistance distributed over a relatively long rotational angle, and at the clockwise end, it has a relatively large amount of resistance distributed over a relatively short rotational distance. This means that if you have a log pot with the anticlockwise end connected to your 0V rail and a certain voltage applied to the clockwise end, the voltage you see on the wiper (middle) terminal, as you rotate it steadily from fully anticlockwise to fully clockwise will follow the trace that you have marked as "Resistance LM" on your first graph. It increases slowly at the minimum volume end, and quickly at the maximum volume end. This is correct for an audio volume control, where the anticlockwise end is minimum (silent) and the clockwise end is full volume. That's why logarithmic taper is also called "audio" taper and is used for volume controls.
 

MrD

Mar 11, 2014
9
Joined
Mar 11, 2014
Messages
9
I see. I'm afraid I'm not familiar enough with the terminology on the data sheets to be able to tell good from bad at a glance. :) It being an old chip might be an advantage as there's more information and stable example in-use circuits to read about. I was also constrained by availability (it's not to easy to find a low-quantity hobbyist supplier in the UK with a large range, I'd link that one I used but I don't know this forum's policy on that), so I picked what looked most appropriate. For my first veroboard construction, I'm very happy with the result!

This is correct for an audio volume control, where the anticlockwise end is minimum (silent) and the clockwise end is full volume.
Thank you, that was what I wanted to know! I thought it should have been the opposite to that. I've wired the pot up to an IDC-like connector anyway so I can flip it around and see how it sounds the other way in the event.
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
Would you like me to look for a better device on the Farnell site? I doubt they'll have anything better in through-hole; can you deal with an 8-pin SMT device?

It's fine to post links to component suppliers, eBay auctions, etc, as long as it's not for your own personal gain.
 

MrD

Mar 11, 2014
9
Joined
Mar 11, 2014
Messages
9
No thanks, it's okay. I've already built the gizmo and there's no way I'd be able to solder SMT with the tools and experience I have anyway, so there's no need to go rummaging through a thousand spec sheets just for me. :)
 
Top