Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
    
What do you have for a microcontroller? – ThreePhaseEel Dec 7 '15 at 5:29
    
@ThreePhaseEel: It's STM32F3 series. – Alex I Dec 7 '15 at 5:52

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.

share|improve this answer
    
I can totally see how that would work at low data rates, but I need a few mbit/s. I was hoping to (for example) use the UART, but convert each byte to two bytes using a lookup table, and make sure UART is always running sending a pair of bytes that means "ignore this value". – Alex I Dec 7 '15 at 6:41
    
That's not a bad idea if you can make sure the UART buffer is always full. I would recommend trying to keep things DC balanced (same number of 1s and 0s). A standard UART adds one start bit and one stop bit of opposite polarity. So all you need to do is make sure that the data is DC balanced. Perhaps you can do something like this: when you are sending data, send each byte followed by its bitwise inverse. When you aren't sending data, send something with an equal number of 1s and 0s, such as 0xAA, 0x55, 0x0F, 0xF0, etc. You'll also need to make sure the receive UART can lock on to it. – alex.forencich Dec 7 '15 at 6:59
    
Instead of the UART, which will require start and stop bits, consider using the SPI peripheral, which won't. – Nick Johnson Dec 7 '15 at 15:10
    
The main problem I see is getting synchronization. SPI is a really bad idea because it requires an explicit clock. Sure, you can run both ends in master mode, but then you have to do clock recovery in software, which is doable but would probably seriously limit the data rate. – alex.forencich Dec 7 '15 at 18:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.