I am fairly new to arduino, so forgive me if some of these things are obvious... I am in the middle of a project which will involve performing TDM across a bunch of shift register lines to control some large 8 segment LED displays. To do this I have been thinking of using an ISR with FrequencyTimer2 to output data using SPI to my latches. What I have come to realize though is that SPI using shiftOut() is not very fast.
I performed some rudimentary measurements and it seems like shiftOut() takes about 110us to output a byte. Perhaps this explains the 9600 baud limitation to the SoftwareSerial library? After delving into the shiftOut() and digitalWrite() code, (shiftOut() simply calls a bunch of digitalWrite()s in succession), I was able to perform some simple optimizations since digitalWrite() performs much of the same preparatory stuff over and over. I was able to create a dropin replacement for shiftOut() that works in 31ms. This could probably be further optimized but I thought that it was a good start.
This leas me to wonder whether others need higher performance IO in general with the Arduino and whether the core libraries should potentially be better optimized. Perhaps it would be even good to create a separate high performance IO library which may have slightly more complicated but more accurate IO functions. These functions might be slightly harder to use than the standard functions, but if properly used could give a substantial performance improvement still? For example: I split the shiftOut() function into a shiftOutPrep() and a shiftOutRaw() function. If using repetitive data, it can be prepared with shiftOutPrep() and then transmitted with shiftOutRaw(). If the same data needs to be transmitted again later, there is no need to call shiftOutPrep() again. I can get even better performance out of shiftOutRaw() than the optimized shiftOut() above, ~18us to transmit a byte!
These split functions would probably not be useful for random SerialIO such as the SoftwareSerial library, but for my use such as a TDM application where the data to be shifted out cycles through a repeated set of bytes, it pays to prepare the data with shiftOutPrep() function once in advance and then simply send the prepared bytes out with shiftOutRaw() cycling through a few prepared set of bytes. With the ability to send bytes serially in less than 20us one could perhaps perform repetitive serial IO at 50K baud! This is much better than the current 9600baud limitation.
Is anyone else interested in creating a High Performance IO library? I imagine that others could suggest even better optimizations for these functions greatly increasing the arduino's abilities.
If interested, I will post some of my optimizations here along with time measurements. for each.