Aleph90 wrote: Thu Feb 13, 2025 1:35 am
If that's the case, the PWM pins will always be outputting the switching noise on top of the intended sound, so even if I feed the PAM8302 from a separate source won't the noise be amplified alongside everything else?
The noise will be there, but it won't matter. It will be what's called 'common mode' noise on a 'differential' signal.
Voltage is kind of like distance: you have to measure it between two points. In most cases we declare GND to be the 0V reference from which all other voltages in a circuit are measured. Functionally though, you can measure any signal relative to any other one.
That turns out to be useful when you have two signals with equal voltage but opposite polarity.. one goes up when the other goes down, and they always remain symmetric around some middle voltage. We can break that down mathematically as:
line1 = positive-signal + offset
line2 = negative-signal + offset
Since the offset appears in both parts we call it the 'common mode' part of the signal, with the other parts being the 'differential' signal.
Using one line as the reference for the other gives us:
signal-of-interest == line1 - line2 == ( positive-signal + offset ) - ( negative-signal + offset )
The common mode offset gets both added and subtracted, leaving only the difference between the differential parts of the signal. Moving that idea to hardware, the circuit receiving a differential signal can't even see the common mode offset.
If we extend that idea by adding noise we get:
line1 = positive-signal + offset + noise
line2 = negative-signal + offset + noise
As long as we have the same noise on both lines, that noise is part of the common mode signal. A receiver can't even see it unless you have a third connection to some other shared reference voltage (the ground loop).
Aleph90 wrote: Thu Feb 13, 2025 1:35 am
Much of the testing I've done did not involve the PAM8302 at all. The jack only connects to the PWMs and ground, and I don't imagine it would make much sense to ground the jack on a separate power supply. It seems to me that the idea of separating power supplies only has a hope to work with the amplifier, not so much the jack, or am I missing something?
Based on the info above, the jack should only have the A+ and A- signals. Adding a GND connection is what makes any common mode noise detectable.
Aleph90 wrote: Thu Feb 13, 2025 1:35 am
When you say "Moving the RasPi temporarily to a separate power supply", what do you mean "temporarily"? Are you suggesting this just as a strategy for testing to see if the noise goes away?
Yep. The first rule of troubleshooting is "don't believe anything you haven't confirmed by physical measurement."
We rely on a lot of assumptions when thinking about circuits, some of which are embarrassingly easy to get wrong.. I've been caught by "of course the power is connected" more times than I'd like to admit. In many cases, it's easier to test your basic assumptions by changing the design rules for a given project. The change doesn't have to be permanent, just long enough to confirm your assumptions or identify a problem. But don't be afraid to change things long enough to get information you need.
Aleph90 wrote: Thu Feb 13, 2025 1:35 am
I seem to understand that the PAM8302 takes in the difference of what's on A+ and A- and amplifies that. Is that right?
Exactly, yes.
Aleph90 wrote: Thu Feb 13, 2025 1:35 am
Could I be getting outputs from the PWM's that are so similar that the difference is so small that even the amplified signal is still weak?
That's possible. Another possibility is that you have a ground loop making the noise on the A+ and A- lines visible, and the noise is larger than the audio signal. This is one of the reasons electronics types like oscilloscopes so much.. being able to see what the signals are actually doing makes diagnosis a lot easier.
Aleph90 wrote: Thu Feb 13, 2025 1:35 am
When you said "You'll get much less volume driving headphones directly from the filter, but the PAM8302 uses very little input current", does that mean that the volume I get on my headphones depends on the current being put out of the filter, while the amplifier only looks at the voltages?
Yes.
There are two kinds of amplifiers: preamps and power amps. A preamplifier converts a small change of input voltage (say +/-1mV) to a large change of output voltage (+/-1V) as accurately as possible. A power amplifier converts a signal with very little current (+/-1V @ 1mA) to one with a lot of current (+/-1mV @ 1A).
Amplifiers are powered circuits, so you have to choose between spending energy to get more voltage or spending energy to get more current. Trying to do both at the same time is less effective than doing one or the other really well, then putting 'more voltage' and 'more current' in series.
When you drive the headphones directly, all the current the speakers get has to come from the input signal. The PAM8302 is a power amp with a separate power connection though, so it doesn't need to pull current from the input signal. In fact, it's easier to get accurate and responsive input if the input stage draws as little current as possible.
Aleph90 wrote: Thu Feb 13, 2025 1:35 am
If the Pi is powered from the PowerBoost via the 5V power pin, shouldn't the PowerBoost control the voltage on it rather than the Pi, and keep it at a fixed 5V? Of course I imagine the PowerBoost will have its own switching regulators so there may still be noise coming from that, but then I'd expect the noise to sound different depending on the power source, while in my tests it really sounded the same using a wall adapter as it did with the PowerBoost.
In theory the PowerBoost should send the RasPi 5V, and the RasPi's onboard voltage regulators will add another layer of control to the voltage the CPU sees.
In reality there are two problems: the first is that regulators reduce noise but can't remove it completely. The second is that you can't regulate what isn't there.
Noise reduction involves noticing a change, deciding what to do about it, and enacting the change. Each of those steps takes time, so there's always some lag between the input and the response. That means there's a category of changes that happen too fast for the regulator to correct. That's compounded by the simplest kind of control systems whose correction is proportional to the error they see.. perfect correction would mean they wouldn't see any error to correct.
(there are better options, but they're more complicated, more expensive, use more parts, and still aren't perfect)
That kind of correction applies to voltage spikes, but can't do anything about voltage dips. There's nothing a regulator can do about a load that wants more current than the supply can deliver.
Switching regulators like the PowerBoost use PWM, so their output is full of spikes and dips. The RasPi uses PWM to generate audio output, and the PAM8302 is also a PWM device. Combining PWM systems creates all sorts of problems when the pulses line up with each other, so there are plenty of ways to generate detectable noise.
Aleph90 wrote: Thu Feb 13, 2025 1:35 am
Why did LadyAda's solution work on the original Pi Zero?
The circuit in the tutorial demonstrates the basic idea but requires the right operating conditions. The RasPi's GPIO pins can't supply much current, so you need high impedance headphones or powered speakers. Most of our audio demos use USB powered speakers, which would sidestep the problem of noise from a shared power supply.