Searching \ for '[EE]: PWM for volume control' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/io/pwm/index.htm?key=pwm
Search entire site for: 'PWM for volume control'.

Exact match. Not showing close matches.
PICList Thread
'[EE]: PWM for volume control'
2005\05\06@151951 by Hector Martin

flavicon
face
Hi all,

I'm trying to control the PC speaker (motherboard beeps etc) volume
using PWM (software-driven PWM from a PIC) but I'm not really sure now
to design the circuit.

Since the PC speaker is just a squarewave output (unless I'm terribly
mistaken) I thought about feeding the PWM into a pair of transistors
to charge/discharge a capacitor (to smooth out the PWM) and then
connect the PC speaker signal to a transistor that turns the output on
or off, using the capacitor as power source. Does this sound OK or is
there some obvious better way of doing it? Maybe using two
transistors, one taking input from the sound input and one from the
smoothed out PWM (plus a pot to control the volume range) all running
from the main power bus? (that way changes in the sound signal
shouldn't vary the load on the capacitor and thus the volume)

Regards,
--
Hector Martin (spam_OUThectorTakeThisOuTspammarcansoft.com)
Public Key: http://www.marcansoft.com/hector.asc

2005\05\07@084809 by Gerhard Fiedler

picon face
Hector Martin wrote:

> I'm trying to control the PC speaker (motherboard beeps etc) volume using
> PWM (software-driven PWM from a PIC) but I'm not really sure now to
> design the circuit.

I'm not sure about using PWM for controlling audio volume in general. Most
PWM frequencies are within the audio range, and you'd need to do some good
filtering to get rid of this unwanted artefact in the output. Maybe in the
case of the PC speaker this is less of a problem, but maybe not. The ear is
pretty good in hearing those things over several decades.

What's your overall objective? Does it have to be PWM? If you just want to
manually control it, a simple pot would be enough :) If you want to be able
to do electronic control, some kind of multiplying DAC could do it. That
can be as simple as a bunch of resistors that form a 5 bit divider (which
should be enough steps). Depending on how you want to control it, it may
not even have to be a PIC -- an up/down counter for example could do it.

Gerhard

2005\05\07@093708 by Hector Martin

flavicon
face
Gerhard Fiedler wrote:
> I'm not sure about using PWM for controlling audio volume in general. Most
> PWM frequencies are within the audio range, and you'd need to do some good
> filtering to get rid of this unwanted artefact in the output. Maybe in the
> case of the PC speaker this is less of a problem, but maybe not. The ear is
> pretty good in hearing those things over several decades.

Yeah, of course I need to have decent filtering so that the signal is
not audible (or barely audible, since when the PC speaker is beeping a
very weak PWM tone would not be noticeable, and the tone would be off
when the speaker is idle).

>
> What's your overall objective? Does it have to be PWM? If you just want to
> manually control it, a simple pot would be enough :) If you want to be able
> to do electronic control, some kind of multiplying DAC could do it. That
> can be as simple as a bunch of resistors that form a 5 bit divider (which
> should be enough steps). Depending on how you want to control it, it may
> not even have to be a PIC -- an up/down counter for example could do it.

Of course I want to use do electronic control ;) A multiplying DAC is
a good solution, but I do not want to add much complexity to the
circuit (besides, I'm already running out of PIC pins for other
stuff). I think this really should use an easier solution, since the
PC speaker sound is binary sound only. It really should be something
like using PWM to generate an analog voltage and then modulate it
according to the PC speaker input, simpler than a full-blown
multiplying DAC. So, really, it boils down to three points:

1. Smoothing out PWM to a decent analog voltage
2. Modulating that voltage on/off according to the PC speaker input
3. Amplifying the whole thing


--
Hector Martin (.....hectorKILLspamspam@spam@marcansoft.com)
Public Key: http://www.marcansoft.com/hector.asc

2005\05\07@095019 by Russell McMahon

face
flavicon
face
>> I'm trying to control the PC speaker (motherboard beeps etc) volume
>> using
>> PWM (software-driven PWM from a PIC) but I'm not really sure now to
>> design the circuit.

Given PWM of a high enough frequency (20 kHz plus frame rate) you
should be able to simply gate the audio signal with the PWM OR ground
it if the supplying impedance is high enough. You will need some sot
of electronic switching - quite possibly a single FET would do. If
speaker is AC coupled it will be slightly more complex. Assume for
simplicity that speaker is DC coupled and driven by a signal never
below ground. A FET in the speaker ground lead could be gated by the
PWM signal. A flyback diode would probably be needed across the
speaker in series with a diode to *attempt* not to modify audio
response too much. It would be easier if you could control the signal
level at lower level and then amplify it for the speaker but that
wrecks the simplicity.

See what sense you can make of that and ask more questions.

       RM

2005\05\07@101525 by Russell McMahon

face
flavicon
face
> 1. Smoothing out PWM to a decent analog voltage
> 2. Modulating that voltage on/off according to the PC speaker input
> 3. Amplifying the whole thing

If you don't mind post amplification it's easy.

Provide audio source never below ground.
Pass through a resistor - say 10k.
Chop output of resistor to ground with 1 transistor driven by PWM.
Feed resistor output (reduced in amplitude by PWM duty cycle) to a
suitable filter (possibly a single R and C and thence to amplifier.
The amplifier could be a single transistor and could be part of an
active low pass filter with gain.
If you can afford to use an op amp section or a few here it becomes
extremely easy to do reasonably well.
An LM358 (dual) or LM324 (quad) would suffice.

If you have two PIC pins available and spare processing power you
could feed tone to one pin. and out put PWM multiplied output from
other pin.


       RM




2005\05\07@103956 by Hector Martin

flavicon
face
Russell McMahon wrote:
> Given PWM of a high enough frequency (20 kHz plus frame rate) you should
> be able to simply gate the audio signal with the PWM OR ground it if the
> supplying impedance is high enough. You will need some sot of electronic
> switching - quite possibly a single FET would do. If speaker is AC
> coupled it will be slightly more complex. Assume for simplicity that
> speaker is DC coupled and driven by a signal never below ground. A FET
> in the speaker ground lead could be gated by the PWM signal. A flyback
> diode would probably be needed across the speaker in series with a diode
> to *attempt* not to modify audio response too much. It would be easier
> if you could control the signal level at lower level and then amplify it
> for the speaker but that wrecks the simplicity.
>
> See what sense you can make of that and ask more questions.
>
>        RM

Actually, the frequencies coming out of the speaker rarely exceed
2Khz, so I could even use a lower PWM freq and add a lowpass filter.
But I'm not sure how fast I can push the PWM, since I don't want it
taking too much software time. Anyways I *do* want an amplifier in
there anyway. "Too complicated" would be DACs and stuff, but I don't
mind some transistors in there. Currently I'm using an optocoupler as
a substitute for the speaker for input (I don't trust how the computer
generates output, common ground, common positive, whatever, so an opto
makes sense here), so I can do whatever I want with its output
photodiode/transistor. I've amplified it with a simple BC547
transistor and a pot to (manually) control volume and it works quite
well (although I need a larger transistor, since at higher volumes the
BC547 gets quite warm). Now all I really need to do is replace the pot
with another transistor, something like this:


+12V --------------------+------------------+-------
                 OPTO   |                  |
  +------------+        |                  |   _ /|
  |           _|_     |/C                  +--| | |
INPUT         /_\ --> |               --------|_| |
  |            |      |\E           |/C          \|
  +--\/\/\/----+        --/\/\/\-+--|
                                 |  |\E
                               |/C    |
    FILTERED PWM INPUT >-------|      |
                               |\E    |
GND ------------------------------+----+------------

(this would of course be an inverted configuration, where a higher PWM
input would mean lower volume, but of course that just means a change
in the software)

But, of course, I either need a filtered mostly clean voltage, or a
very high rate PWM (which I'm not sure I can afford). How clean can
you get with some R-C filters?

--
Hector Martin (hectorspamKILLspammarcansoft.com)
Public Key: http://www.marcansoft.com/hector.asc

2005\05\07@110552 by Bill & Pookie

picon face
I think you are making this way to complicated.  To the best of my
knowledge, the speaker is controlled by a single bit and a square wave is
sent to it to produce the tones.

The speaker has a limited response and the volume will start decreasing at
some higher frequency as the mechanical parts of the speaker can only move
so fast.  By decreasing the on time of the input to speaker you will
effectively be increasing the frequency that the speaker responds to, and at
some point the volume should start decreasing.

So by knowing what on pulse time produces full volume and what on pulse
width produces no sound, you can control volume with the on pulse width
while keeping the original frequency.

Bill
{Original Message removed}

2005\05\07@112735 by Hector Martin

flavicon
face
Bill & Pookie wrote:
> I think you are making this way to complicated.  To the best of my
> knowledge, the speaker is controlled by a single bit and a square wave is
> sent to it to produce the tones.
>
> The speaker has a limited response and the volume will start decreasing at
> some higher frequency as the mechanical parts of the speaker can only move
> so fast.  By decreasing the on time of the input to speaker you will
> effectively be increasing the frequency that the speaker responds to, and at
> some point the volume should start decreasing.
>
> So by knowing what on pulse time produces full volume and what on pulse
> width produces no sound, you can control volume with the on pulse width
> while keeping the original frequency.
>
> Bill

Of course, but I have no control over the generated signal for the
speaker. I just want to post-process it to vary the volume. Plus the
difference in (sound) pulse width would become noticeable many times.

--
Hector Martin (.....hectorKILLspamspam.....marcansoft.com)
Public Key: http://www.marcansoft.com/hector.asc

2005\05\07@113808 by Russell McMahon

face
flavicon
face
>> Given PWM of a high enough frequency (20 kHz plus frame rate) you should
>> be able to simply gate the audio signal with the PWM OR ground it if the
>> supplying impedance is high enough.

> Actually, the frequencies coming out of the speaker rarely exceed
> 2Khz, so I could even use a lower PWM freq and add a lowpass filter.
> But I'm not sure how fast I can push the PWM, since I don't want it
> taking too much software time.

> Now all I really need to do is replace the pot
> with another transistor, something like this:

That's exactly what I meant - just needs some "fine tuning".

Input bias needs work.

If you use a resistor load for the output transistor you can AC couple the
speaker and avoid the DC in the speaker coil which does no good to speaker
or transistor.

{Quote hidden}

PWM does not need to be too many bits effectively probably. I'd say 4 bits /
16 steps would do depending on application. If you ran this at say 10 kHz
with filtering the bit rate = 1/10kHz x 1/16 =~ 6 uS. A 6 uS IRQ would allow
simple PWM in software. This may be easy or crippling depending on
processorspeed.

> How clean can
> you get with some R-C filters?

Filters provide 20 dB/decade/pole roll off. Pure RC filters can not have
enough Q to be universally useful. You can make a 2 or 3 poe low pass with a
single transistor in an emitter follower configuration. 3 poles gives 60 dB
at 1 decade. For 2 kHz audio you'd need 20 kHz PWM for 60 dB filtering (or
is that 40 - no backs of envelopes to hand :-) ). Two stages of filtergives
4 or 5 poles - sensible upper limit for this technology.

