yet another arduino speaker problem

short version: im getting alot of noise from my speaker during playback

My class D amplifier

My 50watt 4Ohm speaker

My SD card reader

This is a video of the sound its making

im using the TMRpcm library to play .wav files from the SD card and an arduino uno. I've read through everything I could find on google from decoupling capacitors and low pass filters and other such suggestions. As for the library i uncommented the recommended settings and changed the quality to 0. I also made the audio file size 8khz to avoid possible buffering issues. I've made sure it otherwise meets the library specs.

I suspect its an issue with the amp itself because I've swapped it for a LM386 amp and it works fine, its just too quiet. I've tried soldering a new class D amp and I get the exact same problem. I've made sure the solder points are good and not affecting anything else on the board.

I had suspicions that only using 1 channel of the amplifier was causing the problem but I was informed by others that this is not the case. To clarify I'm only using the left channel and speaker and the ground. the right channel input and output having nothing connected at all.

The feedback only happens when the sound is playing, its otherwise pretty quiet (if you listen closely you can barely hear a humming sound). I also in the programming turn off (low) Pin 9 on the arduino (the line output to the speaker).

I think that covers everything I've tried. I'm going to upload a schematic when I get a chance, at least I'm going to try. This is my first project I'm attempting by myself without a tutorial so I don't know much but I've tried everything I can think of and its starting to drive me mad.

Thanks for your time and sorry for the long post!

I think there is a lot you don’t understand

I also made the audio file size 8khz to avoid possible buffering issues

A file size can not be a frequency.

the right channel input and output having nothing connected at all.

You should connect the unused input to ground.

I suspect its an issue with the amp itself because I've swapped it for a LM386 amp and it works fine, its just too quiet.

Then it is possible it is a power supply issue, is it capable of providing enough current?

A schematic would be good, especially the filter circuits you are using between the Arduino and amplifier.

What exactly is the speaker trying to play in that video?

Grumpy_Mike: I think there is a lot you don’t understand

No arguments there!

Grumpy_Mike: A file size can not be a frequency.

I'm just repeating information I've read in another forum post that is quite a few years old from the author of the TMRpcm library. Someone was experiencing similar issues and this was a step they had recommended. I'm assuming changing to a lower sample rate results in a lower file size?

Grumpy_Mike: You should connect the unused input to ground.

I'm not in front of my project right now but i will do this next chance i get

Grumpy_Mike: Then it is possible it is a power supply issue, is it capable of providing enough current?

I've tried doing a bit of searching but I'm guessing I don't know enough to find the answer to this question. Could you point me in a direction on how to figure this out?

Grumpy_Mike: A schematic would be good, especially the filter circuits you are using between the Arduino and amplifier.

I tried to upload the schematic and it keeps giving me an error and says to go back and try it again. I'm not sure what the problem is there. As for the filters I went with what was recommended in another similar topic, I have an inline filter on the speaker input line thats a 10nf (this might be wrong, going off memory here) film capacitor. On the power and ground i have a 100uf electrolytic capacitor. Adding these has cleared up some background noise from what i assume is coming from the power supply but has had no impact on the squealing sound.

Grumpy_Mike: What exactly is the speaker trying to play in that video?

its just a synthesized bass hit. I can edit this post after I get off work and put a link to it.

Thanks for taking the time to read through my post and offer suggestions.

I'm just repeating information I've read in another forum post that is quite a few years old from the author of the TMRpcm library.

So how did you do this. A file size can be 8K bytes long, a sample frequency can be 8 KHz. You can have a file size that is a frequency.

For the line filter you need a series resistor of about 1K5 coming from the Arduino output to the amplifier input and then the 10nF capacitor going from this input to ground.

That might not be enough for two reasons. First it is only a single order filter and does not run off very fast. And second the amplifier’s input is a high impedance and so will pick up interference from the digital circuits. I have found that a 4K7 resistor from amplifier input to ground will often cut down the sensitivity to that.

its just a synthesized bass hit. ..... has had no impact on the squealing sound.

I did not hear any squealing sound just a bit of a phutt noise. Then again I am an old fart who’s ears are probably shot through a lot of live gigs.

If you have a stereo amplifier and are only using one channel, you could get a 3dB improvement by strapping the L&R inputs and putting a loudspeaker on the unused channel too.

Make sure that your power supply has enough headroom for what you are trying to do though.

and putting a loudspeaker on the unused channel too.

So connecting the two outputs of a class D amplifier together? I think not.

Maybe read my post again Mike? :wink:

So connecting the two outputs of a class D amplifier together? I think not.

That's what I thought he was saying when I frst read it, but I think he means "putting a*nother* loudspeaker on the unused channel too."

Of course, that also increases the noise by 3dB. ;)

...I've never tried used TMRpcm so I don't know what's normal but I wouldn't expect good sound quality.

Of course it's really PWM so I wouldn't connect to my stereo system or any amplifier that I care about. And, it might cause additional problems with a class-D amplifier. People have reported trouble when using PAM amplifiers but I can't say that's caused by TMRpcm or if they were just doing something wrong.

AJLElectronics: Maybe read my post again Mike? ;-)

Yes sorry I did miss read it.

Grumpy_Mike: So how did you do this. A file size can be 8K bytes long, a sample frequency can be 8 KHz. You can have a file size that is a frequency.

recommended in a tutorial, used an online converter to convert the sample rate/frequency to 8khz, mono, unsigned 8bit as recommended for the library. it supports higher quality sampling but the author just recommended that for testing.

