FPGA generated SPDIF output

[Mike Field] just finished implementing SPDIF generation on an FPGA. SPDIF is an industry standard for transmitting digital audio signals; the acronym stands for Sony/Philips Digital Interconnect Format. It’s been around for more than a decade and since it’s found on most home-audio equipment, building an SPDIF output into your projects may be quite a desirable feature. [Mike] mentions several ideas for this functionality like building high-end test equipment, or providing a high-quality output for electronic instruments.

He first jumped into analyzing the specification in order to determine the hardware requirements. Due to some issues with jitter, he found it necessary to use a 100 MHz clock signal. This pushes the jitter down to +/- 5ns of jitter, which he concedes may raise the hackles of audio purists, but does satisfy the published standard. Output requires just one pin of the FPGA and the five components seen above. A hex inverter (74HC04) voltage divider, capacitor, and RCA connector transmit the 0.5V signal to your audio-receiver of choice. Of course, since TOSLINK fiber optic connectors use the same protocol, you could redesign the output and make this an optical connection.

@DAX The jitter is an issue as the shortest pulse is only about 170ns – so the spec requiring less then 20ns jitter seems reasonable. In a perfect world my project has 10ns jitter, leaving 10ns for jitter from outside my control.

Also crystals are not perfect time sources – they have maybe 30ppm accuracy. This adds lots of complexities when dealing with realtime sources, including DSP – if you are being given samples at 44,101hz and are sending them out 44,099hz due to differences in crystals two samples to you throw away? If you just buffer them over an hour your output will have 7,200 samples buffered and your output will be 163ms behind. Likewise, if you sending at 44101Hz and receiving at 44099Hz where do you get the two missing samples from?

One simple solution is to follow the input clock by storing samples in a FIFO and speeding up or slowing down transmission as the FIFO fills or empties. But this introduces a small amount of FM in the resulting signal.

The other solution is to interpolate the input signal, but then you are lose accuracy and high frequency response.

And if you try to mix two or more real-time digital audio sources you can have a whole lot of fun!

You’d be hard pressed nowadays to find a piece of equipment with an S/PDIF input that DOESN’T have a phase-locked-loop to deal with minor clock drift. It’s pretty much a non-issue, but has been taken up by the same sector that tries to sell you $1000 power cables, as it allows them to take their existing marketing material and do a find-and-replace of ‘noise’ with ‘jitter’.

TOSLINK has been around since 1983 according to the ever-reliable Wikipedia. Since Sony and Phillips (the S and P in S/PDIF) are the developers of the CD audio format, which was released in 1982, it seems like it’s nearer 3 decades…