Poor sound quality and cracking with pi zero

Poor sound quality and cracking noise coming from pi zero running 2.5w d class adafruit amp and a 3w 4ohm 1.5” speaker running through one of the gpio pins.

I have tried different amps and boards but nothing changes, is there a way I can increase the audio quality and remove that cracking sound?

1 Like

Hi Joseph!

Welcome. This sounds interesting. :slight_smile:

Quick word of encouragement. I’ve been playing around with audio on embedded systems this year and It can be done! It has been finicky; but it is possible to achieve good results.

Can you tell us a bit more about your setup?

Can you clarify what this means?
e.g. are we driving the amplifier from a PWM pin?
or are we grabbing audio from the hdmi out and then powering the amp with gpio?

Are we running a script to play some music or are you wanting the grab the output from the Linux audio driver?

Let us know.
Pix :heavy_heart_exclamation:

2 Likes

Hi thank you for the quick response.

Yes amplifier is being driven by a pwm pin and it’s an Adafruit pam 8302

It is playing videos from omxplayer at random on start up, basically I followed this guide 100% and have very poor results with the sound

I’m hoping there is a setting or something I can changed as I have tried multiple different speakers and boards with the same issues

Hi Joseph
If you are following the Audio part of that link forget it. I have never seen nor do I expect to see again a volume control and speaker connected like this. Also his soldering skills are crap. That is, pretty well non existent.

It is a class D amplifier and the speaker inductance forms part of the output filter and is quite important. The presence of any resistance in series with the speaker coil (as in your link) could well be the cause of your “noise”.

Can you post up a schematic of EXACTLY how you are connected and you might be able to get some help a bit easier.
Cheers Bob

Rob are you referring to the articles use of a potentiometer to attenuate the volume? :slight_smile:

No, I am referring to the audio part of this link

Cheers Bob
Edit.
Depends on which article you are referring to. I am referring to the one linked above.
I am not criticising the USE of a potentiometer to control volume, that is normally the case. I AM referring to the manner in which the potentiometer is used.
A bit confusing but if you are referring to the above ling I suppose in a way the answer could be yes.

Thanks for your help

Here is the setup I am currently running

I have had soo many hurdles with this I wish it would just work

Hi Joseph
Shows nothing but a jumble of red wires.
I meant a circuit diagram. you must have worked off something. Is that the whole of that Simpsons TV thing or just the audio bit.

AHHH the dream of many.
Cheers Bob

1 Like

Hi thanks for your advice, could you please explain in my detail why the audio section here is so bad?

I followed the steps 100%, although the screen is working fine my only issue now is the sound

Some better pics, I can’t upload a video to show the crackling sound and qudio quality



Hi Joseph
Read my reply of 3hrs ago about how this bloke is using the potentiometer.

Still can’t make out exactly how you have it wired. Just a mess of red wires.
Can’t even see the pot, I assumeme it is hanging off the 2 wires disappearing off to the left and I can just about make out one of these wires going to a speaker connection on the board so I assume it is wired as per the link you posted. NO GOOD. The speaker has to be connected DIRECTLY to the terminals. NO potentiometer.

Most of the relevant information Here

It would seem the input to this device has to be AUDIO NOT PWM. The device is quoted to have a fixed gain of 24db so audio volume can be controlled by a potentiometer at the input.

Audio “hot” to top of pot.
Audio Gnd to bottom of pot and Amp A- and I think to Amp Ground.
Audio from slider of pot (centre connection) to Amp A+.
Speaker connected directly to speaker connector.

Feeding PWM directly into the Amp would not sound too good. Added to this any pot resistance in circuit would upset the filtering provided by the speaker inductance. All would add up to pretty lousy audio.
Cheers Bob

1 Like

You can’t expect a project to meet your expectations just because someone has made it available for download. Perhaps the original author only knows very bad TV sound and is quite happy with the scratchy sound that the project creates.

A critical aspect of this design (apart from the issues already identified) is the PWM frequency. This is the rate at which a PWM sequence occurs. This needs to be several times higher than the highest audio frequency you expect to hear. But PWM is not designed for this purpose. For its proper purpose, such as controlling servos, the frequency doesn’t much matter. The frequency issue is not mentioned in the project writeup, so it is quite possible that the original author was using a frequency much higher than your default frequency.

The amplifier is very sensitive to supply noise. Basically, measured PWM input voltage (sampled over a suitable period) is added to the supply voltage, so if the supply has any noise then that goes straight through to the output. MCUs are very noisy.

Both the above issues could create a ‘cracking’ sound.

You may have a facility to check and change the PWM frequency - that would be buried somewhere in the MCU documenation… You could see if the power supply is noisy by using a temporary battery supply for the module and checking if the crackling still occurs.

