sound circuit resistor

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Hi All

Attached is a little circuit I will be workin on this weekend...

On the right side of the circuit is a resistor 'R2: 22-220 ohm' meaning that a resistor value between 22 - 220 ohm needs to be chosen in order to not pass very high a sound level into my speaker. The resistor will be connected to a PWM channel.

The speaker I am using has the following specs: max.0.2W, 8ohm!

Any help in choosing the appropriate value of the resistor will be appreciated!

Thanks!
 

Attachments

#12

Joined Nov 30, 2010
18,224
So, what's that box? Personal Computer? PIC microcontroller? Power Contributor? Phase Circuitry?

The way it's drawn, it has zero volts to work with so the resistance doesn't matter. Zero volts divided by any resistance = 0 watts.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
It a PIC microcontroller!

the left side of the box is a potentiometer that will be connected to ADC
the right side of the box (PIC mcu) PWM channel!
 

#12

Joined Nov 30, 2010
18,224
Assuming a PIC uses 5 volts as a supply and you are outputting a sine wave, you would need 3.18 ohms to protect the speaker...if that's what you're trying to protect. If there is a limit on the current a PIC can output, and that is what you are trying to protect, that is another matter.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Assuming a PIC uses 5 volts as a supply and you are outputting a sine wave, you would need 3.18 ohms to protect the speaker...if that's what you're trying to protect. If there is a limit on the current a PIC can output, and that is what you are trying to protect, that is another matter.
Thanks for your reply!

PWM will output a square wave...

the resistor to be chosen is between 22 and 220 ohm and says it is needed in order to *not pass too high a sound level into your speaker* (I gave my speaker specs in OP).

I am not too sure sure what it means myself! but by the look of things (diagram) what is that *resistor* for?

thanks!
 

#12

Joined Nov 30, 2010
18,224
The way I calculated it, the speaker does not have enough wattage capability to survive a sine wave you can make out of 5 volts, in the long run...so 3 point sumthin' ohms will cure that.

A square wave contains twice the power of a sine wave so the math is wrong.

Now you need at least 14.36 ohms to protect the speaker. If you have a 15 ohm, 1 watt, 1% resistor, use that. If not, use a 22 ohm, 1 watt, whatever tolerance, resistor.
 

Audioguru

Joined Dec 20, 2007
11,248
It must be a very cheap tiny speaker since it is rated for only 0.2W. An earphone?
If the resistor is 15 ohms and the speaker is 8 ohms then the load on the PWM circuit is only 23 ohms. A PIC cannot drive such a low impedance.

If the PIC is driving a power amplifier with zero output impedance then the 10uF capacitor into the 23 ohms load causes a loss of frequencies below 696Hz.
 

Audioguru

Joined Dec 20, 2007
11,248
I kind of hinted at that but still don't know the current limit for a PIC.
The maximum allowed output current of a PIC is 25mA peak. It will have a voltage drop.

A PIC might produce 4V p-p when the peak current is 25mA. Then the minimum load impedance is 2V peak/25mA peak= 80 ohms.
The peak power into 80 ohms is 50mW and the RMS power is 25mW which is almost nothing.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
@Audioguru: Thanks for your reply Sir!

So if I got you right, your suggested resistance value is 80 Ohms, right? as you have in post #10.

Just a curious question, what would happen for instance if one chooses 220 ohm?

thanks again!
 

#12

Joined Nov 30, 2010
18,224
The power supplied to the speaker will diminish according to Ohm's Law (V=IR)and Watt's Law (P=IE). The DC blocking capacitor mentioned in post #8 will have a lower frequency limit as derived from Xc=1/(2 Pi F C)
 

Audioguru

Joined Dec 20, 2007
11,248
Not only is the output power reduced because the total load resistance is high, but the resistor in series with the speaker forms a voltage divider.

The PIC output might be 4.5V p-p into 228 ohms which is a total power of 0.022W but the 8 ohm speaker will produce only 0.00078W.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Here's what I am trying to acheive:

Generating a continous sound that varies between two frequencies by varying the voltage (0V to 5V) on the ADC channel using a potentionmeter. The PWM will generate that sound!

I don't need no code (can do it myself!) but rather a right approach to solve the problem.

Here's what I have in mind:

Given a 10bit ADC resolution, we have the following:

Assuming the two limit frequencies are 200Hz - 3000Hz

0V -> 0 (ADC value) -> 200Hz
5V -> 1023 (ADC value) -> 3000Hz

