I2S audio connections usually use 3 different clocks: a frame clock, a bit clock and a master clock that must be synchronized. This is just a small sheet showing different sample rates for the standard sample rates. One thing that is important for anybody designing I2S audio interconnects: The frequencies can be relatively high. Make sure, you keep the traces as short and use countermeasures against ringing. Otherwise your circuit might interfere other devices.
Today I spent several hours looking for a hardware problem of the HiFiBerry DAC. I had a quick look at the I2S line and the power supply – everything seemed to be ok. After some hours testing I noticed, the the sound output was working with FLAC files, but not with WAV files. WTF? At least it was clear now, that I should look for a software problem, not a hardware problem.
Here is a picture of the BCLK and LRCLK lines when playing back the FLAC file:
And this is the playback of the WAV file:
Can you see the difference? In the second scope picture you can see, that the driver only creates 20 clock cycles for the left and the right channel, in the first case there are 32. Because the DAC supports only BCLK=64xLRCLK, it does not create any output in the second example.
Therefore, when debugging I2S circuits, not only have a look if there is a signal on all lines, but also check, that the clock frequencies are correct.
Our HiFiBerry Mini, HiFiBerry Digi or HiFiBerry DSP boards use a I2S connection to the Raspberry Pi. The Raspberry Pi Release 2 is already prepared for this connection. However you have to solder the necessary pin header by yourself.
Identify the P5 header
If you look on the underside of the Raspberry Pi, you will find 8 pads between the large extension header (2×13 pins) and the SD card connector. This is the connector you have to solder.
If this connector is missing, you have an old Version 1 Raspberry Pi board. Unfortunately there is no header prepared on this board. In this case, we recommend to buy a new Raspberry Pi. All Raspberries bought since autumn 2012 should have the connector.
Solder the P5 header
Now insert an 8-pin header from the top and solder it on the bottom. The result should look like this:
That’s it. You can now plug an I2S board (e.g. HiFiBerry Mini) to the Raspberry Pi.
Our DSP project for the Raspberry Pi has reached the next milestone: hardware prototyping. The digital part of the circuits is working. There was still a minor bug (wrong pinout of a transistor) that was easy to correct by soldering the transistor on its back. The rest of the circuit worked well. As you can see on the picture, the analog part is not assembled yet. First I want to be able to upload the software to the chip.
Unfortunately, the simple approach to upload the program did not work. The chip simply did not acknowledge any I2S requests. Soldering some cables and connecting the I2S bus to the logic analyzer showed some unexpected behavior. While I2C read requests did not work, there was no problem with write requests. What happened? I had a look at the datasheet again and I think, I found the problem. Before every read request, the chip expects a write request with the address to read. However, both requests have to be in the same I2C transaction. The chip expects multiple start bits. Unfortunately, the Python I2C library that I wanted to use does not support multiple starts. It seems that I have to use the lower-level device driver of the operating system to upload the software to the chip.
Here are some noise and distortion measurements of the HiFiBerry Mini DAC. Without the ethernet connected, noise is practically non-existing. But also distortions look good. D2 has the highest level and higher-order noise is decreasing with each order. This is really a nice chip.
At 1kHz we see 0.0037% THD+N (distortions alone only 0.003%). However, the measurement equipment itself (an EMU0404) itself has a THD+N level of 0.002% at this frequency (in- and output together). Therefore the real noise and distortion figure might even be a bit smaller.
We also did tests at other frequencies and they look similar:
Note, that these measurements are a bit flawed, because at higher frequencies there are less harmonics within the measurement frequency range than at lower frequencies. Therefore the distortions go down. Unfortunately I was not able the extract the D2 and D3 levels alone.
There are more good news. The voltage regulation on the board works great. Even with the worst power supply I could find (a Nokia charger), the figures did not change much. THD+N went up from 0.0037% to 0.004% at 1kHz. That means there is no urgent need to upgrade the power supply of your Raspberry Pi.
Update 1.12.2013: We did some THD+N measurements of our production version. They were even lover than the values show here.
Today I did some tests with the HiFiBerry Mini and RaspyFi. I replaced the kernel by the HiFiBerry enabled kernel – and it worked perfectly. The music was played from a cheap USB-Stick. But the most interesting part was the test with 192kHz/24bit FLAC files. And yes – it works! I think, this is the smallest Raspberry-based setup that is able to play 192kHz FLAC music.
It is also nice to see, that RaspyFi also plays MP3 files in 24bit resolution, which means potentially less distortions.