An easier approach may be a voltage controlled attenuator where slow speed
PWM is turned into a DC control voltage.

If you have never met a diode switch/attenuator you're in for some fun. Two
diodes say cathode to cathode with positive feed via R's to each anode and a
common R from centrepoint to ground. When diodes are DC on AC will pass
through the two in series (magic ;-) ). As the R to ground is increased
attentuation rises. provide this bias voltage with PWM.

Google on diode switch.


       RM





>
> --
> Hector Martin (EraseMEhectorspam_OUTspamTakeThisOuTmarcansoft.com)
> Public Key: http://www.marcansoft.com/hector.asc
>
> --

2005\05\07@125751 by Hector Martin

flavicon
face
Russell McMahon wrote:
> That's exactly what I meant - just needs some "fine tuning".
>
> Input bias needs work.
>
> If you use a resistor load for the output transistor you can AC couple the
> speaker and avoid the DC in the speaker coil which does no good to speaker
> or transistor.
>

True. I was wondering why AC coupling it wasn't working -- of course I
need a load R. 220ohm/ 1uF is working OK (the resistor gets warm, but
nothing to worry about)

>
>> But, of course, I either need a filtered mostly clean voltage, or a
>> very high rate PWM (which I'm not sure I can afford).
>
> PWM does not need to be too many bits effectively probably. I'd say 4 bits /
> 16 steps would do depending on application. If you ran this at say 10 kHz
> with filtering the bit rate = 1/10kHz x 1/16 =~ 6 uS. A 6 uS IRQ would allow
> simple PWM in software. This may be easy or crippling depending on
> processorspeed.
>
6us looks too low to me. Say I run the PIC at 20Mhz, that would mean a
0.2us instruction cycle, which means 6us would be 30 instructions.
Taking into account the interrupt register save/load stuff and the PWM
loop, and checking for other interrupts (I'd need other stuff running
at a multiple of that period), 30 cycles is too low, and it has to
give some time for the main program to run. 16 steps is fine, but not
less.

>> How clean can
>> you get with some R-C filters?
>
> Filters provide 20 dB/decade/pole roll off. Pure RC filters can not have
> enough Q to be universally useful. You can make a 2 or 3 poe low pass with a
> single transistor in an emitter follower configuration. 3 poles gives 60 dB
> at 1 decade. For 2 kHz audio you'd need 20 kHz PWM for 60 dB filtering (or
> is that 40 - no backs of envelopes to hand :-) ). Two stages of filtergives
> 4 or 5 poles - sensible upper limit for this technology.

