Hi !
I've been strugguling for a few weeks now with my project. It consists in writing in a SD card, data comming from an encoder. For 1 turn, the encoder gives 16 384 impulsions and its speed can go from 5 to 15 RPM (rotation per minute).
I used 3 bytes in order to write high state time and time between 2 impulsions. I store them into an array of 1024 * 3 bytes. To store data in the array , I use interruptions and ercaguy library to use a counter for the time.
My problem is that sometimes (~every 10 turns at 15 RPM, don't know why), I lose 2 or 3 arrays, which represents ~3000 impulsions. The problem comes from the writing on the SD card (see picture 1. Picture 2 and 3 show expected signals).
In order to write on SD card, I tried different ways (I used several (class 4 and 10) SD cards).
I used an tempory buffer and when it was full, I did a memcopy to another array in order to not overwrite data (because I knew that writing on SD was no that fast) and in my loop, I wrote data to the SD. This method didn't look to perform well, so I switch to another one.
I used two buffer. When one was full, I switch to the second one for the same reasons explained above. This method was better than the previous as I lost less data but I'm still loosing some...
I also tried to change my code as I read many forums : use file.flush() and file.sync() to force data to be written, when you call file.open(...), use O_WRITE | O_CREAT instead of FILE_WRITE, divide SPI clock to increase the speed, reduce the size of my arrays (it was even worther), but nothing solved my problem ...
Anyone can help me please ?
chronograms.zip (1.49 MB)