Behind The Pin: How The Raspberry Pi Gets Its Audio


Single board computers have provided us with a revolution in the way we approach computing as hardware creators. We have grown accustomed to a world in which an entire microcomputer has become a component in its own right rather than a complex system, and we interface to them as amorphous entities through their exposed interfaces. But every pin or socket on a single board computer has something behind it, so following up on a recent news-inspired item in which we took a look at what lies behind the Ethernet jack on a Raspberry Pi, we’d like to continue that theme by looking behind more pins and interfaces. So today we’ll stay with the Raspberry Pi, and start with an easy target by taking a look down its audio jack.

All the main Raspberry Pi board releases since 2012 with the exception of the Pi Zero series, have featured a 3.5mm jack carrying line-level audio. The circuits are readily accessible via the Raspberry Pi website, and are easy enough to understand because of course all the really hard work is done within the silicon of the Broadcom system-on-chip. Looking at the audio circuitry, we’ll start by going back to the original Pi Model B from 2012 (PDF) because though more recent models have seen a few changes, this holds the essence of the circuitry.

The audio circuitry from the first Raspberry Pi.
The audio circuitry from the first Raspberry Pi.

The schematic above shows the audio circuitry from the first Raspberry Pi. On the left are inputs from a pair of BCM2385 PWM lines, and on the right is the audio jack. What is in the middle might seem quite surprising, this circuit uses only discrete components. Even that splits neatly into two sections, the diodes perform the function of protecting the input from harmful voltages that might come in through the jack, and the RC network is a filter. This last section is the interesting part, and deserves a more in-depth explanation.

PWM, which stands for Pulse Width Modulation, is an entirely digital way of representing an analogue value as a chain of pulses whose width is proportional to the analogue value being expressed. In itself it is not an analogue signal, though it is simple to convert to one by passing through a low-pass filter whose cut-off frequency is the maximum frequency of the analogue signal. So if we take a look again at the right hand side of the circuit, we see using the numbers from the right channel in the top circuit that R21 and C20 form a low-pass filter. The values of 270R and 33nF can be calculated to give a cut-off frequency of just below 18kHz, which is a sensible sounding value for an audio output.

The next two components are a high-pass filter, R20 and C48. This takes away any extremely low frequencies which might cause uncomfortable rumbling or damage to speakers. The values of 150R and 10uF can be calculated as having a cut-off of about 100Hz, yet again a sensible-sounding figure. The output from this pair of filters should be an acceptable audio signal, and goes straight to the 3.5mm jack.

Newer Pi, Better Audio

The more recent Raspberry Pi models have had a few changes in the audio department. The early boards had a low-ish audio level, and their frequency response could have been better. The newer version of the circuit adds a high-speed buffer chip to provide a lower-impedance source, and tweaks the filter values somewhat.

The audio circuitry from the Raspberry Pi 3.
The audio circuitry from the Raspberry Pi 3.

The low-pass filter’s 220R and 100nF now give it a cut-off of just over 7kHz, and the high-pass filter’s 100R and 47uF give it 33Hz. Both these values sound way off the mark, after all 7kHz is hardly hi-fi. But to imagine that the calculated cut-off frequency is a brick wall is to make a grave error. In fact that is better termed as a roll-off frequency, at which the response starts to decline. These revised values will give a rounded frequency response that still lets through plenty of high frequencies and stops plenty of low ones, but has an end result that doesn’t stretch too high above the audio range.

Thanks to some maths that torment electronic engineering students, the response of the low-pass filter should end at  half the sampling frequency (at least) of the audio being played, to avoid unwanted distortion in the result. These values provide a better approximation to that figure, and thus make for a better quality audio output from more recent Pi versions.

This is a circuit that seems simple enough, yet there lurks a surprising complexity. It has plenty of uses beyond the Pi, because wherever you may use a PWM audio signal from a microcontroller or SoC you will need to replicate its functionality.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *