I'm quite new to the whole world of the Arduino and have only been playing with one for a day now, so please excuse anything that should be obvious
I'm wondering whether it would be possible to use my Duemilanove (ATmega328) to bit bang a SPDIF signal to plug into an external amplifier. Given the chip runs at 16MHz and SPDIF has a transfer rate of 3Mbps (at 48kHz), that would allow for about five 'cycles' per SPDIF bit. Is this too optimistic? I guess all I'd have time to generate is a square wave...
Are there any other methods that could be used to work around this? e.g. using multiple digital outputs in parallel, and another IC to shift the bits out instead?
Anyway, maybe it can't be done but I'm just wondering how others might go about attempting something like this...
Well, having recently purchased a cheap second hand oscilloscope, I've had a chance to try out some experiments. This could be wrong as I haven't used an oscilloscope before, but the figures seem OK to me.
The first test was a simple loop with digitalWrite:
for (;;) {
 digitalWrite(13, 0);
 digitalWrite(13, 1);
}
This revealed that each 'bit' lasted for 3.5us, or 7.1us for the whole on/off cycle. By my calculations (which you should double check!) I came up with a loop speed of 141kHz, giving a maximum bitrate of 277kbps (since there were two bits per loop iteration.)
Changing digitalWrite() to direct port manipulation revealed a surprisingly large (almost 30x) speed increase:
for (;;) {
 PORTB |= B00100000;
 PORTB &= B11011111;
}
Now each bit only lasted for 0.12us, however the loop itself takes up an additional 0.16us per iteration, giving 0.38us per iteration - a loop speed of 2.63MHz. Technically the bitrate achieved was 9Mbps, but that would only happen if your code consisted of a list of PORTB= statements and nothing else. Once the loop is taken into account it drops to 5.2Mbps.
Given that SPDIF has a transfer rate of 3Mbps it would seem that the Duemilanove is technically capable of bit banging it, but as I suspected in my original post there's not going to be much time left over to generate useful data to transmit. Not to mention difficulties in keeping the timing stable.
The only way I can think of that might get around this is to use some kind of shift register so the Arduino can output the bits in parallel and have the register convert them into serial and drive the SPDIF line. It might be difficult to make this happen smoothly though, as I imagine there'd be a timing glitch every time the register needed to be refreshed with the next lot of data. Maybe one of those bus interface ICs might help there, by acting as a parallel buffer between the Arduino and the shift register?