I want to constantly store data to sd. But how I make sure data is not corrupted on moment of power off? I think I could add small capacitor on 5V and check when voltage drops, so I would stop data write. Or is there better solution for safe data write?
2 Answers 2
I think a "small" capacitor here is not going to do the job as you need to keep power stable until the write is completed. You need to determine:
- How much power am I using?
- How quickly can I detect a power outage?
- How much time do I need to keep power on the Arduino to complete the write operation(s) I want to complete.
Then you will be in a position to calculate how much capacity you need and whether a capacitor or battery is more appropriate.
-
well data is written in probably microseconds, so I 3300uF or something would be enough for short period of time. Question - is that proper way to do it? Discharging capacitor will reduce it's voltage, so I have no idea what could happenName– Name2020年12月04日 20:44:57 +00:00Commented Dec 4, 2020 at 20:44
-
1You're just guessing on both how much time and how much reserve you need. Take measurements and do calculations. That's engineering.jwh20– jwh202020年12月04日 21:28:23 +00:00Commented Dec 4, 2020 at 21:28
-
Also calculate the odds of having a power outage, right when you are writing to the SD card. If you, for example, only write once every 15 minutes, the odds are very low. Combined with the chance of a power outage, it might not be worth you time to try to prevent.Gerben– Gerben2020年12月05日 16:19:20 +00:00Commented Dec 5, 2020 at 16:19
You're probably going to want to look to various forms of NVRAM (Non-volatile RAM). SRAM with an automatic save to EEPROM function on power loss, e.g. 47L16. Or battery backed RAM; if you have a real-time clock in your project you may have some limited storage in it. E.g., the DS1307 has 56 bytes, although you can probably find a more accurate RTC that has storage in it. Or FRAM, though it's as bit expensive, e.g. cy15b064q-sxet
In any case you'd probably want to write your data out in blocks with CRC so that you can make a determination on whether or not a partial write was done when reading back later.