Data storage in EEprom
Jon M
Posts: 22
Hi,
I have a problem, which I am hoping all you clever bods out there can help me with.
I need to store data to eeprom on a regular basis.· However, with eeprom I can only write to a location so many times before it will fail.·Does anyone have a routine that will cycle the memory locations my data will be stored and retreived from.· The routine needs to remember the last used memory location even when the power is removed from the BS2p40.·
Thanks
Jon Millard
I have a problem, which I am hoping all you clever bods out there can help me with.
I need to store data to eeprom on a regular basis.· However, with eeprom I can only write to a location so many times before it will fail.·Does anyone have a routine that will cycle the memory locations my data will be stored and retreived from.· The routine needs to remember the last used memory location even when the power is removed from the BS2p40.·
Thanks
Jon Millard
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
I thought the write times was limited to about 100000 or so. Anyway, I have developed an electrical system that I use in office equipment that can be installed and operational for many years. I use the storage for life counters, document counts etc which gets stored after every batch of forms has been processed, or when document jams occur. Unfortunately, I don't think I would be able to add additional hardware without redesigning my PCB etc. Therefore I need to find a software solution if it is possible.
the data I need to store are
forms_low.LOWBYTE
forms_low.HIGHBYTE
Forms_high
life_count
counter
Thanks
Jon Millard
RecNum····· DATA·· 0
FrmsLo0·· · DATA·· Word 0
FrmsHi0···· DATA·· 0
LifeCnt0··· DATA·· 0
Cntr0·······DATA·· 0
FrmsLo1···· DATA·· Word 0
FrmsHi1···· DATA·· 0
LifeCnt1··· DATA·· 0
Cntr1······ DATA·· 0
Since the number of bytes per "storage record" is fixed at five,·update·the·EEPROM like this:
· READ RecNum, record
· eePntr = FrmsLo + (record * 5)
· WRITE eePntr, Word formsLo, formsHi, lifeCount, counter
This doesn't address the the issue of making a copy of the previous record set which you'll want to do for retrieval after a possible reset.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
I don't know how often you record new data, but with an AT45DB041B EEPROM, if you recorded 8 bytes every hour the EEPROM would last for almost 8 years.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
· record = record + 1 // 5
· WRITE RecNum, record
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Do you use real time in your system as well? Real time clocks like the DS1302/1307 have some free RAM onboard which can be made 'Non Volatile' using a backup battery or capacitor.
You can write to this NV-RAM as many times as you like.
Regards,
Klaus
Thanks to you all
Jon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
My final design is to have a counter that counts how many times a "storage" cell has been written onto, and once that count reaches a particular value(in my case, 0) it moves to the next designated cell.
In my application, a variable that will be saved to the eeprom will have eight memory cells allocated to it, four for the counters and four to store the variable value. For example, VarA will use memory address 0-7 with 0-3 being the counters with each cell having a value of 255 when the stamp is programmed. Cells 4-7 will hold the current value of the variable and the cell the holds the current value depends on which counter is being used. In other words, if counter 0 is being used, VarA will be written on 4, if counter is 2 then VarA will be written on 5, and so on.
A routine in my application will perform the following when saving to eeprom:
1) Determine which counter cell is being used (cell that does not have a value of 0) and its address.
2) If all counter cells are zero, write 255 on all of them and then set the counter cell that is being used as the first cell in the counter group.
3) Once the address of the cell counter is determined, the address of the storage cell can be determined with a simple math. In the example above, it will be the address of the cell counter plus 4.
Here is the code for my routine:
I hope that helps.