OK, here is where I get lost with the numbers :P

>
> An easier approach may be a voltage controlled attenuator where slow speed
> PWM is turned into a DC control voltage.

This is what I want, isn't it?

If I got this right you were (in the previous paragraph) referring to
adding a filter *after* the circuit, to the output. But wouldn't it be
easier to filter PWM and then feed the DC control voltage to the
circuit (base of the controlling transistor)? This is what I was
thinking about actually. How can I make PWM into a (clean) DC voltage?

>
> If you have never met a diode switch/attenuator you're in for some fun. Two
> diodes say cathode to cathode with positive feed via R's to each anode and a
> common R from centrepoint to ground. When diodes are DC on AC will pass
> through the two in series (magic ;-) ). As the R to ground is increased
> attentuation rises. provide this bias voltage with PWM.
>
> Google on diode switch.
>

The closest I've found to what you mention is:
users.ece.gatech.edu/~mleach/ece3050/NewNotes/chap02.pdf
(last page).

Interesting idea... I'll give it a try.

--
Hector Martin (hectorspamspam_OUTmarcansoft.com)
Public Key: http://www.marcansoft.com/hector.asc

2005\05\07@130055 by Hector Martin

flavicon
face
But then, come to think of it, if the audio is  binary (which it is),
isn't it easier to just gate the DC voltage from the smoothed out PWM
using the audio signal, instead of attenuating the audio signal?

--
Hector Martin (@spam@hectorKILLspamspammarcansoft.com)
Public Key: http://www.marcansoft.com/hector.asc

2005\05\07@131058 by Peter

picon face

Think of the PC speaker as a device attached between +Vcc (usually 5V
but it can be 3V) and a switch that grounds it periodically (the chipset
output). Now if you make a programmable small value resistor and attach
it between +Vcc and the speaker wire that was previously connected to
+Vcc you have volume control. The resistor can be a PNP/PNP current
mirror for example, controlled by a microprocessor. That should work
nicely (excepting for the P=R*I^2 law which you must turn into a log law
to satisfy human requirements for volume control - for example using a
lookup table). Maximum expected current is 0.6A which is in range for
almost all simple low power transistors.

hope this helps,
Peter

2005\05\07@142047 by Peter

picon face

Otherwise: why not use pure software pwm which can be oversampled or
mixed with noise etc to generate any volume you like (within reason).
Windows and Linux both have 'speaker' sound drivers which use the
speaker to output (low quality) music and even speech.

Peter



2005\05\07@145837 by Andre Abelian

picon face
Hi to all,

Remove the opto-coupler and connect your audio directly and
use pwm thru opto resister to change the resistance this will
lower the volume.
If you do not have opto resister make one take small tube
one side add led and the other side photo resister.

Andre Abelian  






{Original Message removed}

2005\05\07@160046 by Hector Martin

flavicon
face
Andre Abelian wrote:
> Hi to all,
>
> Remove the opto-coupler and connect your audio directly and
> use pwm thru opto resister to change the resistance this will
> lower the volume.
> If you do not have opto resister make one take small tube
> one side add led and the other side photo resister.
>


But I also want to *amplify* the sound, not just attenuate the
existing volume (which is pretty low)

