SD card write latencies

Hey guys,

I was playing around with the ADC of the Arduino. When I change the pre-scaler to 32, I can get around 38k samples per second. The main problem right now is to store these values.

I have a slight doubt regarding the write latencies. I know that the memory in the SD card is divided into chunks of 512 bytes each, and each chunk gets filled up before the next. I got this idea of storing all the samples from a project (somewhere online, I'm really sorry, I don't remember who did this) where the person uses double buffers.

Let's say I have 2 buffers (both 512 bytes, because if I keep them as 1kB, the entire RAM would disappear). I constantly write one buffer's data to the SD card while storing the ADC values through interrupts in the other buffer. The person who had done the project said that there is plenty of time to get the samples written on the SD card.

But I have a question. If we write 512 bytes of from a buffer to an SD card, does it write all 512 bytes in 1 instant? As in, will there only be 1 write latency for all 512 bytes? Or will there be a write latency for each of the integer that we write on the SD card? 512 bytes gives us 256 integers, so does this mean I'll have 256 write latencies?

If this is true, is there any way I can store all these samples into an SD card?

tl;dr - How do I store 19k or 38k samples per second into an SD card and overcome the write latencies?


Have you seen this post (about the 10th down from yours, at the moment): Try this super fast analog pin logger

An “SdCard Write Latency” is an “random effect”, which lasts (WL duration) from few msecs up to 250msecs (or more), with quite random occurrence, and WL depends on many factors which are not known (SdCard’s internals).
WL relates to internal processes an SdCard provides (internal housekeeping).
It has been discussed in this forum many times.
In order to write a continuous stream of data to the SdCard you must overcome these outages somehow - there are several approaches, my favorite is to use FIFO buffer for buffering the samples within the FIFO while the SdCard is not accessible (during an WL hit).