SD Card Logging Inconsistent

Sup everyone,

I'm trying to implement a datalogger on a Teensy 3.5 with as low latency and high write speeds as possible (WITHOUT writing to a .dat file) and I've been running some speed benchmark tests.

During my benchmark tests, I've been writing some dummy data to a .csv file with one field being a the output of a timer (in microseconds) that measures how long it took for the loop() function to complete it's current iteration. I have code for other features of the project, but all of them are commented out in the loop() function so that the only two features currently running constantly is the SD logging function and the timer.

After running a test, I've found that the data writes usually take about 3200us (0.0032s) but randomly get spikes of about 10000us (0.01s) and once in a while even get a spike as large as 230000us (0.23s).

The time between spikes seem to be random.

I'm doing a flush() once every 100 iterations of loop().

The complete code and the resulting .csv are attached to this post.

My question is this: What is causing these random lag spikes? Is there anything I can do to eliminate these?

Thank you,
PB

Code_and_CSV.zip (495 KB)

The write action does not write directly to the card but to a software buffer; this is fast.

Once that buffer is full, the data will be written to the card; this is slow. Forcing a flush does the same thing and hence it's slow.

You can test by changing how often you flush (e.g. every 50 iterations of loop()).

PS
Can't look at your code.

I’m not sure you understood my post. I mentioned that I’m callin flush() at a consistent rate (every 100 iterations of the loop function) BUT the lag spikes are not every 100 .csv entries and are random.

You can view my code by extracting the zip file I attached and opening the sketch folder.

My question is still unanswered and I’m not sure why these lag spikes are occurring.