--
Hector Martin (KILLspamhectorKILLspamspammarcansoft.com)
Public Key: http://www.marcansoft.com/hector.asc

2005\05\07@160819 by Hector Martin

flavicon
face
Peter wrote:
>
> Otherwise: why not use pure software pwm which can be oversampled or
> mixed with noise etc to generate any volume you like (within reason).
> Windows and Linux both have 'speaker' sound drivers which use the
> speaker to output (low quality) music and even speech.
>

well, software PWM depends on the main CPU and wastes precious cycles.
Besides, I'd like this to work for standard beeps, e.g. BIOS POST
beeps and similar stuff. And I need an amplifier anyway (because I
want higher maximum volume), but I might not want BIOS POST beeps and
standard beeps to sound at max volume the whole time.

And I'm not too sure if the software PWM driver will get along with
the CPU on-the-fly speed changing (cpufreq powernow-k8)


--
Hector Martin (RemoveMEhectorTakeThisOuTspammarcansoft.com)
Public Key: http://www.marcansoft.com/hector.asc

2005\05\07@181118 by Hector Martin

flavicon
face
Ok, this circuit looks like it is working fine:

+12V ----------------+----------------------+--------
             OPTO   |                 220  |
  +--------+        |              +\/\/\/-+  _ /|
  |       _|_     |/C              |       +-| | |
INPUT     /_\ --> |               -+--| |----|_| |
  |        |      |\E            |/C  1uF       \|
  +-\/\/\/-+        |     E---+--|
      1K            |         |  |\E
                    |         |    ----+
                    |         | 10K    |
                    /     ----+-\/\/\/-+------+
          INPUT POT \   |/E                   |
                10K /<--|      +----PWM INPUT |
                    \   |\C    /              |
                    |     |    \ PWM POT      |
                    |     +--->/              |
                    |          \ 10K          |
GND -----------------+----------+--------------+-----

As you can see, the input signal drives the base of a transistor,
which either turns on or off the PWM signal which is then fed to
another transistor to amplify it for output.

Currently I'm testing with no PWM (haven't got that part ready yet),
so with the input at +12V (and varying the pot). About 0.6V in the pot
center tap is totally off, and about 1.5V is full volume (when the
input pot is adjusted properly, since its setting changes this too),
so I'd have to offset the signal 0.5V and then use the pot to adjust
the range of PWM voltages to that range.

So the only thing left is cleaning up the PWM output to a constant DC
voltage to feed it into the circuit.

--
Hector Martin (spamBeGonehectorspamBeGonespammarcansoft.com)
Public Key: http://www.marcansoft.com/hector.asc

2005\05\07@183219 by Andre Abelian

picon face
Martin,

I am assuming your amp is ready You just need to lower the volume
not amplify. If you like to amplify too then use op amp and put photo
resister as feedback resister.

Andre Abelian




{Original Message removed}

2005\05\08@033922 by Russell McMahon

face
flavicon
face
> But then, come to think of it, if the audio is  binary (which it
> is),
> isn't it easier to just gate the DC voltage from the smoothed out
> PWM
> using the audio signal, instead of attenuating the audio signal?

That's an excellent idea - and is more or less what you have done in
the circuit you subsequently posted.
A capacitor to ground from the wiper of the PWM pot would provide an
adequate filter (see below) as you can make the cutoff frequency as
low as you wish (ie cap as large as needed) to get smooth DC from your
PWM.

If you put a filter cap on the PWM pot output its effect will vary as
the pot wiper moves. By using an output resistor at least as large as
the pot value between pot wiper and switch transistor and placing a
filter cap from the transistor end of this resistor to ground you get
a more constant impedance and filter cutoff frequency.