Grumpy_Mike: For the line filter you need a series resistor of about 1K5 coming from the Arduino output to the amplifier input and then the 10nF capacitor going from this input to ground...

so i dont have a 4k7 resistor, closest i have on hand is a 5k1. this seemed to have helped with the noise. i assume if i get a 4k7 i might get a little bit more volume?

i also grounded the other input as you suggested and that seems to have been where most of the noise was coming from. looks like i was just taking some bad advice when they said it didnt need anything done with it.

the sound is alot cleaner but now that ive got rid of the noise from the ungrounded input i can still hear the normal buzzing feedback sound that is so common. its a constant buzz even when the sound isnt playing back so i assume its coming from the power. would increasing the capacitance of the decoupling capacitors from the power supply help? i currently have 100uf electrolytic capacitors connected but ive seen some people recommend 1000uf instead.

Thanks for all your help and time!

AJLElectronics:
If you have a stereo amplifier and are only using one channel, you could get a 3dB improvement by strapping the L&R inputs and putting a loudspeaker on the unused channel too.

for now im trying to work within a small budget, trying to find the best compromise between volume and cost, then quality. so far the speaker is about half the cost and thats just with one.

DVDdoug:
People have reported trouble when using PAM amplifiers but I can’t say that’s caused by TMRpcm or if they were just doing something wrong.

i started out with the lm386 but that was far too quiet. after speaking with others they recommended the amplifier i picked out. as somehow who doesnt know much about amplifiers but is still trying to stay within a reasonable budget is there a different amp i should be looking at getting?

recommended in a tutorial, used an online converter to convert the sample rate/frequency to 8khz, mono, unsigned 8bit as recommended for the library. it supports higher quality sampling

Yes that is the sample rate, it is not what you said which was the file size. It is important to use the right words when describing something.

Yes 5K1 will do just as well, we are after a order of magnitude here not a precise value. I doubt if you will notice any difference with a 4K7. The lower the resistor the lower the noise but at the expense of a lower volume.

Yes a bigger capacitor will help, but also make sure you are using a 0.1uF ceramic capacitor as well in parallel to handle the higher frequencies.

Grumpy_Mike: but also make sure you are using a 0.1uF ceramic capacitor as well in parallel to handle the higher frequencies.

will film capacitors instead of ceramic work as a replacement without any negative impact? i have film capacitors but not ceramic on hand.

will film capacitors instead of ceramic work as a replacement without any negative impact

This is one of those cases where only a ceramic capacitor will be effective. They handle high frequencies where as other capacitor types do not, with the possible exception of silver mica, which I haven’t seen for many years and you can’t get the value that large.anyway.

i started out with the lm386 but that was far too quiet. after speaking with others they recommended the amplifier i picked out. as somehow who doesnt know much about amplifiers but is still trying to stay within a reasonable budget is there a different amp i should be looking at getting?

Voltage is a limiting factor.

5V peak-to-peak is the theoretical maximum you can get from the LM386. That’s about 1.75 Volts which is about 3/4ths of a Watt into 4 Ohms.* (Half that into 8-Ohms.)

The PAM has a bridge output (there is no ground to the speaker) which means the voltage can “reverse” for 10V peak-to-peak and you can get 4 times the wattage. That’s 6dB louder.

In the real world, there is voltage loss in the amplifier (depending on the particular amp) so you can’t get the theoretical maximum.

If you want more power you need higher voltage (or more speakers, or lower impedance, etc.).

Of course, if you increase the wattage & gain the noise goes up with the signal.

  • One way to calculate power is P = V2/R

eric2vr: Did you try different amplifiers?

I tried a prebuilt lm386 and the class d amp I listed in the original post. I only tried these because of other posts I've read that recommended those specific amps.

Unless I have the specific type of amp I'm searching for, just searching amplifiers gives me a lot of unwanted results.

From my understanding though class d amps are one of the best ones you can get. As far as the variety of class d amps I'm open to suggestions.

From my understanding though class d amps are one of the best ones you can get

Do you understand what a class D amplifier is? Yes it is efficient but not exactly the best audio quality. It works by sending a signal full on or full off. The time between the on and the off controls the average sound pressure you receive. So not exactly hi-fi.

Do you understand what a class D amplifier is? Yes it is efficient but not exactly the best audio quality. It works by sending a signal full on or full off. The time between the on and the off controls the average sound pressure you receive. So not exactly hi-fi.

They can be. The good ones operate at very-high frequencies and the output is properly filtered to true-analog. (The same concept that allows a switching power supply to put-out pure-DC.)

Most modern home theater & hi-fi receivers are now class-D. [u]This professional amplifier[/u] is class-D.

But again, I wouldn't connect any good amplifier to an Arduino PWM output!

Grumpy_Mike: Do you understand what a class D amplifier is? Yes it is efficient but not exactly the best audio quality. It works by sending a signal full on or full off. The time between the on and the off controls the average sound pressure you receive. So not exactly hi-fi.

0.01% THD is not uncommon now, when GaNFET class D becomes mainstream with higher switching frequencies I think it will get even better. Remember we can do things in the time-domain with unrivalled precision and much less reliance on component quality or tolerances. The standard approach is wrapping feedback loop around the whole class D amp + filter to improve performance, which gets much more effective as switching frequency is raised.

[ small class D chips will of course lag behind the curve in terms of quality, but you can do direct digital output to drive an H-bridge by doing the PWM conversion with noise-shaping in software ]