12F675 EEPROM Wear leveling

Author
crisco886
New Member
  • Total Posts : 7
  • Reward points : 0
  • Joined: 2012/06/20 14:14:31
  • Location: 0
  • Status: offline
2012/10/16 07:16:15 (permalink)
0

12F675 EEPROM Wear leveling

I've been working on a product with EEPROM. Every time the product has a power loss I store data to EEPROM. Just two locations so the write happens rather quickly. I was cycling one of the products in an oven (worst case scenario for EEPROM life) and I got one to fail around 80k cycles. This got me thinking if there was a way to extend the EEPROM life by writing to a different location every time to equally "wear" out the EEPROM. I've done some searching and it seems like some people do this. I was wondering if anyone had any experience with it on a 12F675 or if you had any suggestions as to a good starting point. I'm running out of space so I can't have a gigantic routine to do this.  
  
If/When I figure out a way to do this I will post my code and thoughts.  
  
Thanks 
 
Edit: I apologize I posted in the wrong thread so I reposted here. 
  
  
#1

3 Replies Related Threads

    Ian.M
    Super Member
    • Total Posts : 13224
    • Reward points : 0
    • Joined: 2009/07/23 07:02:40
    • Location: UK
    • Status: offline
    Re:12F675 EEPROM Wear leveling 2012/10/16 07:29:51 (permalink)
    0
    In the other subforum, open your post and click the manage message link below it.  If you are lucky, it will offer you a delete option, but you must type a reason - like "wrong forum". I've replied here as I don't know if it will let you delete it if there are any replies.
     
    To simply increase endurance by a factor of 16, if you have a multi-byte counter in the EEPROM, use 4 bits from one of the high byte (at a fixed location) to index between 16 blocks of EEPROM data that each hold the low byte of the counter and any other data that changes frequently.  Only update the high byte if the low byte of the counter in the current page overflows. 
     
    Its also worth writing your power loss code so it waits a few seconds after power is restored before permitting any further writes or you can chew through your endurance very quickly if the supply has a lot of glitches
     
    #2
    crisco886
    New Member
    • Total Posts : 7
    • Reward points : 0
    • Joined: 2012/06/20 14:14:31
    • Location: 0
    • Status: offline
    Re:12F675 EEPROM Wear leveling 2012/10/16 07:45:00 (permalink)
    0
    Thanks for the fast response Ian. I don't think I made myself clear enough. I'm not just counting power loss cycles. I am storing data into two EEPROM locations. The data will potentially be different each time. I was hoping to do something like write to a different location every time, cycling through all 128 locations or write to one location 50k times and then switch to a new location for another 50k. Both of these options require the code to "know" where it wrote to EEPROM last time. Which would require me to have an EEPROM location that stored that data, and that brings me right back to where I started. 
     
    The EEPROM delay write is a good idea. I have a count and delay to make sure there is an actual power loss before EEPROM write. After EEPROM writes I have a lockout bit I set so that I can't write again until the unit actually cycles power. 
     
     
    #3
    Ian.M
    Super Member
    • Total Posts : 13224
    • Reward points : 0
    • Joined: 2009/07/23 07:02:40
    • Location: UK
    • Status: offline
    Re:12F675 EEPROM Wear leveling 2012/10/16 08:14:51 (permalink)
    0
    That's why you *MUST* add a counter - if you don't have something that increments sequentially every time you need to store your power loss data, you cannot track the wear so cant implement wear levelling. 
     
    The strategy above basically writes a data set to the current block 256 times then moves on to the next block. As the high byte of the counter is only updated at 1/256 of the rate of the other data, it does not wear out quickly and you can use it to locate which block is currently active.  The low byte of the counter is kept in the current block.
     
    You could have 16 x 7 byte blocks, one byte of each being lost to the counter, giving you 6 bytes of 16 x endurance user data storage for a total cost of  113 bytes of EEPROM, or if you went to a 5 bit block number, you could have 32 x 3 byte blocks giving you 2 bytes of
    32 x endurance user data storage for a total cost of 97 bytes of EEPROM.
     
    The 5 bit block number 32 x endurance, would extend the worst case extended temperature range endurance of 10K writes/byte to 320K writes.  If you can guarantee that you don't write a block more often than once every 5 seconds, that gives you over thee years endurance even if the power fails every 5 seconds 24/7.   When you run out of theoretical endurance, or maybe when you start getting write errors, program three "EEPROM Fail" bytes with 0xA5 that were originally programmed as 0x5A and are never otherwise written.   If any of the bits in any of those bytes have been flipped, you know you cannot trust the whole EEPROM.
     
    Finally, don't store anything critical at location 0!  It is advisable to always clear EEADR after use so a rogue write caused by something crashing the PIC doesn't smash anything important.
     
     
    If you are using external EEPROM ,you need to make sure that your data blocks are aligned on write/erase page boundaries.  Not a problem for the internal EEPROM as it has true byte access.
     
     
     
    #4
    Jump to:
    © 2019 APG vNext Commercial Version 4.5