• Afaik it is not the writing 'per se', but the flipping of the bits that wears the silicon down.

    Depending on the architecture/construction/type of the FLASH EEPROMs, you can write just bytes, but you have to erase by pages.

    For your solution, with these assumptions:

    • your odometer reading fits into a block of 4 (or 8) bytes
    • you have a byte addressable and byte writeable EEPROM
    • your EEPROM has 256 bytes (for the example only)
    • your EEPROM has 256 bytes pages (for the example only, and for the first part, it does not even matter)

    I suggest to:

    • divide your memory space into two regions:

      • 1. space management - 8 bytes - 0..7 - bit by bit = 64 spaces - 64-bits
      • 2. odometer readings - 248 bytes - 8..255 - 62 blocks of 4 bytes for each reading

    You see that you have 2 more space management bits than you need to manage the 62 blocks for the odometer readings, which you will use for a different purpose - explained later.

    To write an odometer reading you proceed as follows:

    Find the the first non-zero (1) bit in the first 8 bytes starting with the 3rd bit . Byte and bit position adjusted by some constant tells you what block of 4 bytes you can use next.

    Since you already read the space management byte, you flip the found (1) to a zero and overwrite the the byte with the effect that only the flipped byte changes state only (and the bits 'before' that one do actually not matter). Then you write the four bytes with the odometer reading value.

    For the very first time / block, byte is 0, bit pos is 2, and 1st byte of odometer reading writing block is 8 - all values 0 based.

    After writing six (6) odometer readings, the byte will be 1, bit will be 0, and 1st block byte is 56.

    When you cannot find a 1 bit anymore, you know that your EEPROM 'is full', and for that reason you clear the 2nd bit of the first space management byte... because you may have more than one 256 bytes EEPROM for storage.

    Applying this to real world EEPROMs, you just scale this up:

    • each page contains its own space management area(s) and its data storage area(s).
    • each page has a bit telling when it is full
    • each page has a bit telling it can be eased (because some retrieval mechanism has read / consumed / freed the page)
    • with that you have a circular memory buffer / fifo...

    I know that flash EEPROMs are very cheap and have immense capacity... but thy also have the issue of wear and the need for delays on write, and need erasing. Therefore, I would look into alternatives, such as FRAMs and MRAMS: solid state memories that use polarized magnetized zones for storing bits. They have no wear and need no delays on write (you find them in some forum posts... )... and there are actually microcontroller chips on the market that do have FRAM/MRAM technology as RAM... so power can be turned of any time with no need to save the RAM somewhere and to have the buffered power left to do so (very simple setup for power supply, brown out and resume logic).

    On the other hand - being realistic - the wear of 100K writes combined with the size and the price should not be that a problem: just keep somewhere the information how many cycles you have run thru and then toss it out.

    Btw, sent you a message (see 'yellish' letter below your gravatar image in the top right corner of the page...

About

Avatar for allObjects @allObjects started