I think there should be some kind of mapping between ADC values and frequencies, correct?

Varying the frequency would result in different sounds but continuous!

My first concern is how many different sounds would be reasonable to have? so I can do set a number of frequencies between the limits!

Am I also correct to say that a certain range of ADC value must correspond to a specific frequency!?

for instance, 0 - 30 (ADC) -> 200 Hz
31 -61 (ADC) -> X Hz
.....

Maybe I don't even have to have equal interval frequencies, huh?

Any comments would be appreciated!:)
 
Last edited:

Audioguru

Joined Dec 20, 2007
11,248
Usually the carrier frequency of a PWM circuit does not change. The modulation frequency is changed to vary the audio frequency. The PWM can also vary the loudness.

Your cheap tiny speaker might not produce a frequency as low as 200Hz and might not produce a frequency as high as 2kHz.

Some people are not interested in music because to them a low frequency sounds the same as a high frequency.

What is your waveshape?
A square-wave sounds like a buzzer, a triangle-wave sounds something like a violin and a sine-wave sounds something like a flute.
The attach and decay times determine what instrument produces the waveform.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Usually the carrier frequency of a PWM circuit does not change. The modulation frequency is changed to vary the audio frequency. The PWM can also vary the loudness.

Your cheap tiny speaker might not produce a frequency as low as 200Hz and might not produce a frequency as high as 2kHz.

Some people are not interested in music because to them a low frequency sounds the same as a high frequency.

What is your waveshape?
A square-wave sounds like a buzzer, a triangle-wave sounds something like a violin and a sine-wave sounds something like a flute.
The attach and decay times determine what instrument produces the waveform.

Thanks Sir for your reply!

my waveshape is a square-wave! I must have frequencies between those two values!! so how to solve this problem? changing the speaker or that R2 resistor?

Also I think I will ignore the 2 Msbs in the result of the ADC and just use the 8 LSBs to make things simpler when mapping ADC results to frequencies...
 

Markd77

Joined Sep 7, 2009
2,806
The frequency of the PWM module isn't 10 bit, it's a bit more complicated than that.
The duty cycle is up to 10 bits, but that isn't important.
The period (1/frequency) is a combination of the PR2 register which is 8 bits and the prescaler which is either 1, 4 or 16 (other PICs may vary, I looked at the 16F819 datasheet). Working with the PWM module gives me a bit of a headache. Try making a spreadsheet with the available frequencies. You will find that they aren't evenly spaced and a lot of them are higher than you want. If your highest frequency is only 3000Hz, you can get a decent range of frequencies just in code without bothering the PWM module, you get 166 instruction cycles in each half of the period at 3000Hz with a 4MHz PIC.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
The frequency of the PWM module isn't 10 bit, it's a bit more complicated than that.
The duty cycle is up to 10 bits, but that isn't important.
The period (1/frequency) is a combination of the PR2 register which is 8 bits and the prescaler which is either 1, 4 or 16 (other PICs may vary, I looked at the 16F819 datasheet). Working with the PWM module gives me a bit of a headache. Try making a spreadsheet with the available frequencies. You will find that they aren't evenly spaced and a lot of them are higher than you want. If your highest frequency is only 3000Hz, you can get a decent range of frequencies just in code without bothering the PWM module, you get 166 instruction cycles in each half of the period at 3000Hz with a 4MHz PIC.

Thanks Sir for your reply...

I made a huge mistake when typing...I actually meant *10 bit ADC* :) sorry for the confusion!

I will only consider the 8 bit Lsbs of the ADC result...Yes sound frequencies are Not evenly spaced as shown in the above link...

I will make 32 different sounds...

ADC result from:

0 - 7 will correspond to 200Hz
8 - 15 -> ...
16 - 23 -> ...

....

Then instead of comparing ACD result with 32 values (ie from 0 - 7 to 248 - 255) and using a 'cpfslt f' which is an instruction that does not exist in PIC16F ...can create it t will make code unnecessary complicated and will use too many instruction cycle...

what i will do is have a table with 256 entries, ie table index values will the the same for 8 entries...ie 0-7, 8 -15, ....so I will use the ADC result as index and have the table return a value corresponding to the frequency 'PR2' and fed it to wherever I have to feed it to for square wave output...

I will cooksome code and present it to the big boy in case I run into a problem...but I dont think so...maybe with ADC 'acquisition time'...but I'll see

Thanks and comments are always welcomed:)
 
Top