Arduino Forum

Using Arduino => Audio => Topic started by: s3n4te on Feb 28, 2011, 10:15 pm

Title: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: s3n4te on Feb 28, 2011, 10:15 pm
Hi,

I was wondering if the circuit below will be able to drive a 0.2 W speaker?

(http://i.imgur.com/F0NAs.jpg)

The capacitor is used to remove the DC offset from the PWM output, and the voltage divider is used to reduce the vpp to 1 V. The 10 kOhm resistor is to reduce current to the OPAMP, and 20 kOHM is to multply the input by 2 so that the output wil be 2 V peak to peak. The transistors in the feedback loop helps to supply the required 125 mA to the speaker.

I don't have an scope to test this out, so I'm wondering if someone can verify that this circuit will not blow up.

Thanks,
s3n4te


Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: retrolefty on Feb 28, 2011, 11:04 pm
Looks like it will function OK to me. I would use a audio taper pot on the input signal to give one a volume control. Keep in mind that there will be some 'cross-over' distortion in your output when the signal passes through 0vdc and neither transistors are conducting. 'Hi-Fi' class A/B amps usually apply a little dc bias such the both transistors are conducting a few milliamps with zero signal so that there is a smooth transistion between positive and negative cross-over. However as you are feeding this amp stage square waves anyway it's not like you won't have terrible odd order harmonic distortion anyway. Now if you did some low-pass filtering before the input stage and fixed the cross-over bias you might get musical quality tones through the thing.

Lefty

Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: s3n4te on Mar 01, 2011, 12:53 am
Would feedback cause the output to compensate for deadzone problem?
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: retrolefty on Mar 01, 2011, 01:01 am

Would feedback cause the output to compensate for deadzone problem?


No. Recall your transistor basics. The emitter/base junction will only conduct when the applied voltage is greater then around .6vdc, so there is a time while the signal is moving from 0 to .6v that the transistor can't conduct. This is the source of the so called cross-over problem as one transistor stops conducting and the other starts conducting.

Any basic description/drawing of class AB amplifiers will explain the DC bias set-up where neither transistor is allowed to completely turn off no matter what the signal value is. In essence the amplifier runs in class A (at a low continuous current flow) until the signal is high enough to 'take control' of the conduction transistor and so enters class B operation.

Lefty
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: Grumpy_Mike on Mar 01, 2011, 01:08 am
Why have you drawn 12v batteries all over the place?
You just need a +12 rail and a -12v rail.
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: s3n4te on Mar 01, 2011, 01:40 am
I understand why there is distortion if there is no opamp there, but not when there is an opamp with the output is connected back to inverting input of the opamp. The output would always equal to the input * gain no matter if the transistors off when input is -0.7 -- +0.7V? Is this correct?

Edit: I did a Fourier analysis at the output with 10khz sine wave, and the THD is only 1.3%.
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: retrolefty on Mar 01, 2011, 01:51 am

I understand why there is distortion if there is no opamp there, but not when there is an opamp with the output is connected back to inverting input of the opamp. The output would always equal to the input * gain no matter if the transistors off when input is -0.7 -- +0.7V? Is this correct?


Yes the opamp feedback circuit will try and correct the situation, but then the output of the amp isn't the real reflection of the input signal (+ gain) for short period of time around zero input signal. It causes a 'notching effect' at zero crossing that is easily seen on a scope and can be heard if one knows what to listen for. Again just read up on basic audio amplifier circuits using discrete components and you will learn all there is to know about the subject.

Modern IC audio amplifier chips do the same thing inside to eliminate the problem. Again this is a classic problem for any amplifier using bipolar voltage push-pull output stage, which allows DC coupling to the speaker. A single ended amp stage does not have this problem, but are very inefficient running in continuous class A operation (50% current flow with zero audio signal) and have to be capacitance coupled to the speaker.

Lefty
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: s3n4te on Mar 01, 2011, 02:35 am
If I add active low pass filter would that cause my output wave to be triangular?
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: retrolefty on Mar 01, 2011, 02:41 am

If I add active low pass filter would that cause my output wave to be triangular?


Not for frequencies below the cutoff design frequency of the filter. Not sure how you are processing audio information via PWM output. Is this using some kind of PCM signal? Or are you just ramping up and down the PWM duty cycle using a audio sine wave table?

It's hard to design an effective filter unless one knows the signal format being used.

Lefty
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: retrolefty on Mar 01, 2011, 02:50 am

Quote
the output of the amp isn't the real reflection of the input signal (+ gain) for short period of time around zero input signal. It causes a 'notching effect' at zero crossing that is easily seen on a scope and can be heard if one knows what to listen for. Again


Absolutely true. However, if s3n4te is only listening to square waves out of an Arduino, he probably won't even notice it.

I told him that.  

Not clear why one would string all those discrete components together to make a low-power amplifier when you can get an LM386 for less than the price of a pack of chewing gum?

Maybe he is trying to learn how to design audio circuits, it's still an honorable task. The 'golden ear' audiophiles still frown on using opamps or ICs in general in their megabucks systems, go figure.

PS: In his circuit he is taking the feedback signal not from the opamp output, but rather right from the speaker output tap, which is common for such audio amps.

 
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: stimmer on Mar 01, 2011, 03:42 am
You can improve the crossover distortion by trying to keep the transistors biased. Try adding a few resistors as shown to see if it improves things. You will need to experiment with the exact values, that's half the fun of building amplifiers.
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: s3n4te on Mar 01, 2011, 03:43 am
Okay after taking your recommendations, I have adjusted the circuit to resemble this:

(http://i.imgur.com/9DOMY.jpg)

The diodes are to provide the dc bias to prevent crossover distortion, the pot for volume control, and 22pF cap for active low pass filter. What do you guys think?
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: Vanyamba on Mar 01, 2011, 03:58 am
I am using the following scheme:
(http://sites.google.com/site/vanyambauseslinux/_/rsrc/1298081054520/electronics/arduino-generator-signalov/fast-pwm-sound2.png?height=196&width=400)
http://sites.google.com/site/vanyambauseslinux/_/rsrc/1298081054520/electronics/arduino-generator-signalov/fast-pwm-sound2.png (http://sites.google.com/site/vanyambauseslinux/_/rsrc/1298081054520/electronics/arduino-generator-signalov/fast-pwm-sound2.png)
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: retrolefty on Mar 01, 2011, 05:17 am
Quote
What do you guys think?


Yea, dump the 1k and 4k resistors, just wire the pot's wiper to the 10k resistor.

Time to melt some solder?
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: retrolefty on Mar 01, 2011, 05:20 am

I am using the following scheme:
(http://sites.google.com/site/vanyambauseslinux/_/rsrc/1298081054520/electronics/arduino-generator-signalov/fast-pwm-sound2.png?height=196&width=400)
http://sites.google.com/site/vanyambauseslinux/_/rsrc/1298081054520/electronics/arduino-generator-signalov/fast-pwm-sound2.png (http://sites.google.com/site/vanyambauseslinux/_/rsrc/1298081054520/electronics/arduino-generator-signalov/fast-pwm-sound2.png)


That's a rather Lo-Fi approch, but with square wave input who cares, it will make noise.  ;)
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: Vanyamba on Mar 01, 2011, 10:27 am

That's a rather Lo-Fi approch, but with square wave input who cares, it will make noise.  ;)


Transistor is good noise filter.
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: Vanyamba on Mar 01, 2011, 05:44 pm

Not really.  In fact it is more often the opposite.


In order to switch a bipolar transistor, some amount of current required, isn't it?
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: Vanyamba on Mar 01, 2011, 06:51 pm

Yes. And every active component (and many passive components) are all sources of noise and/or distortion.


Sounds a bit paranoidal.  :)
"This is my HiFiduino, baby." (c)
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: s3n4te on Mar 03, 2011, 08:36 pm
Okay I built the circuit, and the wonderful smell of magic smoke started to come out both bjts after decreasing resistance in the pot to 0 (I had to replace both). By the way, I kept the 4k and 1k voltage divider in the circuit. How do I calculate the power dissaption of the bjts in this type of circuit?
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: CrossRoads on Mar 03, 2011, 08:53 pm
Okay, here is a more appropriate circuit.

The MOSFET I used is IRF3707Z, any higher current logic level MOSFTETwill work, such as the sparkfun sells.
The speaker is from mpa.com
http://www.mpja.com/prodinfo.asp?number=14618+SP
90dB. I use it in a fencing club to make a warble when a touch is scored, can be heard very well.

The current thru your BJT is (Vsource - Vce)/(sum of resistance in the rest of the path)

So (5V-0.5v)/(8ohm+pot)
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: s3n4te on Mar 03, 2011, 09:00 pm
I think I figured it out, since with 0 ohms at the pot, the voltage output of the opamp would be 1V, which means 12 - 1 = 11V must be dropped across the bjt. 1V/8ohms = 0.125 A ----> power disipation of bjt = 11V*0.125A = 1.375W > 0.6 W max of the transistor. Is this correct?
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: CrossRoads on Mar 03, 2011, 09:07 pm
Which circuit do you have wired up? There have been several posted.
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: s3n4te on Mar 03, 2011, 09:08 pm
This one:

(http://i.imgur.com/9DOMY.jpg)
Title: Re: Is this an appropriate circuit to drive my 8 ohm speaker using PWM?
Post by: CrossRoads on Mar 03, 2011, 09:21 pm
Yes, for full on (12V - Vce)/8 = ~1.44 amp.
P=I^2R = 16W goin thru the speaker
P= IV = ~0.5*1.44 = 720mW dissipating in the transistor.

2N4401 absolute max 600mA - 1.44A would smoke 'em!