Go Down

Topic: Save data in nonvolatile memory (Read 1 time) previous topic - next topic

MostafaHamdy

I make project counting object , I use eeprom to store data when reset board start counting from where i have left from the previous count
but i'm worry because i use it to store data 300 time in day ,I don't know if the repeating of store data in eeprom will make problem in long time because i read There is a limited number of write cycles available for eeprom and i want to know if it safe or not &
if i use SD card ,Is it better than eeprom or not ? & if SD card better ,How i save data with address ?

Thanks :D


pylon

Flash memory usually allow about 10'000 write operations. The EEPROM allows about 100'000 write cycles till it gets unreliable. An SD card has the same restrictions but there you have an intelligent controller on the card reordering the write operations in a way that the blocks written to change in every write operation. This way you can use an SD card more like a hard drive but the limitations still apply.

If your project includes an RTC use the nonvolatile RAM they offer because that memory area can be written as many times as you like.

MostafaHamdy


Flash memory usually allow about 10'000 write operations. The EEPROM allows about 100'000 write cycles till it gets unreliable. An SD card has the same restrictions but there you have an intelligent controller on the card reordering the write operations in a way that the blocks written to change in every write operation. This way you can use an SD card more like a hard drive but the limitations still apply.

If your project includes an RTC use the nonvolatile RAM they offer because that memory area can be written as many times as you like.

yes i have RTC in my project to show date and time for each object but i can't  understand you in this point (
Quote
RTC use the nonvolatile RAM they offer because that memory area can be written as many times as you like

How use the nonvolatile RAM ?
i know RAM is volatile memory !

tuxduino

From:

http://www.sparkfun.com/datasheets/Components/DS1307.pdf

Quote

56-byte, battery-backed, nonvolatile (NV)
RAM for data storage

MostafaHamdy

I use RTC (http://tronixstuff.wordpress.com/2010/05/28/lets-make-an-arduino-real-time-clock-shield/) in my project with RTC library to save date and Time i don,t know the code to save count values into it , can help me with simple code ?

pYro_65

If your project includes an RTC use the nonvolatile RAM they offer because that memory area can be written as many times as you like.


That is a nice feature, providing some battery backed up RAM. I guess the data dies when the battery dies, right?

MostafaHamdy


If your project includes an RTC use the nonvolatile RAM they offer because that memory area can be written as many times as you like.


That is a nice feature, providing some battery backed up RAM. I guess the data dies when the battery dies, right?

yes , this is good point but i think the battery is long life battery and it will stay for long time

Nick_Pyner


yes , this is good point but i think the battery is long life battery and it will stay for long time


The battery life is utterly meaningless. Much more to the point is how much data do you need to store, and will it fit in 56 bytes? 

PeterH


I make project counting object , I use eeprom to store data when reset board start counting from where i have left from the previous count
but i'm worry because i use it to store data 300 time in day ,I don't know if the repeating of store data in eeprom will make problem in long time because i read There is a limited number of write cycles available for eeprom and i want to know if it safe or not &
if i use SD card ,Is it better than eeprom or not ? & if SD card better ,How i save data with address ?

Thanks :D




You'll have to work out how to store the count, how many times it needs to be updated and what the reliable storage life will be. An approach which others have suggest in the past is to use multiple EEPROM storage locations, advancing to the next location when the number of updates to the current location exceeds the safe limit. For example you could store a counter in the first two bytes of EEPROM which you use to count from 0 .. 50,000; when it reaches 50,000 you leave it and start counting 0 .. 50,000 again in the next two bytes, and so on for as long as necessary. To get the instantaneous value you simply walk through the EEPROM reading two-byte pairs and accumulate them until you reach a terminating marker; the last cell before the marker is the entry that needs to be incremented to update the stored value.

Another approach that was suggested was to put a capacitor on the input supply that allowed the Arduino to continue running briefly after power was removed - just long enough to flush the current counter from RAM to EEPROM. That way the EEPROM update only needed to be performed once per power cycle so wear was not a problem.
I only provide help via the forum - please do not contact me for private consultancy.

LROBBINS

#9
Jan 22, 2013, 08:10 pm Last Edit: Jan 22, 2013, 08:13 pm by LROBBINS Reason: 1
Another approach to EEPROM limits is to use a ring memory, you can then shift around the ring periodically spreading the read/write operations over several addresses.  Here's a snippet where I create a 20-byte ring (starting at byte 20 of the EEPROM) during setup using one additional byte (in byte 0) to store the current address of where by data is stored.  The data's location shifts around the ring once each time the sketch is started.  Here, I am storing 1 byte of data and my worst case guess is that it will be read ten times and written 210 times each day, while the processor will be re-started about 10 times a day.  Thus, the byte where the data address is stored will be reliable for 100000/10 days, or 27+ years, and the ring will last 100000*20/220 days, or about 25 years.  If your data updates more frequently, you need a bigger ring, and if you need more than 254 cells, your address will need to be stored in 2 bytes instead of 1.  (The Serial.print statements are there just so that I can see what happens at startup; they will be gone in actual use.  The ring doesn't start at byte 1, but at byte 20, because I will use the low bytes to index other rings.)
Code: [Select]
 ModeAddress = EEPROM.read (0); // address where Mode value was last stored
 if (ModeAddress == 0){
   Serial.println (F("A Mode value has not yet been stored"));
   ModeAddress = 20;
 }
 else {
   Mode = EEPROM.read (ModeAddress);
   Serial.print (F("Stored Mode = "));
   Serial.print (Mode);
   Serial.print (F(" in byte "));
   Serial.print (ModeAddress);
   ModeAddress = ModeAddress + 1;
//  EEPROM memory ring runs from address 20 through 39
   if (ModeAddress > 39){
     ModeAddress = 20;
   }
 }
 EEPROM.write (0, ModeAddress); // address where Mode will be stored
 EEPROM.write (ModeAddress, Mode); // re-stored in new address
 Serial.print (F("   Mode will now be stored in byte "));
 Serial.println (ModeAddress);

Ciao,
Lenny

pylon


I use RTC (http://tronixstuff.wordpress.com/2010/05/28/lets-make-an-arduino-real-time-clock-shield/) in my project with RTC library to save date and Time i don,t know the code to save count values into it , can help me with simple code ?


This is how I save a position (two integer values) into the non-volatile RAM of the DS1307:

Code: [Select]
#define DS1307_ADDRESS 0x68
uint8_t address = 0x30;
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(address); // Storage address 0x30
byte b1, b2, b3, b4, b5;
b1 = left >> 8;
b2 = left & 0xff;
b3 = right >> 8;
b4 = right & 0xff;
b5 = b1 ^ b2 ^ b3 ^ b4;
Wire.write(b1);
Wire.write(b2);
Wire.write(b3);
Wire.write(b4);
Wire.write(b5);
Wire.endTransmission();


And this way it's read again:

Code: [Select]
#define DS1307_ADDRESS 0x68
uint8_t address = 0x30;
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(address);
Wire.endTransmission();

byte b1, b2, b3, b4, b5;
Wire.requestFrom(DS1307_ADDRESS, 5);
b1 = Wire.read();
b2 = Wire.read();
b3 = Wire.read();
b4 = Wire.read();
b5 = Wire.read();
if ((b1 ^ b2 ^ b3 ^ b4) == b5) {
*left = b1;
*left <<= 8;
*left += b2;
*right = b3;
*right <<= 8;
*right += b4;
return 1;
}
return 0;


This includes a 5th byte to save a checksum (simple XOR) to check if the position was saved correctly. Adapt it to your needs.

Go Up