Component choice for class AB amplifier.

Thread Starter

glyndavidson

Joined Jul 26, 2020
12
Hi All. This is my first post so be gentle with me :D

I'm building a PCB using an Atmega1284 (essentially it's an Arduino) and have need of an audio amplifier.
Previously, I was using a very simple amplifier arrangement using a single transistor and an 8ohm speaker.
Schematic below:
wb7Ev (1).png

However, using a single 150mah lipo battery, the battery would only last on average for 40 minutes.
If I remove the amplifier and speaker from the circuit, then the battery lasts for 8.5 hours on average.
Clearly, my current amplifier setup is extremely inefficient so I'm looking for a better circuit.

I found that if I replace the speaker with an electromagnetic buzzer (and include a flywheel diode - schematic below), then I get 1 hour 40 minutes out of the battery (more than double the battery life with a speaker).
Annotation 2020-07-26 171935.png
Using an LM386 instead of the transistor, I get nearly 4 hours of the battery. So battery life is fantastic, but there is very little amplification and it requires many external components which is a big concern given the extremely limited space on my PCB.

I've also tried an Adafruit PAM8302 breakout. This gives the loudest sound from the buzzer but battery life is poor at just under an hour.
Using a TPA2005D1DGN I get slightly over an hour. I was very surprised by both of these given that they are class D amplifiers.

So as it is, the best solution I have is a single transistor and flywheel diode across the buzzer.

So this brings me to my question. I've been reading about class A, B and AB amplifiers and from what I've understood it should be fairly easy and without too many components to modify my original circuit and make it a class AB amplifier. However, what I haven't been able to understand is how to calculate resistor and capacitor values for the class A or class AB amplifier and wondered if somebody could help me here?

If a kind person could do the calculations for me and explain how they did it then that would be amazing! Some values which might help here:
  • I'm using a single Lipo battery so typical output is 3.7v.
  • The Atmega1284 is using a single pin to generate the audio signal (a square wave). Max RMS current draw on the pin is 20ma, absolute max is 40ma.
  • I haven't yet decided which buzzer I'm going to use, but typical resistance seems about 25ohms. If I can make the amplifier more efficient then I may go back to my original speaker.
  • The transistor I'm currently using is a MMBT2222A but I can change this if required. This is an NPN and I haven't looked for a matched PNP.

Thanks in advance,

Glyn
 

Papabravo

Joined Feb 24, 2006
14,253
Hi All. This is my first post so be gentle with me :D

I'm building a PCB using an Atmega1284 (essentially it's an Arduino) and have need of an audio amplifier.
Previously, I was using a very simple amplifier arrangement using a single transistor and an 8ohm speaker.
Schematic below:
View attachment 213187

However, using a single 150mah lipo battery, the battery would only last on average for 40 minutes.
If I remove the amplifier and speaker from the circuit, then the battery lasts for 8.5 hours on average.
Clearly, my current amplifier setup is extremely inefficient so I'm looking for a better circuit.

I found that if I replace the speaker with an electromagnetic buzzer (and include a flywheel diode - schematic below), then I get 1 hour 40 minutes out of the battery (more than double the battery life with a speaker).
View attachment 213190
Using an LM386 instead of the transistor, I get nearly 4 hours of the battery. So battery life is fantastic, but there is very little amplification and it requires many external components which is a big concern given the extremely limited space on my PCB.

I've also tried an Adafruit PAM8302 breakout. This gives the loudest sound from the buzzer but battery life is poor at just under an hour.
Using a TPA2005D1DGN I get slightly over an hour. I was very surprised by both of these given that they are class D amplifiers.

So as it is, the best solution I have is a single transistor and flywheel diode across the buzzer.

So this brings me to my question. I've been reading about class A, B and AB amplifiers and from what I've understood it should be fairly easy and without too many components to modify my original circuit and make it a class AB amplifier. However, what I haven't been able to understand is how to calculate resistor and capacitor values for the class A or class AB amplifier and wondered if somebody could help me here?

If a kind person could do the calculations for me and explain how they did it then that would be amazing! Some values which might help here:
  • I'm using a single Lipo battery so typical output is 3.7v.
  • The Atmega1284 is using a single pin to generate the audio signal (a square wave). Max RMS current draw on the pin is 20ma, absolute max is 40ma.
  • I haven't yet decided which buzzer I'm going to use, but typical resistance seems about 25ohms. If I can make the amplifier more efficient then I may go back to my original speaker.
  • The transistor I'm currently using is a MMBT2222A but I can change this if required. This is an NPN and I haven't looked for a matched PNP.

Thanks in advance,

Glyn
The match for a 2N2222 is a 2N2907. You can also consider a 2N3904 (NPN) and 2N3906 (PNP). Will you be using through hole or surface mount components? Better choices may exist in the surface mount universe, which I have not checked lately. What is the purpose of this audio output?

Do you have knowledge of or access to a simulation program? That would make the explanations and the information transfer much much easier.
Checkout the following article:

http://www.ecircuitcenter.com/Circuits/pushpull/pushpull.htm

