Playing WAV using 3W 8Ohm speaker

Hi!

I've tried to playing sounds using this speaker (3W 8Ohm) and everythings looks good if I played only tones (like star wars theme) even if I used pam8403 amplifier.
But when I tried playing music from wav files this speaker it only sounds farting - no music, no voice.

I've tried connection with and without amplifier and with and without 10uF capacitor.

Is this a problem with speaker or I did anything wrong? Please help.

How are you playing WAV files? The regular Arduino doesn't have a DAC, so there's no true-analog output... Are you using the TMRpcm library?

With TMRpcm (which is actually PWM) you need a low-pass filter. Even with a filter some high-frequency PWM can leak-through and do "unknown things" to a power amplifier.

Yep, I'm using TMRpcm library.

I've built some low-pass filter (resistor 33Ohm and 100uF capacitor) - is it a good filter?

I don't know all of the answers... I've never used TMRpcm and I don't know the sample rate or the PWM frequency. I'm not sure what to expect from TMRpcm… I'm pretty sure you can't get "CD quality" or the quality of a good MP3... And, I don't know how sensitive the PAM amplifier is to the PWM signal.

I've built some low-pass filter (resistor 33Ohm and 100uF capacitor) - is it a good filter?

No...

  • The minimum resistance load on the Arduino is 120 Ohms. (That gives you the "absolute maximum current draw of 40mA at 5V.)

For line level audio input to an audio amplifier you should be in the ballpark of 10K Ohms. (Amplifiers typically have an input impedance of 10K - 100K.)

  • RC filters are not "great" filters. You might need a multi-stage (multi-pole) active filter (made with one or more op-amps.

  • 33 Ohms and 100uF gives you a cutoff frequency of 48Hz. Only the bass is coming through without attenuation and it probably sounds "muffled".

  • The 1st goal goal is to let the audio through the filter. The "traditional" audio frequency range is 20Hz - 20kHz, so typically you'd want the cutoff frequency to be above 20kHz. But, with digital audio the frequency range is limited to half the sample rate. For example, if you have a sample rate of 16kHz, you can only have audio to 8kHz and your filter can cut-off/reduce everything above 8khz without hurting the sound.

  • The other goal is to kill the PWM frequency. If the PWM frequency is 10 times the audio frequency or more it gets pretty easy and you can use a simpler, more gentle filter. for example, class-D amplifiers use something like PWM and they often run at MHz rates. The PAM switches at 260kHz. The higher frequency is easier to filter out without filtering the audio, the speakers provide more "natural filtering", and it's way-above anything you can hear anyway.

If the PWM is closer to the audio frequency you need a filter with a sharp cutoff.

DVDdoug:
I don't know all of the answers... I've never used TMRpcm and I don't know the sample rate or the PWM frequency. I'm not sure what to expect from TMRpcm… I'm pretty sure you can't get "CD quality" or the quality of a good MP3... And, I don't know how sensitive the PAM amplifier is to the PWM signal.
No...

I don't need very high quality. I want only "acceptable" quality - such quality would make it possible to recognize words.

DVDdoug:

  • The minimum resistance load on the Arduino is 120 Ohms. (That gives you the "absolute maximum current draw of 40mA at 5V.)

So should I use only >=120 Ohms resistors?

DVDdoug:
For line level audio input to an audio amplifier you should be in the ballpark of 10K Ohms. (Amplifiers typically have an input impedance of 10K - 100K.)

As far as I know, this amplifier (PAM8403) works with 4-8 Ohms. I found in documentation:
"Maximum Gain
As shown in block diagram (Page 2), the PAM8403 has two internal amplifier stages. The first stage's gain is externally configurable, while the
second stage's is internally fixed. The closed-loop gain of the first stage is set by selecting the ratio of RF to RI while the second stage's gain is
fixed at 2x.The output of amplifier 1 serves as the input to amplifier 2, thus the two amplifiers produce signals identical in magnitude, but different
in phase by 180°. Consequently, the differential gain for the IC is
AVD = 20log [2(RF/RI)]
The PAM8403 sets maximum RF =142kΩ, minimum R =18kΩ, so the maximum closed-gain is 24dB. "

DVDdoug:

  • RC filters are not "great" filters. You might need a multi-stage (multi-pole) active filter (made with one or more op-amps.

I hope that RC is enough for my applications.

DVDdoug:

  • 33 Ohms and 100uF gives you a cutoff frequency of 48Hz. Only the bass is coming through without attenuation and it probably sounds "muffled".

Right, so 220 Ohms + 100nF should be better?

DVDdoug:

  • The 1st goal goal is to let the audio through the filter. The "traditional" audio frequency range is 20Hz - 20kHz, so typically you'd want the cutoff frequency to be above 20kHz. But, with digital audio the frequency range is limited to half the sample rate. For example, if you have a sample rate of 16kHz, you can only have audio to 8kHz and your filter can cut-off/reduce everything above 8khz without hurting the sound.

  • The other goal is to kill the PWM frequency. If the PWM frequency is 10 times the audio frequency or more it gets pretty easy and you can use a simpler, more gentle filter. for example, class-D amplifiers use something like PWM and they often run at MHz rates. The PAM switches at 260kHz. The higher frequency is easier to filter out without filtering the audio, the speakers provide more "natural filtering", and it's way-above anything you can hear anyway.

So if PAM switches at 260kHz and I have audio to 8kHz that I need LPF which can cut-off everything above 8kHz - e.g. 220 Ohms and 68nF, right?

DVDdoug:
If the PWM is closer to the audio frequency you need a filter with a sharp cutoff.

How can I check if the PWM is closer or farther?

I'd use more like 10k and 2.2nF. No need for ultra low impedance with an audio signal, amplifiers
have input impedances around 50k.

Your PWM must be running at a high enough frequency (62.5 kHz for instance) so the LPF
can do its job.

There is a risk the PWM frequency breakthrough will beat with the class D oscillator in the amp chip.
This will produce spurious tones. Changing the PWM frequency slightly may help.

As far as I know, this amplifier (PAM8403) works with 4-8 Ohms. I found in documentation:

Yes, but that's the output impedance. The filter goes on the input. :wink:

...You don't actually need much voltage gain (and the dB values reference voltage). The Arduino puts-out 5V peak-to-peak (before filtering). You mostly need current gain to drive the lower impedance speaker which also means you're getting power gain (Wattage gain).