The present arrangement with the opto gating the pass transistor on is
OK provided you get clean on/off switching at all levels of PWM/DC
control signal. With 12v supply you risk reverse biasing the PNP
switch transistor b-e junction so substantially that some transistors
will break down and make magnificent noise generators. Exact breakdown
varies with parts. Altering the pot (or two resistors in its place so
that it is hard on and hard off will best do what you want - then let
the PWM do the actual volume controlling.

For small values of smoothed PWM to DC the switch transistor is not
going to get enough forward bias to turn on well. As Vc approaches
ground, available Vcb with transistor on will decrease - which causes
the effect you notice.

If you want PWM/DC to go all the way to ground you can replace the PNP
with a small cheap N Channel MOSFET with (IMPORTANT) the drain to the
PWM pot input and source to the amplifier. This will remove the effect
you see now. Put say 100k gate to ground and 10k gate to opto and you
will get hard switching with the PWM doing all the volume control.
Functionally you COULD swap drain and source and the FET would be just
as happy (as, unlike bipolar transistors, they operate in 2 quadrants)
BUT the body diode would conduct when Vpwm rose above about 0.6v.

Using smoothed PWM / DC allows the PWM to operate very slowly indeed.
If you had say a 1 second time constant filter you could use say 100
HZ PWM frame rate = 1600 Hz bit rate for 4 bit PWM. A 1 mS interrupt
would suffice. PWM code is almost trivially easy * and very compact.
This does however drop the PWM bit rate right into the audio band of
interest, but this is unlikely to be an issue given the quality of the
sound source and a filter two decades lower than the PWM frequency.

The amplifier is arguably "a bit naughty" but if it works OK leave it
alone at this stage and work on the above.

I have heard credibly good speech and singing through a PC speaker.
Maybe you can revive a lost art :-)



       RM


*
Inc vPWMCOUNTER
IF vPWMCounter > kPWMMax then vPWMCounter = 0

IF vPWMCOUNTER > vPWMLim then
   bPWMOut = 0
ELSE
   bPWMOut = 1
ENDIF



2005\05\08@093259 by Hector Martin

flavicon
face
Thanks for all your comments :)

I'll be out for a couple days, and make the changes when I come back.

+12V ----------------+----------------------+--------
             OPTO   |                 220  |
  +--------+        |              +\/\/\/-+  _ /|
  |       _|_     |/C              |       +-| | |
INPUT     /_\ --> |               -+--| |----|_| |
  |        |      |\E            |/C  1uF       \|
  +-\/\/\/-+        |         +--|
      1K            |         |  |\E
                    |         |    ----+
                    |         | 10K    |
                    /     ----+-\/\/\/-+------+
          INPUT POT \   |/E                   |
                10K /<--|      +----PWM INPUT |
                    \   |\C    /              |
                    |     |    \ PWM POT      |
                    |     +--->/              |
                    |          \ 10K          |
GND -----------------+----------+--------------+-----

As far as I know all the transistors are NPN (!) (BC547) The circuit
diagram layout is a bit strange, but the idea was for the switch
transistor to allow current to pass from the PWM input to the
amplifier's base (plus a 10K resistor to ground) when the opto
conducted. Have I done something terribly wrong? (Obviously I'm not
too good at analog circuits :-)

--
Hector Martin (TakeThisOuThectorEraseMEspamspam_OUTmarcansoft.com)
Public Key: http://www.marcansoft.com/hector.asc

2005\05\09@030127 by Russell McMahon

face
flavicon
face
{Quote hidden}

No - you are correct that both the transistors should be NPN. Must
have been asleep when I said otherwise ;-)
The failure to turn on when Vpwm-dc is less than about 0.7v is due to
the second transistor base needing that much voltage to be biased on.

As I said, if it works OK for you then fine - but here is a suggested
change which you MAY want to try once you get the basic system
working.

Q1 = 1st transistor
Q2 = 2nd transistor
Call existing 10k = Ra

[Ca]    Electrolytic /10 uF from Q1e to Q2b.
[Rb]    68K to 100k resistor Q2b to +12v
Q2e emitter resistor to ground of 100r [Rc]
Increase 220r somewhat - say 470r to start [Rd]
[Cb]    Electrolytic ?10 uF Q2e to ground.

What this does is provide fixed DC bias for Q2 base using Ra/Rb. Base
is about 1.5v above ground so emitter will be about 1v. 1vish across
Rc forces ~= 10mA collector current.
This also flows in Rd so 10 mA x 470r = 5v drop so Q2c sits at about
6v ish.
Input signal is coupled to Q2b by  Ca so DC level of PWM affects
signal but not dc bias on Q2.

