Encoder/decoder for serial connection without separate clock

encoderserialspdiftoslink

I'm putting together a link where the physical layer is SPDIF transmitters and receivers. I control both sides of the link (ie it doesn't have to interoperate with any other equipment). I would like to send data from a microcontroller, essentially treating this as a UART. The problem: if the output stays low or stays high too long (not sending data on the UART), the SPDIF receiver output becomes unpredictable, and it takes a fair amount of time with regular transitions for it to recover. SPDIF normally uses Bi-phase Mark Code (BMC) to deal with this problem (the clock is always running so there are always low-high transitions).

What is the easiest way to encode and decode data which ensures the link is always transitioning between states? I'd like to use the least amount of hardware to implement, and relatively simple software; ideally no hardware, and just using the peripherals on the microcontroller. It doesn't have to be BMC; 8/10 for example would be perfectly ok.

Best Answer

Best solution in terms of achievable throughput would probably be a CPLD or small FPGA. If that's not reasonable, then I would recommend using frequency modulation. Use a timer/counter to transmit and another one to receive. Perhaps have 3 different frequencies, one for idle, one for high, and one for low. Transmit complete cycles of various widths on one end using the timer/counter module, then use the capture mode of the timer/counter to measure the frequency on the other end. I would think you can get a data rate of a few kbps without too much trouble with this setup.