They are good for sinewaves, squarewave, and capacitive loads.

WOW
https://www.diodes.com/assets/Datasheets/ds30278.pdf

Looks like a matched pair in a single package.
 
Last edited:

Thread Starter

glyndavidson

Joined Jul 26, 2020
12
Thank you for the fast response and the matched pairs. What would be the advantage of using the 2N3904 over the 2N2222?

I'm using surface mount components.

The purpose is an air pressure sensor (a variometer to be more specific) which "beeps" as the air pressure changes. The frequency of the square wave sent to the buzzer changes depending on how fast the air pressure is changing. Frequencies range from 100hz for a small change in air pressure to 1500hz for a lrage change in pressure.

No, I don't have access to a simulation program unfortunately, although I did have a look at some of the cheap oscilloscopes on Amazon this morning. I've never used one before though and it seemed like stretching out the learning curve more than was necessary.
 

Ylli

Joined Nov 13, 2015
976
Since you are not looking for anything that resembles HiFi, I'd go with the buzzer or even a piezo speaker. Then I would add a differentiator to the base of the transistor to turn that square wave into narrower pulses. Add a diode (1N4148 or eq) between the base and ground with the cathode to the base. Insert a capacitor in series between the volume control and the transistor base/diode. The value of the cap will affect the volume, with the volume and current draw increasing at higher frequencies. Start with something around 0.47 uF. If you must use a polarized cap, the negative term of the cap goes to the transistor base.
 

Thread Starter

glyndavidson

Joined Jul 26, 2020
12
I would add a differentiator to the base of the transistor
Just spent an hour reading about Op-Amps and differentiators but don't feel like I got anywhere with it o_OWhat is the purpose of adding a differentiator to the circuit? Does it turn the square wave into a "sine" wave? I thought that was the purpose of the capacitor?

Add a diode (1N4148 or eq) between the base and ground with the cathode to the base.
What purpose does the diode serve?

Insert a capacitor in series between the volume control and the transistor base/diode. The value of the cap will affect the volume, with the volume and current draw increasing at higher frequencies. Start with something around 0.47 uF. If you must use a polarized cap, the negative term of the cap goes to the transistor base.
Ahh, that explains why I was having problems when using a non-polarised cap.
 

Thread Starter

glyndavidson

Joined Jul 26, 2020
12

Ylli

Joined Nov 13, 2015
976
With a square wave feeding the transistor base, the transistor is simply acting as an on-off switch. It is on 50% of the time, and all it is doing is holding the speaker in the fully retracted (or extended) position. The speaker makes noise when it is moving, not when it is holding still, so you are really just hearing the edges of the square waves anyway. But doing it that way wastes a lot of power. Instead, just pre-select the edges and allow the transistor to turn on just momentarily on the edge, causing the speaker to draw a very short burst of current. Still makes noise, but doesn't waste as much power. The diode prevents the base voltage from going nagative, and creates a path for the capacitor to discharge when the square wave goes low.

Quick sim using an 8 ohm speaker shows an average current draw of >200 mA with the original circuit, and about 20 mA with the modified circuit (still with the 8 ohm speaker). I think that was when I had a 0.1 uF cap on the base.
 

Papabravo

Joined Feb 24, 2006
14,253
Here is a simulation using LTspice (a free download). The BC847BPN is a transistor pair in a single package. You can certainly adapt the circuit to suit multiple purposes.

Push-Pull_SMT.png

I kinda like the suggestion of converting the edges of square wave into a series of impulses. That is what a differentiator does. It takes the derivative of the input.
If you've never heard of such a thing before it can be intimidating but the concept is pretty simple. There are two rules for the squarewave input:
  1. The derivative (output of the differentiator) of ANY constant value is zero.
  2. The derivative of any rapidly changing value is a spike in the direction of the change. So a positive (rising) edge gives a positive spike, and a negative (falling) edge gives a negative spike.
 

Attachments

Papabravo

Joined Feb 24, 2006
14,253
So here is an example of a differentiator. I include images of both the circuit and the output.

Differentiator.png DifferentiatorPlot.png

In the plot the red waveform is the square wave input and the blue waveform is an amplified version of the differentiation. Let me catch up with the other posts that I missed while I was away. I know this is a lot to grab onto, but just take it in bite sized chunks and you will get there.

I made a mistake in computing the components for the high frequency roll-off. Corrected images and LTspice file have been updated in this post.
 

Attachments

Last edited:

Papabravo

Joined Feb 24, 2006
14,253
Had a look at this article then spent the best part of an hour trying to work out how to do SPICE simulations. Ended up banging my head against a wall :D


That looks great, but I wouldn't understand how to calculate the values for the passive components to accompany the ds30278.
The 2N2222 and 2N3904 are from the same era, about 55 years ago. Cost and availability might be concerns. Any general purpose NPN and PNP transistor should work for this application.
Learnimg to do simulations with a graphical interface is not as difficult as it might seem. time enough for that later.