1 Like

Jef, Joseph
Jeff is absolutely correct. PWM as generated bu a MCU could be anything. For instance the UNO I have has a frequency of about 490Hz. So the best audio you could reproduce would be about 50Hz.

A D class Amp is digital. It takes in Audio, converts to digital (PWM) then spits it out at the end all suitably processed. All inside this very clever IC. The final output is a form of PWM which is filtered by the output circuitry of which the speaker inductance plays a very significant role. For most upper market D class amps the speaker impedance is pretty tight. Any change to the design impedance requires a Capacitor change or even an inductor change as well. There is usually a chart provided outlining this.

All this is done in one IC nowadays. But go back a lot of years. There was an English engineer called Sinclair who developed this revolutionary audio amplifier that could get quite a few audio watts out of a small 9V battery. Yes, you guessed, this was an amplifier with a digital out (PWM). Pretty much exactly as today but done with discreet components. All this probably 50 years ago so nothing new here. The down side is they used to radiate noise like crazy and you had to lock them up in metal boxes.

This was simply called the “Sinclair Amplifier”.

Just Googled this and found the first was 1962. 60 years ago. There is some history of his different models here
http://rk.nvg.ntnu.no/sinclair/audio/amps.htm
I haven’t had a detailed look at this yet but will do so later
Cheers Bob

1 Like

Hi thanks for that but I am a complete beginner so I am having difficulty understanding what you are saying but I think I have a basic idea.

Would you be willing to pls draw a diagram for me so I can see exactly how to write it?

Also what do you mean about audio feeding to the amp instead of pwm?

1 Like

Would something like this work with no extra adjustments or coding?

Hi Joseph

Tomorrow.

Audio signal as what you get out of a headphone socket is about the easiest way to describe this.
It will be an AC signal going above and below zero volts whereas PWM (Pulse Code Modulation) is a series of pulses from 0V to some value and the width determines the instantaneous amplitude value after filtering.

An Audio signal is basically what you can hear in electrical form so something can be done about it.
A microphone is an example of a device that converts this sound into electrical signals.
A speaker is a device that converts these electrical signals back into sound pressure so we can hear it.

That is about as simple as I can make it. If you don’t understand some of the terms like “AC” you are going to have to do some reading. I am sorry but it is something that is difficult to explain in simple terms without being extremely long winded and it is not possible to do an electronics course in 5 minutes remotely. There have been literally volumes written on the subject.
Cheers Bob

1 Like

Hi Josep
Your diagram has just come through.
That would not work but you have the basic idea. The potentiometer is almost correct. Swap the 2 green wires over. Put the one from MCU to the end connection and the centre connection goes to A+ on the Amp.

But. What you apply to the green wire on the end of the pot cannot be PWM. Must be audio. Refer my last post
A minor point which does not matter much at this stage. You have a 10kΩ pot curve “B” (B10k marking) which is linear. for audio you need curve “A” which is logarithmic so the human ear will hear a linear progression of sound level when the pot rotates. With a linear curve the level changes will appear scrunched up at one end of pot travel.
Cheers Bob

2 Likes

I will change the connections as you said and hope for the best.

But what about feeding audio into it instead of pwm? I see other people soldering to the audio jack to get audio but I don’t have one as it is a pi zero

Will it still work if I use the method in the diagram using the gpio pin?

1 Like

The project you have referred to works by using the PWM facility of the MCU to create a signal that is nearly an ordinary audio signal.

Your audio source is a series of numbers representing the voltage level of the audio signal at instances of time, lets say 44,100 times per second.

An audio signal can be created from this digital source by varying a voltage according to the level indicated by the digital data in the source. But your MCU cannot create a varying voltage directly (if it could you would have a phono socket). It can create a PWM signal at a high repetition rate. A PWM signal is high for a certain proportion of the time and low for a certain proportion. The amplifier input senses the PWM signal as a voltage level according to how much of the time it is high and how much of the time it is low. It has to test a large number of repetitions of the PWM signal (several multiples of 44,100 times per second) to get a reasonable assessment of the intended voltage level. At this point the signal is effectively an audio signal, and is processed through the amplifier.

Your crackle could be coming from your digital source, from errors in the program code that is controlling the PWM, from a PWM repetition rate that is too slow, from electrical noise that is being introduced into the voltage measurement process or from the other issues already mentioned. Each of the possibilities should ruled out one by one. Have you confirmed that your audio source does not already have the crackle in it?

2 Likes

Hi Jeff

I think Joseph is under the impression that the MCU is going to output a signal at the GPIO that is suitable for use without any further intervention by him.

I don’t believe it works like that.
Cheers Bob