Acquiring and storing data to SD card at high rate from 4 analog pins

Pardon me but...

The basic premise is that Arduino is single-threaded processing... only one routine can access the core at a time. Interrupts push the microprocessor registers and addresses onto the program stack before the ISR can execute, so while interrupts do help to ensure that certain things happen in a asynchronous manner, there is a small time delay and SRAM resources that must be allocated to this effort. Additionally, SD flash memory requires that a 512Byte buffer be allocated for every write operation, on the UNO, this is 25% of the total SRAM. And there are additional SRAM requirements.

Hardware serial is asynchronous and a rather light-weight Arduino implementation in software. If one moves the SD-card off to a separate Atmega328P which is dedicated to receive, buffer, write to SD a minimum of 25% SRAM is returned to the main Arduino and a significant amount of microcontroller bandwidth. From a software architecture point-of-view, the main data-acquisition uC really knows nothing about the SD-card... it simply streams a log-file out the serial port at the highest rate that can be accepted by the downstream processor... the exact rate will depend on the quality of the SD card, so testing would be required. A previous link by Caltoa suggests that newly released forum SD routines can process very fast.

If you implement "Streaming.h" (requires no uC resources... just another way of saying Serial.print()) then you can easily write your program output syntax and test on the Arduino monitor (or TeraTerm or your favorite serial monitor) and simply connect the downstream SD-writer for logging. Logically, this simplifies the conceptual programming. It is, however, no always the right thing to do, if you must do read and write operations on the SD... the concept works best for write-only. We simply abstract the SD-card to a terminal device. All of the uC SRAM is dedicated to the SD write routines, so multi-buffering on the incoming datastream is possible, but hopefully that would not be necessary.

There is latency in this operation, although it can be characterized with testing. If one of the data elements is a timestamp, then latency in the write-to-SD is inconsequential.

Ray

Link to Streaming.h
http://arduiniana.org/libraries/streaming/

Link to SD off-loading (this is a dedicated 9600 BAUD routine and is dated, but it will give you an idea)
http://forum.arduino.cc/index.php?topic=154864.0

Link to understanding Arduino SRAM allocations (must read):

Things to know about SD cards:
http://arduino-info.wikispaces.com/SD-Cards