Arduino Forum

Using Arduino => General Electronics => Topic started by: nickgammon on Apr 01, 2013, 07:38 am

Title: What is this amplifier doing, exactly?
Post by: nickgammon on Apr 01, 2013, 07:38 am
I'm going to show my ignorance of how transistors work here, but whatever. I'm hoping to improve my understanding. :)

I built up the audio amplifier from the Arduino Basic Connections thread (http://arduino.cc/forum/index.php/topic,154549.0.html) in particular this:

(http://www.gammon.com.au/images/Arduino/Arduino_forum_amplifier_query.png)

I didn't have a BC337 so I used a BC546 instead. I connected a 6 ohm speaker from an old portable radio/cassette player.

It worked great in that it gave nice loud amplification of the tones from the Tone library. Measuring the input signal (from the Arduino pin, in yellow) compared to the transistor collector (blue) shows the amplification isn't perfect, but not too bad.

(http://www.gammon.com.au/images/Arduino/Arduino_forum_amplifier_query2.png)

Now my questions are:



Title: Re: What is this amplifier doing, exactly?
Post by: Grumpy_Mike on Apr 01, 2013, 09:18 am
Quote
What is the purpose of the amplifier? Impedance-matching? Current amplification? Voltage amplification?

Impedance matching and current amplification is the save thing so a bit of all of them.


Is the ringing around the rise and fall expected? Could it be improved somehow?

It is due to the inductance of the speaker, it can be improved by a better transistor or amplifier


Are there any "gotchas" in there? Like, drawing too much current through the transistor, or something?
Yes it is quite a simple amplifier. I would include a 0.1uF cap between the pin input and the amplifier input.

If I wanted to implement a volume control, what would be the recommended way of doing that?
Put a pot directly on the output and connect the wiper through a cap to the input.


Is the purpose of the 100K resistors to bias the transistor base?
Yes


What is the purpose of the 10 ohm resistor? To limit current?
Yes

Is the purpose of the 2.2K resistor for impedance-matching?
No, it is isolating the bias circuit from the DC effects you get from the input pin, that is why I would use a cap because that removes it compleatly
Title: Re: What is this amplifier doing, exactly?
Post by: Erdin on Apr 01, 2013, 09:31 am
I like that ABC guide a lot, but I would not use this circuit. I even think it is really bad.
If the output pin of the Arduino is not set as output, the two 100k resistors will turn the transistor on a little.
The two 100k resistors makes the amplification a little analog, but the Arduino output pin is purely digital.

So I would remove both 100k, and perhaps add a flyback diode over the speaker.

Nick, you can't rely on the measurements. The BC546 can do 100mA, and this circuits requires 278mA. The BC337 is a transistor that can handle 800mA.
Title: Re: What is this amplifier doing, exactly?
Post by: nickgammon on Apr 01, 2013, 09:59 am
Quote
The BC337 is a transistor that can handle 800mA.


Och, well I'm about to order a hundred or so. "Cheaper by the dozen" is the motto. ;)
Title: Re: What is this amplifier doing, exactly?
Post by: nickgammon on Apr 01, 2013, 10:00 am
Quote

The BC546 can do 100mA, and this circuits requires 278mA.


If you could explain that calculation I would be grateful.
Title: Re: What is this amplifier doing, exactly?
Post by: Erdin on Apr 01, 2013, 10:20 am
I read the datasheets for the maximum current of the transistors.
The current is 5V / (10 + 8 ohm) = 278mA, assuming no voltage drop of the transistor and the transistor being fully on.
At 278mA the BC337 has Hfe of about 250. So the 2k2 will turn it into saturation.

The NPN BC337 is an old transistor.
The NPN BC639 is a little newer, it can do 1A, and it has the BC640 as complementary PNP.

These are the prices in my country (a piece)
BC547B : 5 euro cents
BC546B : 6 euro cents
BC337 : 10 euro cents
BC639 : 20 euro cents
Title: Re: What is this amplifier doing, exactly?
Post by: Docedison on Apr 01, 2013, 10:47 am
@ Mike the only point I'd disagree with you on is the input resistor and that is to limit the base current to a safe value. 2K2 is 50 times the "bias'" resistors and as such will have little effect on their operation.. A .1 to 1uF cap (depending on the desired low frequency response) should work well with the 30 k or so input impedance presented at the base lead.

Bob
Title: Re: What is this amplifier doing, exactly?
Post by: pighixxx on Apr 01, 2013, 11:41 am
Ciao,
The initial intentions were to make an amplifier as simple as possible (with only 1 cheap transistor).  :D
There are several modifications that can be done, especially include a capacitor between the input pin and the amplifier.
In the next few hours, i check it and i put an optimized one (with volume control  :D)

PighiXXX

Thanks for the support!
Checking diagrams is a good thing from you because for surely there are people better than me in this forum and together we can do a good job for everyone.
Title: Re: What is this amplifier doing, exactly?
Post by: nickgammon on Apr 01, 2013, 11:49 am
I am extremely grateful for your insight.

@pighixxx - I am testing to check my knowledge is sufficient to understand your diagrams, and if things don't work perfectly I'm keen to understand why. Perhaps it's my fault.

:)
Title: Re: What is this amplifier doing, exactly?
Post by: krupski on Apr 01, 2013, 02:52 pm

I built up the audio amplifier from the Arduino Basic Connections thread (http://arduino.cc/forum/index.php/topic,154549.0.html) in particular this:


That amplifier is a "Class A" amplifier. Theoretically, it is supposed to be biased so that with no signal, the collector sits at about 1/2 Vcc (so that it can swing UP to VCC and DOWN to GND).

The resistors on the base circuit create a bias (base current * beta = collector current) to keep the transistor conducting (that is, in a Class-A mode).

The top bias resistor is connected to the collector to provide NEGATIVE feedback and stabilize the bias. That is, if the bias is too "strong", the collector will go lower and decrease the base bias, thereby self-stabilizing the circuit.

I would try this for fun: Remove the 2.2K resistor between the Arduino and the transistor base and replace it with a 1 uF (not critical) capacitor (positive side to the transistor base).

Here's a sketch I made for another guy a while back to explain Class A and Class B amplifiers. Hopefully this will help:

(edit to add): If you take the "Class A" sketch and invert it so that the "spring" is at the top, that is basically the same as your circuit - and BJT vs MOSFET doesn't matter - they both do the same jobs - albeit in a different way.

(edit to add more): Notice that the Class B amplifier "rope" needs to be taut, otherwise there will be a small "dead zone" where the speaker doesn't move. The tension on the rope is the bias, and if there isn't enough bias and the rope is loose, the dead zone on the speaker is called "crossover distortion".
Title: Re: What is this amplifier doing, exactly?
Post by: CrossRoads on Apr 01, 2013, 04:46 pm
Hey Nick,
This is the amplifier I have in my fencing scoring machines, driven by a burst of Tone to make a nice two-tone warble when a touch is scored (sounds like cell phone ring).
Can probably replace the MOSFET with NPN too. (The IFR3707Z apparently went obsolete right after I bought a sleeve of 10.)

When input is Low, transistor is off, cap keeps any DC from flowing into the speaker, but the yellow wire sits high.
When input is High, transistor turns on, pulls cap low to move speaker one direction.
When input goes back high, the cap goes high and the transition thru the cap drives the speaker the other other direction until the cap charges up again.
So Tone makes a nice sound with this MOSFET and speaker. The 68 ohm resistors were an attempt at high/low volume control - my wife says it is still way too loud.
Title: Re: What is this amplifier doing, exactly?
Post by: CrossRoads on Apr 01, 2013, 04:48 pm
This is the speaker. I am quite happy with them.
http://www.mpja.com/4-Ohm-Mini-Speaker/productinfo/14618%20SP/
Title: Re: What is this amplifier doing, exactly?
Post by: oric_dan on Apr 01, 2013, 08:30 pm
Well, actually, not "quite" a Class A design. Class A is intended to bias the transistor
into its linear region of operation, but you'll never get that with the ckt as shown.

It looks like the person who designed it had the intent of Class A, but you would need
a resistor in the emitter lead, so the 100Ks on the base have something to bias in
a stable fashion. As it is, they simply turn on the transistor, and whether or not the
collector sits at Vcc/2 is strictly a factor of the hFE [beta] dc current-gain of the
transistor.

But there is a much more serious problem with this design, namely that there will be
a constant dc-bias on the speaker and a non-trivial amount of dc-current continually
running through it. Not good, the speaker can burn up. Instead, speakers should be
AC-coupled through a large capacitor with a ckt like this - ie, attempted Class A. And
unfortunately, that cap needs to be a large value, eg 220 uF, to get proper low-
frequency response, since the speaker impedance is so small.

Also, with a proper Class B, as Krupski mentioned, the positive and negative drive
ckts will be adjusted so the DC current through the speaker is 0, so that takes care of
the problem of continuous current burning up the speaker.

Advice - throw this ckt away, use something better.
Title: Re: What is this amplifier doing, exactly?
Post by: nickgammon on Apr 01, 2013, 10:33 pm
Thanks for the comments everyone!


But there is a much more serious problem with this design, namely that there will be
a constant dc-bias on the speaker and a non-trivial amount of dc-current continually
running through it.


Why is there that current (which incidentally the scope trace appears to agree with)?

If the transistor is "off" it shouldn't be conducting, should it? Or does the biasing keep it on? I guess it must be that, because on the scope it looks like when the input signal is off, the output signal is around 2.2V.
Title: Re: What is this amplifier doing, exactly?
Post by: oric_dan on Apr 01, 2013, 10:54 pm

Thanks for the comments everyone!


But there is a much more serious problem with this design, namely that there will be
a constant dc-bias on the speaker and a non-trivial amount of dc-current continually
running through it.


Why is there that current (which incidentally the scope trace appears to agree with)?

If the transistor is "off" it shouldn't be conducting, should it? Or does the biasing keep it on? I guess it must be that, because on the scope it looks like when the input signal is off, the output signal is around 2.2V.

Yes, that's it. If you remove the 100K pullup, and keep the 100K pulldown - to keep
the transistor turned off, and then capacitively couple the input signal, as others have
mentioned, then the transistor will stay off when no signal is present. Then, you also
don't need to capacitor-couple the speaker.

However, you'll only ever get square-wave outputs [ie, rasty sounding things] from
your speaker.

It is possible to get sweeter sounding audio using the Arduino. Would require going to
a true Class A amplifier ckt [or more complex Class B, etc, as Krupski mentioned], and
then using high-frequency PWM, modulated at a lower audio rate, and then using
low-pass filters ahead of the amplifier to smooth out and anti-alias the PWM. 

Title: Re: What is this amplifier doing, exactly?
Post by: nickgammon on Apr 01, 2013, 11:01 pm
Interesting. In this particular case I am feeding in square waves anyway, so that's no great loss.

I mean, you can get amplifier chips for a couple of dollars if you want proper amplification, but I was leaning towards getting the square wave tones out of the thing to be loud enough to hear, and not damage the output pin.

So your suggestion of adding the capacitor, and removing the resistor, could well achieve that with minimal effort.

BTW, if I remove the resistor between collector and base, wouldn't the capacitor need to have the positive side (if it had one) to the Arduino output pin, and not the transistor base, as the output pin would be more positive?
Title: Re: What is this amplifier doing, exactly?
Post by: CrossRoads on Apr 02, 2013, 12:49 am
Nick,
Wire it up like my Mosfet example. The cap keeps the DC out of the speaker, and the sound is nice.

Here's the heart of the code:
Code: [Select]

// info on alarm sound
#include "pitches.h"

// notes in the melody:
int thisNote = 0;
int noteDuration = 0;
int pauseBetweenNotes = 0;
int melody[] = {
 NOTE_C6, NOTE_A5, NOTE_C6, NOTE_A5, NOTE_C6, NOTE_A5, NOTE_C6};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
 12,12,12,12,12,12,4};


Code: [Select]

 // create a warble once
 for (thisNote = 0; thisNote < 8; thisNote++)
 {
   // to calculate the note duration, take one second
   // divided by the note type.
   //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
   noteDuration = 1000/noteDurations[thisNote];
   noTone(6);       //apparent known bug - need this for the tone to play next.
   tone(6, melody[thisNote],noteDuration);
   // to distinguish the notes, set a minimum time between them.
   // using the note's duration + 10%:
   pauseBetweenNotes = noteDuration * 1.10;
   delay(pauseBetweenNotes);
   // stop the tone playing:
   //  noTone(6);
 }

pitches.h is  tab in my sketch:
Code: [Select]

/*************************************************
* Public Constants
*************************************************/

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978
Title: Re: What is this amplifier doing, exactly?
Post by: nickgammon on Apr 02, 2013, 01:09 am

So I would remove both 100k, and perhaps add a flyback diode over the speaker.


First experiment ...

Without flyback diode:

(http://www.gammon.com.au/images/Arduino/Arduino_forum_amplifier_query4.png)




With flyback diode:

(http://www.gammon.com.au/images/Arduino/Arduino_forum_amplifier_query3.png)
Title: Re: What is this amplifier doing, exactly?
Post by: Erdin on Apr 02, 2013, 01:14 am
Nice pictures! Even I didn't expect a normal loudspeaker to cause that spike.
Title: Re: What is this amplifier doing, exactly?
Post by: nickgammon on Apr 02, 2013, 01:23 am
Next experiment:


I would try this for fun: Remove the 2.2K resistor between the Arduino and the transistor base and replace it with a 1 uF (not critical) capacitor (positive side to the transistor base).


0.33 uF capacitor added in series with the 2.2K resistor:

(http://www.gammon.com.au/images/Arduino/Arduino_forum_amplifier_query5.png)




0.33 uF capacitor added instead of the 2.2K resistor:

(http://www.gammon.com.au/images/Arduino/Arduino_forum_amplifier_query6.png)

The sound is a bit thin with this one.
Title: Re: What is this amplifier doing, exactly?
Post by: nickgammon on Apr 02, 2013, 01:31 am

So I would remove both 100k, and perhaps add a flyback diode over the speaker.


Back to original circuit, (no capacitor), however the 100K resistor from collector to base removed (flyback diode still in place):

(http://www.gammon.com.au/images/Arduino/Arduino_forum_amplifier_query7.png)

Now both 100K resistors removed (looks much the same to me):

(http://www.gammon.com.au/images/Arduino/Arduino_forum_amplifier_query8.png)

Title: Re: What is this amplifier doing, exactly?
Post by: MarkT on Apr 02, 2013, 01:34 am
The DC bias on the speaker will push (or pull) the diaphragm well away from centre and thus
can give strong even harmonics or worst-case damage the mechanical suspension - not good.

For a novelty speaker driver try a MOSFET driver chip like the MIC4422 which takes logic level
in and can run from 5 to 18V and deliver up to 9A!! (at 18V).  Definitely want to use an output
capacitor to protect the chip and speaker, and check it doesn't overheat, but it is also plenty
fast enough to run as a class-D amplifier very nicely - a fast PWM signal for instance will get
you 8-bit audio of sorts.



Title: Re: What is this amplifier doing, exactly?
Post by: nickgammon on Apr 02, 2013, 01:44 am
This is a variation of what CrossRoads suggested:

(http://www.gammon.com.au/images/Arduino/Arduino_forum_amplifier_query9.png)

I kept the transistor, put 100 ohm and a 0.33 uF in series with the signal to the base.

No resistor from collector to base, and 1K from base to emitter.

Sounds a bit thin still. Maybe I'm not doing it right.
Title: Re: What is this amplifier doing, exactly?
Post by: CrossRoads on Apr 02, 2013, 02:00 am
Maybe depends on the speaker too. Mine definitely do not sound thin.
Title: Re: What is this amplifier doing, exactly?
Post by: nickgammon on Apr 02, 2013, 02:00 am
Wiring it like this (I think):

(http://www.gammon.com.au/images/Arduino/Arduino_forum_amplifier_query10.png)

I get this output:

(http://www.gammon.com.au/images/Arduino/Arduino_forum_amplifier_query11.png)




Change the 2.2K base resistor to 100 ohms (is that good for the output pin?) and I get:

(http://www.gammon.com.au/images/Arduino/Arduino_forum_amplifier_query12.png)

That last one sounds pretty good (and loud!).
Title: Re: What is this amplifier doing, exactly?
Post by: nickgammon on Apr 02, 2013, 02:12 am
I was starting to doubt that the thing I had in my hand really was a capacitor (it was just sitting around on a breadboard) so I swapped it out for a 1 uF electrolytic. Got much the same results as with the other capacitor, with the last circuit above (with the 100 ohm resistor) and a 1 uF capacitor in series with that:

(http://www.gammon.com.au/images/Arduino/Arduino_forum_amplifier_query13.png)

I just don't "get" the shape of the blue line. I obviously need to learn more about capacitors and the way they work in circuits like this.
Title: Re: What is this amplifier doing, exactly?
Post by: westfw on Apr 02, 2013, 02:16 am
Quote
throw this ckt away, use something better.

Bah.  It attempts to be an audio amplifier, but the arduino isn't feeding it "audio" anyway, so there is little point.
Throw it away and replace it with something simpler that ISN'T anything close to an audio amp.  Like the traditional "higher power" transistor switch...
Title: Re: What is this amplifier doing, exactly?
Post by: nickgammon on Apr 02, 2013, 02:22 am
The circuit in reply #24 is close to that isn't it, Westfw?
Title: Re: What is this amplifier doing, exactly?
Post by: afremont on Apr 02, 2013, 02:38 am
The cap is doing what caps do, it's trying to prevent a change in voltage by supplying a large amount of current when it first switches.  Notice how the upper trace (yellow) pin voltage sags when it switches.  I think the 100 ohm resistor performance shows that the transistor is too small since driving it so hard gets it to produce a much better looking wave.
Title: Re: What is this amplifier doing, exactly?
Post by: oric_dan on Apr 02, 2013, 03:29 am
Try a 10 or 22 uF cap, instead of 0.33 uF. Maybe also use a 100 ohm R from emitter
to ground. This should greatly improve the low-frequency response. Those rapid decays
in the waveforms are due to the input time-constant being way too small.

The large overshoot without the snubbing diode is the typical inductive kickback that
occurs when you open the current to the speaker.
Title: Re: What is this amplifier doing, exactly?
Post by: nickgammon on Apr 02, 2013, 04:53 am
I found a 220 uF cap lying around and that gives this:

(http://www.gammon.com.au/images/Arduino/Arduino_forum_amplifier_query14.png)

I presume I put the + side on the Arduino side? That's the more positive side of it, right?




As for the 100 ohm between emitter and ground, that made it much softer:

(http://www.gammon.com.au/images/Arduino/Arduino_forum_amplifier_query15.png)

Did you mean to replace the 1K with 100 ohm between base and ground?
Title: Re: What is this amplifier doing, exactly?
Post by: oric_dan on Apr 02, 2013, 05:50 am
The 220 uF looks much better than 0.33 uF. The quick decay is gone, and you'll
not have any dc-currents through the speaker.

I thought the 100R in the emitter would help improve the low-freq response, but
it also kills the gain too much. So you might go back to tying the emitter to gnd,
and use a 10K in series with the 220 uF cap on the base. I might also use a larger R
on the base to gnd, eg go back to the 100K.

I'm not sure why you're getting the overshoot on the leading edge. Do you have the
scope probe ground lead tied close to the same point as the speaker gnd, or right
at the emitter?
Title: Re: What is this amplifier doing, exactly?
Post by: nickgammon on Apr 02, 2013, 06:16 am
The Arduino Gnd pin, so there was a bit of a cable run. I moved it to next to the emitter, but no real change on the display.

By a coincidence I got these in the mail today from eBay:

(http://www.gammon.com.au/images/Arduino/Arduino_forum_amplifier_query16.jpg)

2 Channels 3W PAM8403 Class D Audio Amplifier Board 5V

$US 2.84 each.

Wired one up to my iPhone and those old speakers. Quite nice sound out of it.
Title: Re: What is this amplifier doing, exactly?
Post by: nickgammon on Apr 02, 2013, 06:29 am

So you might go back to tying the emitter to gnd, and use a 10K in series with the 220 uF cap on the base.


Nah, that just killed the sound altogether (the 10K resistor).
Title: Re: What is this amplifier doing, exactly?
Post by: Learning on Apr 02, 2013, 06:51 am
Your question on the 10 ohm resistor was good. It is exactly for current limiting. Remember the 6-8 ohm speaker is an impedance (Xl = 2*pi*f*l) usually measured at 1000 HZ. So with no ac signal, the dc value of that speaker is basically a short circuit.
Title: Re: What is this amplifier doing, exactly?
Post by: krupski on Apr 02, 2013, 04:02 pm

Well, actually, not "quite" a Class A design. Class A is intended to bias the transistor
into its linear region of operation, but you'll never get that with the ckt as shown.

It looks like the person who designed it had the intent of Class A, but you would need
a resistor in the emitter lead, so the 100Ks on the base have something to bias in
a stable fashion. As it is, they simply turn on the transistor, and whether or not the
collector sits at Vcc/2 is strictly a factor of the hFE [beta] dc current-gain of the
transistor.

Advice - throw this ckt away, use something better.



Sure it's Class A. Class A is defined as bias current flowing all the time. Class A doesn't HAVE to also be "linear".

And, given the choice of Class A, Class AB, Class B, Class C or Class D, what would YOU call it?  :)

The emitter resistor isn't really needed because the bias-stabilizing negative feedback comes from the fact that the top base resistor is connected to the COLLECTOR and not to VCC.

I agree though, that circuit is better off in the trash can!  :)
Title: Re: What is this amplifier doing, exactly?
Post by: krupski on Apr 02, 2013, 04:05 pm

This is the speaker. I am quite happy with them.
http://www.mpja.com/4-Ohm-Mini-Speaker/productinfo/14618%20SP/



For a tiny speaker amp, why not an LM-386?
Title: Re: What is this amplifier doing, exactly?
Post by: krupski on Apr 02, 2013, 04:11 pm

By a coincidence I got these in the mail today from eBay:

(http://www.gammon.com.au/images/Arduino/Arduino_forum_amplifier_query16.jpg)

2 Channels 3W PAM8403 Class D Audio Amplifier Board 5V

$US 2.84 each.

Wired one up to my iPhone and those old speakers. Quite nice sound out of it.


Nice!

Here's my 300 watts per channel Class-D power amplifier (300W into 4 ohms, 150W into 8 ohms and 50V output swing +50/-50). Bwahahaaa!!! :)
Title: Re: What is this amplifier doing, exactly?
Post by: CrossRoads on Apr 02, 2013, 04:17 pm
Very nice - but will it give Tone outputs that nice warm Tube sound? 8)
Title: Re: What is this amplifier doing, exactly?
Post by: oric_dan on Apr 02, 2013, 07:46 pm


So you might go back to tying the emitter to gnd, and use a 10K in series with the 220 uF cap on the base.


Nah, that just killed the sound altogether (the 10K resistor).

I don't know what works best from 5000 miles away, so you have to play with values, :-).

But I would definitely keep the cap in line to the base and the R to gnd on the base [but
larger than 1K], so the amp is turned off with no signal input, and so no DC flows through
the speaker. With these in place, you can remove the 10 ohm R from the speaker line.

Quote
And, given the choice of Class A, Class AB, Class B, Class C or Class D, what would YOU call it?

The emitter resistor isn't really needed because the bias-stabilizing negative feedback comes from the fact that the top base resistor is connected to the COLLECTOR and not to VCC.

My feeling was, the original ckt was an "attempt" at a Class A linear design, but not
especially well done, ;-).

And you're right, I overlooked that the upper base R is really connected for "self-biasing"
and not normal Class A linear operation, which brought the comment about an emitter R.
So, I get a demerit for that [bad dog]. OTOH, I've tried self-biasing ckts like that, and
never found them to be very stable with beta and temperature variations. The emitter R
is the way to get real gain stability.

Also, of course, if you are going to do either bias scheme, then you need to isolate
the speaker using a really big cap, as previously mentioned.

So, would Nick's ckt as is be a Class C?
Title: Re: What is this amplifier doing, exactly?
Post by: Learning on Apr 02, 2013, 08:41 pm
If the device (tube or transistor) operates into 'cutoff', it will meet the class C fingerprint.
Title: Re: What is this amplifier doing, exactly?
Post by: BillO on Apr 02, 2013, 09:57 pm
It's really just acting like a switch.  I'd hazard to say you could call it a class 'D' amplifier, but even that would not be right.  Class 'C' would, I guess, be closest.

Edit:  On second thought, no, it's not a class 'C'.  It's just a switch.  It gets driven between saturation and cut-off and is not linear in any way.  For lack of a proper name, we could call it a class 'S' amplifier.
Title: Re: What is this amplifier doing, exactly?
Post by: nickgammon on Apr 02, 2013, 11:08 pm
I did a DC test of this circuit from page 2:

(http://www.gammon.com.au/images/Arduino/Arduino_forum_amplifier_query10.png)

I replaced the speaker with a 10R resistor, just in case I damaged it.

With the input grounded the current flow was virtually zero.

With the input at 5V the current flow was 100 mA (which seems to be the limit for the BC546 if the value for "Collector Current (DC)" is the correct one to look at (absolute maximum ratings, heh).

Replacing the 2.2K resistor with 100R gives a higher current (160 mA) but I guess the transistor won't be liking that, huh?

The capacitor doesn't seem to make much difference. With no input voltage, the transistor won't turn on, and current won't flow, whether or not it's there, am I right?

I measured 1.8 mA current drawn from the Arduino (input) when on, so that would seem to be well within the limits of a digital output pin.

So as a simple "square wave" amplifier (or indeed digital switch) are there any problems with the above circuit?
Title: Re: What is this amplifier doing, exactly?
Post by: oric_dan on Apr 02, 2013, 11:23 pm
Yes, if the input stays high, then the speaker burns up. Can you 100% guarantee the
Arduino I/O pin will always be low 100% of the time when not using the amp?
Title: Re: What is this amplifier doing, exactly?
Post by: Learning on Apr 02, 2013, 11:25 pm
class C amplifier [‚klas ?s? ?am·pl?‚f?·?r]
(electronics)
An amplifier in which the bias on the control element is appreciably greater than the cutoff valve, so that the output current in each device is zero when no alternating control signal is applied, and flows for appreciably less than half of each cycle when an alternating control signal is applied.
A transistor amplifier in which each transistor is in its active region for significantly less than half the signal cycle.
Title: Re: What is this amplifier doing, exactly?
Post by: oric_dan on Apr 02, 2013, 11:29 pm
Quote
flows for appreciably less than half of each cycle

So what is the class if current flows for half of each cycle, as here?

As I recall, Class C RF amps rely on the low-duty "ping" to stimulate the LC tank,
and set it to oscillating.
Title: Re: What is this amplifier doing, exactly?
Post by: nickgammon on Apr 02, 2013, 11:32 pm

Yes, if the input stays high, then the speaker burns up. Can you 100% guarantee the
Arduino I/O pin will always be low 100% of the time when not using the amp?


OK, so the input capacitor means only transitions drive the speaker, and if I happen to load a sketch that drives the pin high full-time, then the speaker is OK. I get it. Thanks.
Title: Re: What is this amplifier doing, exactly?
Post by: BillO on Apr 02, 2013, 11:35 pm

So as a simple "square wave" amplifier (or indeed digital switch) are there any problems with the above circuit?


Hi Nick,

Have you tried something like this?  This will eliminate the possibility of DC on the speaker and has a similar small parts count.  The transistor is a 2N2222.
Title: Re: What is this amplifier doing, exactly?
Post by: oric_dan on Apr 02, 2013, 11:38 pm
Oof, 1/2 Amp through the transistor when input held high. Nice 2.5W glow worm.
Title: Re: What is this amplifier doing, exactly?
Post by: Learning on Apr 02, 2013, 11:53 pm

Quote
As I recall, Class C RF amps rely on the low-duty "ping" to stimulate the LC tank,
and set it to oscillating.



Right! low-duty "ping" or a spike like pulse. Most RADAR amplifiers operate as class C. A Low duty cycle packs all that power into a very narrow bandwidth, like a CW transmitter as well. 
Title: Re: What is this amplifier doing, exactly?
Post by: afremont on Apr 03, 2013, 01:24 am

Quote
flows for appreciably less than half of each cycle

So what is the class if current flows for half of each cycle, as here?

As I recall, Class C RF amps rely on the low-duty "ping" to stimulate the LC tank,
and set it to oscillating.



Class AB amps as in HF ham radio linear amplifiers rely on the tank circuit to generate the entire other half of the waveform.  Class C amplifiers are non-linear, but that doesn't matter for FM or CW amplification.
Title: Re: What is this amplifier doing, exactly?
Post by: krupski on Apr 03, 2013, 03:20 am

Very nice - but will it give Tone outputs that nice warm Tube sound? 8)


No. No it will not.  :(
Title: Re: What is this amplifier doing, exactly?
Post by: BillO on Apr 03, 2013, 03:21 am

Oof, 1/2 Amp through the transistor when input held high. Nice 2.5W glow worm.


Well, maybe you can show me the math on that?  Vce measured at .5V in my test rig with that rascally little ole input held high.  That's .25W where I live.  And if you're real paranoid about it, decouple the DC with a cap on the input.

Just wondering though, why would you leave the input high?  Do you not have control over that in your world?  Interesting.  Here in Canada microcontrollers do what you tell them to.  Unusual, I know, but must be a Great White North thing.
Title: Re: What is this amplifier doing, exactly?
Post by: oric_dan on Apr 03, 2013, 04:15 am


Oof, 1/2 Amp through the transistor when input held high. Nice 2.5W glow worm.

Well, maybe you can show me the math on that?  Vce measured at .5V in my test rig with that rascally little ole input held high.  That's .25W where I live.  And if you're real paranoid about it, decouple the DC with a cap on the input.

5V/10ohms = 0.5 Amp.
5V*5V/10ohms = 2.5 Watts.

Plus, it's much much worse if you're not providing enough base drive to saturate transistor.
Worst case, 1.25 watts --> transistor=poof!

Quote
Just wondering though, why would you leave the input high?  Do you not have control over that in your world?  Interesting.  Here in Canada microcontrollers do what you tell them to.  Unusual, I know, but must be a Great White North thing.

Read post #43.
Title: Re: What is this amplifier doing, exactly?
Post by: retrolefty on Apr 03, 2013, 05:03 am
Quote
Just wondering though, why would you leave the input high?  Do you not have control over that in your world?  Interesting.  Here in Canada microcontrollers do what you tell them to.  Unusual, I know, but must be a Great White North thing.


Lots of things work well in Canada, but too bad their beer is so bad!

Lefty
Title: Re: What is this amplifier doing, exactly?
Post by: oric_dan on Apr 03, 2013, 06:34 am
You've obviously never had a Moosehead, lefty, but apparently their GreatNorthern
Transistors don't go poof, even if your code forgets to set the I/O pin low.
Title: Re: What is this amplifier doing, exactly?
Post by: Docedison on Apr 03, 2013, 10:20 am
D'you think the moose would care too much?
Title: Re: What is this amplifier doing, exactly?
Post by: BillO on Apr 03, 2013, 01:43 pm

5V/10ohms = 0.5 Amp.
5V*5V/10ohms = 2.5 Watts.


Brilliant.  Thanks for that.  Now I see where your signature line comes from.

Plus, it's much much worse if you're not providing enough base drive to saturate transistor.
Worst case, 1.25 watts --> transistor=poof!


There is enough drive.  You keep talking about situations that, unless your a total zonk, should never occur.  What if you attach the power to your Atmega328 backwards?  What if you try to monitor a 12V signal directly?  There are so many things you could do wrong, so I am not sure where you are coming from on this.  That circuit is up a n running in my lab.  It does not get hot, explode or glow if used the way it was intended.  Just like so many things.

Read post #43.


Just because you said something from the OneD TenT file earlier does not make it any more realistic if you reference it again.  You simply execute a digitalWrite(LOW) to the pin in question once you are done making pretty sounds.  This is so obvious I'm embarrassed to have to spell it out.

Again, it you are a total zonk, then I could suggest some small alterations to the circuit that should allow it to deal with your shortcomings.

1) Put a DC blocking capacitor on the input.  This will require the addition of a cap and a resistor
2) Use a 3W resistor on the collector

... and ... change the base resistor to 500 ohms.

However, none of this is necessary as it works just fine as it is.  BTW, any Canadian beer is better than Old Milwaukee!!

Even this guy know what I'm talking about.
Title: Re: What is this amplifier doing, exactly?
Post by: afremont on Apr 03, 2013, 02:08 pm
On BILLO's circuit.  According to the Fairchild datasheet for a 2n2222a, Vce(sat) is 1V for "large" currents.  That means that a maximum of 1V will be dropped by the transistor and a minimum of 4V will be dropped by the resistor.  That puts the max collector current at 4V / 10R = 400mA.  That means the resistor will be dissipating 4V * 400mA = 1.6W which will exceed the resistors max dissipation.  The 2n2222a will be dissipating 1V * 400mA = 400mW which will exceed the derated maximum dissipation for the transistor as it heats up.  Tell me where I got it wrong please.
Title: Re: What is this amplifier doing, exactly?
Post by: BillO on Apr 03, 2013, 02:23 pm
I think I've entered the twilight zone.

Okay, one more time.... I did not design the circuit to be turned on and left that way.

So, since every single person who looks at this is assuming that they will be forced against there better judgement to use it incorrectly, I will update the design and test it to make sure it is idiot proof.
Title: Re: What is this amplifier doing, exactly?
Post by: afremont on Apr 03, 2013, 02:39 pm

I think I've entered the twilight zone.

Okay, one more time.... I did not design the circuit to be turned on and left that way.

So, since every single person who looks at this is assuming that they will be forced against there better judgement to use it incorrectly, I will update the design and test it to make sure it is idiot proof.



I intended no offense, just offering up my thoughts and trying to be sure that I understand the circuit.  :)  When it comes to these microcontrollers, anything can happen.  The output pin being left high wouldn't be an unusual situation during development, so how else should the circuit be analyzed?  I'm thinking that just adding a blocking cap on the base along with a pulldown and it should be well protected from DC.  At 50% duty cycle, everything should be fine, but you might want to use a smaller resistor on the base since hfe at large currents is as low as 20, unless I got it all wrong.
Title: Re: What is this amplifier doing, exactly?
Post by: BillO on Apr 03, 2013, 03:58 pm
I do understand what you are saying, at least partially.  I'm not sure where you got the hfe of 20.  My spec sheet (Farichild 09/99) states a worst case hfe of 40 @ 500mA and shows a typical of around 80 @ 500ma.  The transistor I am using actually measures at 121, but that is besides the point.  Looking at DC characteristics in a circuit like this is pointless.  The average current through the transistor is much less than 500ma.  In fact, at 400hz the circuit only draws about 200ma.

I've come up with a 'better' circuit that will be (almost) idiot proof.  I am just going to build it and test it to make sure it meets the design specs.  However, I am cannot seem to come up with fool-proof design based on the simple switch we've been discussing here, so the new circuit is an AC-coupled class 'A'.  I'll post the schematic when I'm done the tests.
Title: Re: What is this amplifier doing, exactly?
Post by: afremont on Apr 03, 2013, 04:46 pm
Oops, you're right the minimum hfe is around 40.  But average current isn't the point, this is about idiot-proof non-self-destructive design. ;)  If the average is 200mA then the max is 400mA which will melt things if it gets stuck on. 

I don't see any need for a class A amp, common emitter class B should be plenty good enough and use less power.  Sound quality certainly isn't the issue.  An emitter follower would be good enough I think.
Title: Re: What is this amplifier doing, exactly?
Post by: CrossRoads on Apr 03, 2013, 04:48 pm
Sounds like the discussion has come back around to this.
AC coupled, transistor turns off when Input gets held High or Low, no DC going thru the speaker either.
Title: Re: What is this amplifier doing, exactly?
Post by: CrossRoads on Apr 03, 2013, 04:51 pm
I have 5 of these running, I have two Tones to make a nice output warble like a loud cell phone ring. Have been running since Jan 2011, so 2+ years. Ignore the header/switch at the top left, just use a series resistor from V+ to the transistor.
Title: Re: What is this amplifier doing, exactly?
Post by: CrossRoads on Apr 03, 2013, 06:10 pm
This article goes into depth of the single gate amplifier. Scroll down to page 8.
http://www.ece.ucsb.edu/Faculty/rodwell/Classes/ece2c/labs/Lab_2_2C_2007.pdf
We don't need it biased to operate in the linear region since the tone output is either on or off - hence the amplifiers output can be on or off as well.
Title: Re: What is this amplifier doing, exactly?
Post by: afremont on Apr 03, 2013, 06:14 pm
Yeah, like Crossroads showed.  Class B and no wasted energy with DC idle currents.
Title: Re: What is this amplifier doing, exactly?
Post by: BillO on Apr 03, 2013, 06:22 pm

Oops, you're right the minimum hfe is around 40.  But average current isn't the point, this is about idiot-proof non-self-destructive design. ;)  If the average is 200mA then the max is 400mA which will melt things if it gets stuck on.


Well, I'm not sure that would be self-destructive.  In any case, as I said before, just rate the collector resistor at 3w.  Problem solved.  But read on... 

I don't see any need for a class A amp, common emitter class B should be plenty good enough and use less power.  Sound quality certainly isn't the issue.  An emitter follower would be good enough I think.


Class 'A' because I'm sure someone will likely find fault with any other solution.  Since they have not seen it before, they will assume it just doesn't work.  Not that they won't find fault with a class 'A'.  Also, class 'A' will only require a couple of extra parts.  Since the very simple was apparently too simple, why not go the extra step and make it something everyone can look up and wrap their heads around. BTW, I can't seem to get my head around an emitter follower solution.  Not that it won't work.

So, below is the class 'A' I came up with.  Draws 210mA @ 5V and delivers 125mw into 8ohms from 20Hz to 6KHz.  Has typical single stage class 'A' distortion on sine a triangle waveforms and is biased to start clipping more or less symmetrically at Vin = about 4.5V.  Square waves produce an expected over-shoot spike which is controlled by C3.  If you don't care about the over-shoot, you can leave C3 out.  The over-shoot on square waves causes and appreciable increase in gain at frequencies above 6KHz.  Increasing C3 can help with this.

It works as described and does not get hot, explode, glow, kick the dog or beat the wife despite what you may believe.  You can leave the drive pin high or low as you wish.  If you want to prove it is does anything other than what I've stated, build one and show me actual results.  So, all you 'Bash Street Kids', have at it. 
Title: Re: What is this amplifier doing, exactly?
Post by: BillO on Apr 03, 2013, 06:32 pm

This article goes into depth of the single gate amplifier. Scroll down to page 8.
http://www.ece.ucsb.edu/Faculty/rodwell/Classes/ece2c/labs/Lab_2_2C_2007.pdf
We don't need it biased to operate in the linear region since the tone output is either on or off - hence the amplifiers output can be on or off as well.


I agree.
Title: Re: What is this amplifier doing, exactly?
Post by: oric_dan on Apr 03, 2013, 09:32 pm
Quote
... I will update the design and test it to make sure it is idiot proof.

From a practical viewpoint, this should be Rule #1, since everybody who's ever done
anything at all knows how large the idiot population really is.
Title: Re: What is this amplifier doing, exactly?
Post by: retrolefty on Apr 03, 2013, 09:37 pm

Quote
... I will update the design and test it to make sure it is idiot proof.

From a practical viewpoint, this should be Rule #1, since everybody who's ever done
anything at all knows how large the idiot population really is.


"Make it idiot proof and someone will make a better idiot."

Title: Re: What is this amplifier doing, exactly?
Post by: CrossRoads on Apr 03, 2013, 09:53 pm
I have a card at home that someone here in the forum sent me 2 years ago that uses a 754410  H-bridge chip as the amplifier.

http://www.ti.com/product/sn754410
Title: Re: What is this amplifier doing, exactly?
Post by: oric_dan on Apr 03, 2013, 10:10 pm


Quote
... I will update the design and test it to make sure it is idiot proof.

From a practical viewpoint, this should be Rule #1, since everybody who's ever done
anything at all knows how large the idiot population really is.


"Make it idiot proof and someone will make a better idiot."

Yeah well, such is life in the trenches. OTOH, adding one small feature can have an
enormous impact - case in point, the input cap on the ckt being discussed here ad
infinitum. Leave off that cap and the consequences can be easily disasterous.

For years, all of my pcbs have used simple series-R protection on the I/O pins, and
no one ever blew up one of my boards [at least that owned up to it]. OTOH, back
in the days of yore, another guy was selling similar boards with no protection and
all smt parts, and every single day on the associated forum, some poor guy came
on crying he had blown his xxxx board. Some designs are "more" idiot-proof than
others, I guess.
Title: Re: What is this amplifier doing, exactly?
Post by: retrolefty on Apr 03, 2013, 10:26 pm

Quote

For years, all of my pcbs have used simple series-R protection on the I/O pins, and
no one ever blew up one of my boards [at least that owned up to it]. OTOH, back
in the days of yore, another guy was selling similar boards with no protection and
all smt parts, and every single day on the associated forum, some poor guy came
on crying he had blown his xxxx board. Some designs are "more" idiot-proof than
others, I guess.


No finer example of design for protection then the Ruggeduino. There is a lot one can learn
from reading it's schematic.

http://ruggedcircuits.com/html/ruggeduino.html

http://ruggedcircuits.com/AM010/am010.pdf
Title: Re: What is this amplifier doing, exactly?
Post by: oric_dan on Apr 03, 2013, 11:12 pm
There are a lot of good features on the ruggeduino board. One can argue about
this, but from my years of experience, the single most important one is the
series-Rs in the I/O lines. Those alone save the microcontroller 20 different ways.
Title: Re: What is this amplifier doing, exactly?
Post by: BillO on Apr 03, 2013, 11:28 pm

From a practical viewpoint, this should be Rule #1, since everybody who's ever done
anything at all knows how large the idiot population really is.


While I agree 100% with you on this, this exercise was never meant to be a production item.  It was meant as something for Nick to try out as a short term experiment.

To make a short story long, back in the early eighties I ran a small company that wrote software for DEC PDP-11 mini-computers.  We had just finished a self maintaining parts/sales/service/accounting package for motorcycle and power equipment dealerships.  One of the things we were most proud of was the UI.  We had tested that to within a inch of it's life with every imaginable input scenario.  It was rock solid and it had the capacity to learn.  To reduce the error rate it would analyze the data being input and compare it to what had already been input and verified and suggest auto-completion hints.  It really was an achievement.  We even had one of a largest customers do beta, release and acceptance testing for 3 months.  We did further acceptance testing with 3 additional clients.  Everyone was impressed.  It improved data entry speed and accuracy by huge amounts.

Shortly after we had put it into full time use at all our customer sites, I took a trip out to see how things were going at our biggest site.  I was talking to the accountant about his impressions under actual use conditions and he told me that things were never better.  He even told me that he figured out how to run the general journal batch update instantaneously!  I was quite surprised at this as it would normally take about 5 minutes to back everything up, do a referential integrity check on the input data tables, commit all the transactions, run all the report transactions and get ready for the month-end adjustments.  So I asked him how he did that.  So he told me.  "Just after selecting 'Update' from the menu I just hit the 'ctrl' key and the 'c' together.  Then it flashes "Finished" for a second and returns to the main menu."

It turns out that there was about 10 seconds while the jobs were being submitted to the batch queue that it would accept a ctrl-C and abort the control file.  He was essentially just quitting the process before it even got started.  No one had imagined that scenario.  No one even knew that the ctrl-C trap was being disabled during that short process.  When we asked how he figured this out, all he could tell us was that he found it by accident.  Luckily is was an accumulative procedure, and could be run as many times as you liked ... as long as it was run at least once before month end.  We had to rewrite the UI to all disable input for that 10 seconds.

There is always a more ingenious idiot.