Reading analog input at high frequency using arduino mega 2560 and SD card


I am trying to read a couple of signals using my arduino mega 2560. I need to read them at 4kHz. To do so I am using interrupts and the analogRead function.

My question is: how can I continuously send the data to a SD card? I can create a buffer and send it when is full but I don't know how to avoid data losses with the reading and writing speeds so different.

Thanks in advance

See this

That is great! Thank you.

I only have one question so far: how can I control the acquisition time? If I only need 10 secs, is there a way to set it?