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.
oric_dan:
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.
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?
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:
// 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};
// 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);
}
Krupski:
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:
0.33 uF capacitor added instead of the 2.2K resistor:
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.
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:
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.
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...
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.
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.
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?