ds30278.pdf is the name of the file containing the datasheet for a surface mount part that you might use. The manufacturer's part number for the part, which is how you will but them, is BC847BPN.

Looking at the schematic diagram in post #8 you see that I selected two resistors of 475 Ω each. I did this to provide adequate but limited currents for the two transistors. When the Voltage generator V3 is at -6 VDC There is 18 VDC across R2 and the diode (+12 - (-6)) VDC = 18 VDC. Subtract from that one standard diode drop of 0.7 VDC and divide by the maximum current. I selected 36 ma, the pick a nearby 1% resistor value. If you choose R# to be the same value as R2 then the same maximum will apply when the generator V3 is at +6 VDC. The minimum current in R2/D1 is when the generator is at +6 VDC, and that is (+12 - 0.7 - 6.0) VDC = 5.3 VDC / 475 Ω ≈ 11 mA.

These choices are not critical and I could have made different ones. You just need to ensure that the transistors have sufficient base current. Would I put this design into production in a high end audio product? No. I designed it originally for switching MOSFETs.

D1 and D2 are there to prevent crossover distortion which happens when V3 makes a zero crossing. There is a dead zone due to the finite Vbe of the transistors. There are several ways to do this compensation and it works surprisingly well.

If you want to try the graphical interface for making schematics without doing the simulation you can get a copy here:

https://www.analog.com/en/design-center/design-tools-and-calculators/ltspice-simulator.html
 

sparky 1

Joined Nov 3, 2018
304
piezo might consume even less current, generate a high sound output for long run.
Blasting a 95dB piezo every few seconds.
 
Last edited:

Thread Starter

glyndavidson

Joined Jul 26, 2020
12
Then I would add a differentiator to the base of the transistor to turn that square wave into narrower pulses. Add a diode (1N4148 or eq) between the base and ground with the cathode to the base. Insert a capacitor in series between the volume control and the transistor base/diode.
Are you saying that diode and capacitor form a differentiator, or is the differentiator a separate component which also needs to be added?
 

Thread Starter

glyndavidson

Joined Jul 26, 2020
12
@Papabravo
Thank you for taking the time to create those schematics, and for making them available to download.
In the examples you give, the circuits all need V+ and V- (this seems like a common thing with op amps). Am I right in thinking that to achieve V- you need two power sources? I'm limited to only using one battery.
 

Thread Starter

glyndavidson

Joined Jul 26, 2020
12
View attachment 213231
In the plot the red waveform is the square wave input and the blue waveform is an amplified version of the differentiation.
So would I be right in thinking that as the square wave changes to a falling edge you get something like this?
DifferentiatorPlot.jpg

Which ultimately is more like a sine wave then, with short impulses rather than holding the speaker cone in any one direction like @Ylli suggested.
 

Papabravo

Joined Feb 24, 2006
14,253
So would I be right in thinking that as the square wave changes to a falling edge you get something like this?
View attachment 213246

Which ultimately is more like a sine wave then, with short impulses rather than holding the speaker cone in any one direction like @Ylli suggested.

Yes that is what was being suggested. It looks like that because what you are looking at is not a sine wave but a nearly linear fall and an exponential decay from -6 VDC back to 0.

The other thing you could do is use a lowpass active filter to remove the high frequency content from the square wave to make it look more like a sinewave. The Class AB output stage works fine that as well. This will work as long as we know the range of frequencies for the square wave.
 

Papabravo

Joined Feb 24, 2006
14,253
@Papabravo
Thank you for taking the time to create those schematics, and for making them available to download.
In the examples you give, the circuits all need V+ and V- (this seems like a common thing with op amps). Am I right in thinking that to achieve V- you need two power sources? I'm limited to only using one battery.
That is just a force of habit. All opamp circuits can be reconfigured to use a single supply. You probably want to change the part you use for one that is designed to have the outputs get as close to the supply rails as possible. You re-arrange things so that your new reference point is Vcc/2, halfway between Vcc and GND
 

Ylli

Joined Nov 13, 2015
976
The speaker only makes sound when it is moving. The cone is only moving when the current through it is changing.
Original circuit: Annotation 2020-07-27 114936.png
With a differentiated input: Annotation 2020-07-27 115253.png
Note difference in average current.
Are you saying that diode and capacitor form a differentiator, or is the differentiator a separate component which also needs to be added?
For the positive going edge of the input square wave, the added capacitor, the 220 ohm resistor, and the input impedance of the transistor form the differentiator. For the falling edge of the input square wave, the capacitor, tthe 220 ohm, plus the added diode form the differentiator.
 

Thread Starter

glyndavidson

Joined Jul 26, 2020
12
Haha! Cool! That spice thing is bloody useful!

With a value of 0.1uF at C1, it sounds really "tinny" on my breadboard and quieter than it did before adding the differentiator.
But... If my understanding is correct, looking at this graph(?) in the Spice simulator, if I swap out C1 for a 0.33uF Capacitor then this would likely produce a better quality sound but still use less current than the original square wave? Is that right?
Annotation 2020-07-27 220815.png
 
Top