Hello Nordic gang.
I'm reading sensor data on the nrf9160DK, the sensors have a fifo with 96 entries. If I can't read the sensors fast enough, the fifo overflows and I get data loss.
The sampling rate is 4000 SPS and the sample size is 64bit. Therefore, there is not enough RAM to hold data and there is a need of continuously writing data to memory.
Now, I have integrated a micro sd card, it writes fast, faster than the external flash. If I do a measurement of 20 seconds, sometimes there is no fifo overflow but sometimes there are 2-3 entries being lost during the recording. I find it interesting that it is inconsistent.
However, it is extremely close to being fast enough, and sometimes it actually is. Now, as for solutions I've been considering multi-threading.
The write speed is fast enough and the fifo queue is decreased to its lowest value but then we reach entry #64, there is a delay. I'm guessing this has to do with the cluster or page size of the FAT32 format and the allocation of new memory units takes a bit of time. Every multiple of 64 there is a delay. Each entry is 64 bits so it's every 4096 bits this occurs.
Sometimes this resizing makes the queue overflow but not always. Sometimes it goes from 0 to 40 entries in the fifo, which is fine, other times it goes from 0 to 96 and we have data loss. I thought that maybe you could multithread this so that during the write, we still take down data from the fifo and store it in a variable until the write function is done, thus ensuring there is no data loss. Would this be possible? If so, how is it implemented in code?
I've been using fs_write when writing to a file on the sd card.
Edit: The idea I had was to implement a fifo structure where data from sensor is continuously added and written to memory. Thus, under cluster allocation delay, the fifo grows while waiting for the sd-card.
Thanks for brainstorming with me
Warmest regards
nWre
