EEPROM wear leveling

Hello. I need to write some value very often in EEPROM. I'm thinking about some wear levelling algorithm to distribute write operations over some memory area. For example, use an index stored in other EEPROM area to write that value in a different location every time and to know where the actual value is stored. But I have a problem at start up. How to know if index stores a correct location or it stores garbage from the very first start up. I can add a function to reset the index area and a procedure to use that function before to use my invention. Any other ideas? Thanks in advance.

[quote author=Jose Francisco date=1456529579 link=msg=2635312] Hello. I need to write some value very often in EEPROM. I'm thinking about some wear levelling algorithm to distribute write operations over some memory area. For example, use an index stored in other EEPROM area to write that value in a different location every time and to know where the actual value is stored. But I have a problem at start up. How to know if index stores a correct location or it stores garbage from the very first start up. I can add a function to reset the index area and a procedure to use that function before to use my invention. Any other ideas? Thanks in advance. [/quote]

When EEPROM memory is erased (initial State) it contains 0xFF. As long as your value cannot be 0xFF you could scan down from the top of EEPROM starting at address 1023. keep reading the values and decrementing the address until you encounter a value that is not 0xFF. That marks your most recently used storage location.

Chuck.

Thanks
I thought that when you buy a microcontroller its EEPROM contains random values.
Thanks again

[quote author=Jose Francisco link=msg=2635656 date=1456563623] Thanks I thought that when you buy a microcontroller its EEPROM contains random values. Thanks again [/quote]

Normally they are 0xff, it is part of the mfg test cycle. But, as you alluded, Assume nothing! You could write a sketch that initialized your Arduino, run it, then load your actual Sketch.

Chuck.

It's depends on how much data you have to write. One approach is to make 'blocks' of data and implement versioning. For example: you write 'version' number at the beginning of block, then data in the block. Next time you write something, you pick up next block, write version number+1 at the beginning etc. At boot, you need to scan all blocks to check which one was last modified (check where sequence breaks, don't search for highest id). This way you don't need to rely on erased cells (0xff), you could also write from the start of memory right after you reach it's end.