I am working on a device that uses the Microchip MDDFS library to store data to an SD card. The logger will log data at a maximum rate of 1 entry (56bytes) every minute. The problem is the device may lose power at any time, potentially in the middle of a write sequence. I am wondering what is the best way to protect my data against corruption. I have found that if the file is open when the power is lost, all data that was written to the file after the last file-close is lost. I don't know if the same holds true if power is lost in the middle of the write sequence.
Since the write procedure doesn't happen very frequently I could open the file, write the data, and then close the file, every time data is logged. Would this approach damage the sd card over time?
Another approach could be to keep the file open but after every 10 or 50 writes I could close the file and then re-open it.
I could also buffer data in memory, then flush the data occasionally maybe after a kbyte or so.
The last idea I had was, in my circuit, I could add a large capacitor that would provide power to my pic/sd card long enough after the power is disconnected to quickly close the file. The problem with this approach is that the time it takes to close the file and/or save data is very inconsistent. From my understanding, this time can very depending on the current place in a flash page that the file is in.
Anyways, what would you guys suggest?