Gain of this stage is about 200 - 300 (don't ask) so signal level
control via PWM pot may need to be lowish.

To reduce gain remove Cb when gain is ABOUT 220R/Rc - or in this case
about 2.
DC current (which helps set power capability) and gain interact
rather.
Having two emitter resistors with a capacitor in series with the lower
of the two allows setting DC  current and gain semi separately.

Now play :-)



       RM

2005\05\09@043235 by Russell McMahon

face
flavicon
face
part 1 1319 bytes content-type:text/plain; (decoded 7bit)

On reflection, you may not need an amplifer per se.
If the speaker signal swing is 5 volts (it may not be) then that is
about 2v RMS and power into a 8 ohm speaker would be about 0.5 watts
IF the source impedance was low. Half a watt is ample for most such
applications. Quite possibly either the source impedance is higher or
there is less than 5v swing.

Either way, try something like the attached.

R!/C1 convert PWM to DC - as before
Q1 is an emitter follower which buffers DC level - effectively a power
amplifier (not voltage).
R2 and Q2 as before. Input to Q2 must gard switch it as shown here.

For extra simplicity remove R2/C2 and put speaker where R2 was. BUT
this places DC in speaker and gets bad as voltage rises.

The emitter follower is the magic bullet here (which may even work
:-) ) as it turns the smoothed PWM voltage into a stiff source which
improves max available power.

A square wave is notionally Vpk/2 RMS equivalent. Regardless of V+ max
PWM-DC is Vin - 0.6 or about 4.4v or 2.2v RMS. Still V^2/R = 0.6 watt
in 8 ohms. R2 needs adjusting to suit notional peak power (play).

Another variant has no C2 and speaker in series with R2. Reduced
power - limits max volume and PWM take over from there.

Let me know if/how it works.


       RM





part 2 1404 bytes content-type:image/gif; (decode)


part 3 35 bytes content-type:text/plain; charset="us-ascii"
(decoded 7bit)

2005\05\09@102910 by Gerhard Fiedler

picon face
Hector Martin wrote:

> Of course I want to use do electronic control ;) A multiplying DAC is a
> good solution, but I do not want to add much complexity to the circuit
> (besides, I'm already running out of PIC pins for other stuff).

A multiplying DAC can be as simple as one resistor per PIC pin plus one
feed resistor. It needs pins, but isn't actually complex.

One thing you may want to keep in mind is that volume control is
approximately logarithmic, so you might have to check that your circuit
handles the lower end of the target range of volume control. With the
resistor DAC method, you can choose the resistors so that you get a
logarithmic curve, whereas PWM is linear.

Gerhard

2005\05\13@164506 by Hector Martin
flavicon
face
I've followed your description:


+12V ----------------+---------+-------------+-------
      OPTO           |         /        470  |
   +--------+        |         \     +\/\/\/-+  _ /|
   |       _|_     |/C     100K/     |       +-| | |
 INPUT     /_\ --> |           \    -+--| |----|_| |
   |        |      |\E         |  |/C   1uF       \|
   +-\/\/\/-+        |         +--|
       1K            |         |  |\E  100
                     |         |    +-\/\/\/---+
                     |         |    |  10uF    |
                     |         |    +---| |----+
                     |         |       10K     |
                     |     +---+------\/\/\/---+
                     |     |                   |
                     |    ---                  |
                     |    ---10uF              |
                     |     |           10K     |
                     /     +----------\/\/\/---+
           INPUT POT \   |/E                   |
                 10K /<--|      +----PWM INPUT |
                     \   |\C    /              |
                     |     |    \ PWM POT      |
                     |     +--->/              |
                     |          \ 10K          |
GND -----------------+----------+--------------+-----

Note the extra 10K from Q1E to GND. I think it is needed there (i.e.
it wasn't working properly without it)

This circuit sounds different, more buzzer-like, because of the
capacitors of course (specifically the 10uF from Q2E to GND; if I
short that one it goes back to the normal tone). I don't care much
about that except that it seems to also lower the volume (apparently,
especially since it kind of drowns out lower freqs).

I'll play with the values and see what I get :-) thanks for the ideas,
now zero volume is zero PWM and full volume is somewhere around 1.5-2V
PWM.



--
Hector Martin (RemoveMEhectorspamTakeThisOuTmarcansoft.com)
Public Key: http://www.marcansoft.com/hector.asc

More... (looser matching)
- Last day of these posts
- In 2005 , 2006 only
- Today
- New search...