Shop OBEX P1 Docs P2 Docs Learn Events
Limiting EEPROM write burnout. — Parallax Forums

Limiting EEPROM write burnout.

jeffjohnvoljeffjohnvol Posts: 197
edited 2007-06-13 00:02 in General Discussion
Some of you may be familiar with my home project, but basically its a hillside lift that carries people and beer up and down a hill 150 feet.

My STAMP project, is to track the position of the cart to enable/disable switching plus some other stuff.· It will control relays that feed the motor controller.

I'm tracking the position of the cart by using an absolute encoder (0-5 volts for 0-360 degrees read by 12 bit ADC).· The cart is lowered on a cable, which is on a 12 inch drum.· It takes 44 drum rotations to get to the bottom.

One concern I have is to determine the cart location in the event of a power down and power up.· This happens all the time if we are not using the cart, we turn the key off which shuts down the power.· The cart could be at any point on the track.

My program maintains a drum count (how may times has it rotated a full revolution, 38 inches of cable) and the drum's current angular position from the encoder.· Upon power up, I can see the encoder position very easily since it is an absolute encoder, but the drum count is critical to know if the cart is at the top, bottom, or middle.

My plan is to write the drum count to the EEPROM each time it increments or decrements.· A full trip down and back up would be about 90 writes.· I'm using a BS2px which has a max (guaranteed) write cycle of 100,000 times.· I was amazed that the newer technology chip only had a 100K writes when the older modules (BS1, BS2) guarantee 10 million.

So at this rate, a slot would be used up after roughly 1,100 trips.· Although that would probably outlast many of the parts on my lift, I'd like to extend the life of my chip if can do it with a little programming.· I was contemplating having a scheme to rotate through the locations I write to, but this will require a fixed location to put the offset.· Question to the audience, have others done this, and if so, any things I should be considering?

FYI, I have all my inputs/outputs used up, so interfacing with an external eeprom would not be a good choice for me.
«1

Comments

  • Harrison.Harrison. Posts: 484
    edited 2007-06-07 14:09
    It would probably be much easier to just use FRAM (ramtron.com/doc/Products/Nonvolatile/Nonvolatile.asp?ID=5). They have extremely high endurance read/write cycles and usually last > 1 billion read/writes per location. Some of the 3.3v devices have unlimited read/write cycles, which is really nice for projects such as yours.

    The i2c versions function just like their eeprom counterparts. You can even remove the 10ms write delay in your code since FRAM parts can perform much faster write cycles.

    Harrison
  • jeffjohnvoljeffjohnvol Posts: 197
    edited 2007-06-07 14:28
    Sounds like an interesting product, especially with the time savings, but wouldn't I lose 3 I/O lines? I don't have many to spare.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-06-07 14:45
    This very question came up in an odometer context here. It might be worth perusing that thread for ideas.

    -Phil
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-06-07 15:09
    I’m with Phil…Comments I made in that thread are what I was about to post considering the FRAM chips are all surface mount. You may or may not want to deal with SMD parts on your project. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Dave HeinDave Hein Posts: 6,347
    edited 2007-06-07 16:03
    My initial thought was to use a capacitor to keep the BS2 alive long enough to write a value to the EEPROM when the power goes down. I read the thread Phil mentioned, and that is exactly what he proposed as well. The thread contains a lengthy discussion on how to do this.

    You could used the rotating location idea if you write a sequence number along with the position value. It sounds like there are only 45 positions, so this only requires 6 bits. You could use the 2 most significant bits as a sequence indicator. If you only use the values of 0, 1 and 2 for the sequence indicator the latest value will be indicated by a discontinuity in the sequence values. As an example, an 8-byte buffer could have the following values 0:13, 1:12, 2:11, 1:12, 2:13, 0:14, 1:15, 2:14. The value 2:11 would be the last one written because of the discontinuity in the sequence bit going from 2 to 1.

    Dave
  • BeanBean Posts: 8,129
    edited 2007-06-07 16:27
    You could gear down the drum turns by 5:1 and connect to a 10 turn pot.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    “The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • jeffjohnvoljeffjohnvol Posts: 197
    edited 2007-06-07 17:25
    Phil: Thanks for the link, I'm still in the process of reading the thread.

    Chris: You're right, surface mount chips are not what I prefer to deal with, and like I said earlier, I don't have the spare I/O lines for the serial.

    Dave: I don't follow the 2nd paragraph.

    Bean: I have considered this with a 3:1 reducer (45 tooth to 15 tooth) and a 15 turn pot. I have a 15 turn pot that would be perfect, its the size of a soup can cut in half. It would also be a nice way to have an additional "brake" for the drums if needed. Problem is that it would require about $200 of material.


    Does anyone know why the bs2px only has 100K writes versus 10 million for the cheaper stamps?
  • Dave HeinDave Hein Posts: 6,347
    edited 2007-06-07 19:04
    Here is some C code that implements what I'm suggesting.· Since I've been writing·in SX assembly I've forgotten the Parallax Basic syntax.· Note, this code works only if BUFFER_SIZE is not divisable by 3.

    Dave

    #define BUFFER_SIZE 64
    #define EEPROM_BUFFER_BASE ????

    static int sequence_number = 0;
    static int write_index = 0;

    // This routine combines the sequence number and the 6-bit value and writes it in the EEPROM circular buffer
    void WritePositionValue(int x)
    {
    ··· int value = (sequence_number << 6) | (x & 63); // Combine the sequence number and the 6-bit value
    ··· WriteEEPROM(value, EEPROM_BUFFER_BASE + write_index);
    ··· sequence_number = (sequence_number + 1) % 3;
    ··· write_index = (write_index + 1) % BUFFER_SIZE;
    }

    // This routine searches for the latest postion value in the EEPROM by locating an incorrect sequence value
    // sequence_number and write_index are initialized to the next values and the latest position value is returned
    int FindLatestPostionValue(void)
    {
    ··· int i, value, temp1, temp2;

    ··· temp1 = ReadEEPROM(EEPROM_BUFFER_BASE) >> 1; // Get the sequence number at the zero location
    ··· for (i = 0; i < BUFFER_SIZE - 1; i++)
    ··· {
    ······· // Get the sequence number from the next entry
    ······· temp2 = ReadEEPROM(EEPROM_BUFFER_BASE + i + 1) >> 1;
    ······· if (((temp1 + 1) % 3) != temp2) break;
    ······· temp1 = temp2;
    ··· }

    ··· // Extract the latest position value and initialize the sequence_number and write_index with the next values
    ··· value = ReadEEPROM(EEPROM_BUFFER_BASE + i) & 63;
    ··· sequence_number = (temp1 + 1) % 3;
    ··· write_index = (i + 1) % BUFFER_SIZE;

    ··· return value;
    }
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-06-07 19:14
    Jeff, what Dave is suggesting is called wear-leveling. By increasing the number of locations used to store the variable you increase the lifetime before burning it out by approximatly N times where N is the number of locations used to store the number. His use of unused bits is to let your program know which value is the most up-to-date value of the variable by looking for the discontinuity in the pattern of values. For this to work the number of locations N should not be an integer multiple of the maximum index value. Since he has 8 locations and 3 index values (0,1,2) his scheme is a valid index system for this purpose.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.

    Post Edited (Paul Baker (Parallax)) : 6/7/2007 7:20:13 PM GMT
  • metron9metron9 Posts: 1,100
    edited 2007-06-07 19:23
    If you are simply turning off the power to the stamp at a random point you still could have eeprom errors on writing at low power so a voltage monitor IC should be used to supply power the the stamp. Keeping the number in ram until actually turning the unit off would be the way to go given it is not safer to write eeprom under conditions of falling power because the memory location could be corrupt.

    So keeping the number in ram and writing it to eeprom with 2000 bytes to rotate through goves you 200,000,000 times to turn it on and off.

    Simply initialize the eeprom with $FF bytes, when the stamp powers up search eeprom for a location that contains $FF, drop back one address and load the previous saved value, write the next value to the address that contained the $FF

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • jeffjohnvoljeffjohnvol Posts: 197
    edited 2007-06-07 20:08
    Dave/Paul, I get it now. I understood saving the bits, but couldn't grasp the sequence. That makes sense now.

    metron9, that makes sense. It would save the need to have a location byte. That would cover 12 years of continuous use, lol.
  • Dave HeinDave Hein Posts: 6,347
    edited 2007-06-07 20:25
    Paul's description is much better than mine. I also have a couple of errors in my example code. The following line

    temp1 = ReadEEPROM(EEPROM_BUFFER_BASE) >> 1;

    should be

    temp1 = ReadEEPROM(EEPROM_BUFFER_BASE) >> 6;

    The same correction should be made for temp2 as well.

    One thing I realized is that you could get by with a single bit for the sequence number. This bit would actually indicate a pass through the buffer. It would be zero for the first pass, one for the second pass, zero for the third pass, and so on. The latest value will be at the point where the MSB changes from 0 to 1, or from 1 to 0.

    Dave
  • metron9metron9 Posts: 1,100
    edited 2007-06-07 20:27
    Actually about 90 years if you turned it on and off six times a day. There is no reason at all to write 44 values every time it goes up and every time it goes down, just once when power down. If you can't trust the ram because of power failure you cant trust the eeprom either so use the ram and monitor the voltage with a backup supply to write the eeprom on power failure.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • jeffjohnvoljeffjohnvol Posts: 197
    edited 2007-06-07 23:48
    metron9 said...
    Actually about 90 years if you turned it on and off six times a day. There is no reason at all to write 44 values every time it goes up and every time it goes down, just once when power down. If you can't trust the ram because of power failure you cant trust the eeprom either so use the ram and monitor the voltage with a backup supply to write the eeprom on power failure.

    Yeah, thats a decent point about not writing every iteration.· 99% of the time we'd be shutting it down when its at the top and the drum count would be zero.· The remote chance of a power failure (or powersupply failure) when its in mid trip or at bottom is pretty remote, and I can reset the starting point if that were to happen.· One possible way I can tell if it is at the top is the "top offset".· When the cart is at the top of the track, or zero position, the drum still has an angular position that I have to use in my calculations, because resetting it does not zero out the encoder.· I can store that offset value on a "start reset" and check it for plus or minus 5% of that value to see if its at the top.

    In the event of a major failure, or if I was having major problems with my stamp, I'm designing it so I can just turn the thing off and let it run with the normal motor controller logic which is fairly reliable.· I'm just using this controller to disable the "up" button when at the top, and disable the "down" button when at bottom.· Even though there are emergency shutdown limit switches, I'm the one that has to reset the system.· I'd like to kid-proof it.·

    Also, I am adding a center landing point, and the "call" button which brings the empty cart to a waiting passenger will require the stamp system to figure out whether to send the cart up, or to send it down.

    With the current setup, there are limit switches that tell the controller to ramp down the speed.· I'm leaving those because I trust hardware more than software, but the center stop will be software based.

    Sorry, more info than you needed, lol.
  • skylightskylight Posts: 1,915
    edited 2007-06-08 20:22
    Bear with me this might sound ridiculous at first but instead of using the stamps eprom to store the position what about using a mechanical form of memory device, ie a certain length of threaded stud driven directly by the drum, with a well greased nut travelling back and forth along this stud(if nut is suitably weighted gravity will stop it turning)·with a target attached to which you could fire a ping sensor at to determine the distance travelled to scale, or a length of thin wire attached to the nut through a pulley and weight arrangement where the weight operates a lever arrangement that compresses onto the flexiforce pressure sensor device. The stamp could have lookup tables to determine the distance travelled.

    A certain amount of experimentation and calibration·would hopefully give fairly accurate results.

    Post Edited (skylight) : 6/8/2007 8:28:50 PM GMT
  • metron9metron9 Posts: 1,100
    edited 2007-06-08 22:51
    Skylight, are you related to Rube Goldburg?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2007-06-09 01:01
    jeffjohnvol--

    How about a pipe and just PUMP the beer to the top of the hill? 150 feet of PVC shouldn't cost much.

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • skylightskylight Posts: 1,915
    edited 2007-06-09 18:00
    metron9 said...
    Skylight, are you related to Rube Goldburg?

    Who is Rube Goldburg?smile.gif
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-06-09 18:19
    en.wikipedia.org/wiki/Rube_Goldberg For those forum members in the U.K., he's the U.S. equivalent of your Heath Robinson.

    -Phil
  • skylightskylight Posts: 1,915
    edited 2007-06-09 18:32
    Phil Pilgrim (PhiPi) said...
    en.wikipedia.org/wiki/Rube_Goldberg For those forum members in the U.K., he's the U.S. equivalent of your Heath Robinson.

    -Phil
    Thanks LOL
  • skylightskylight Posts: 1,915
    edited 2007-06-09 18:40
    Sorry for being too Rube Goldberg tongue.gif but my idea was extending on the mechanical apparatus as it stands now, keeping the memory problem in mechanics and then converting beyond to read the state using electronics, a sort of shifting the goalposts if you understand my meaning.
  • jeffjohnvoljeffjohnvol Posts: 197
    edited 2007-06-10 02:16
    skylight said...

    Bear with me this might sound ridiculous at first but instead of using the stamps eprom to store the position what about using a mechanical form of memory device, ie a certain length of threaded stud driven directly by the drum, with a well greased nut travelling back and forth along this stud(if nut is suitably weighted gravity will stop it turning)·with a target attached to which you could fire a ping sensor at to determine the distance travelled to scale, or a length of thin wire attached to the nut through a pulley and weight arrangement where the weight operates a lever arrangement that compresses onto the flexiforce pressure sensor device. The stamp could have lookup tables to determine the distance travelled.

    A certain amount of experimentation and calibration·would hopefully give fairly accurate results.

    An interesting project, but I'm too far along my current path.· Thanks.
  • jeffjohnvoljeffjohnvol Posts: 197
    edited 2007-06-10 02:17
    Bill Chennault said...

    jeffjohnvol--

    How about a pipe and just PUMP the beer to the top of the hill? 150 feet of PVC shouldn't cost much.

    --Bill

    The goal is to get the beer down the hill, thats where the boat is [noparse]:)[/noparse]
  • skylightskylight Posts: 1,915
    edited 2007-06-10 14:39
    jeffjohnvol said...
    Bill Chennault said...

    jeffjohnvol--

    How about a pipe and just PUMP the beer to the top of the hill? 150 feet of PVC shouldn't cost much.

    --Bill

    The goal is to get the beer down the hill, thats where the boat is [noparse]:)[/noparse]
    In that case remove the pump and let gravity do it's jobsmile.gif One problem though,·you'll need some eprom to store how many pints of beer have been cosumedlol.gif
  • metron9metron9 Posts: 1,100
    edited 2007-06-10 14:58
    The pipe is ok but now you have three more problems to solve.

    1. That is a lot of beer in a pipe, it is a warm or hot day and now the beer is warm.
    2. Pipes need to be cleaned
    3. thats 75 PSI at the nozzle from gravity. The beer is carbonated as well so I think you may just have foam now.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • skylightskylight Posts: 1,915
    edited 2007-06-10 15:22
    metron9 said...
    The pipe is ok but now you have three more problems to solve.

    1. That is a lot of beer in a pipe, it is a warm or hot day and now the beer is warm.
    2. Pipes need to be cleaned
    3. thats 75 PSI at the nozzle from gravity. The beer is carbonated as well so I think you may just have foam now.

    I have a feeling the beer won't be in the pipe long enough to get warm smilewinkgrin.gif
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2007-06-10 20:10
    jeffjohnvol--

    I get it, now.

    I don't know how many vertical feet of drop there is from the top to the bottom of the hill, but I am dreaming of the "beer pressure" at the spigot of that PVC located at the BOTTOM of the hill! [noparse]:)[/noparse]

    My back yard ends in a cliff that drops (not straight down) to the lake owned partially by me and partially by the golf course. The vertical drop is only about 40 feet. I built some rock steps, but they are a true pain to navigate if you are caring anything. (Building those steps with 300 pound rocks is a story in itself!)

    We are supposed to do some work on the lake next year. If we do, I am going to need plans for your device.

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • jeffjohnvoljeffjohnvol Posts: 197
    edited 2007-06-12 16:51
    Bill Chennault said...
    jeffjohnvol--

    I get it, now.

    I don't know how many vertical feet of drop there is from the top to the bottom of the hill, but I am dreaming of the "beer pressure" at the spigot of that PVC located at the BOTTOM of the hill! [noparse]:)[/noparse]

    My back yard ends in a cliff that drops (not straight down) to the lake owned partially by me and partially by the golf course. The vertical drop is only about 40 feet. I built some rock steps, but they are a true pain to navigate if you are caring anything. (Building those steps with 300 pound rocks is a story in itself!)

    We are supposed to do some work on the lake next year. If we do, I am going to need plans for your device.

    --Bill

    The problem with the lower spigot is that I can't take it on the boat, lol.· Its a 90 foot vertical drop, with about 150 ft straightline.· Its roughly 30 degrees slope.

    I'd be happy to share the plans with anyone.· My dad can even build the motor controller panel if you didn't want to use a stamp.· We use a motor controller that takes 220volts and drives a 3 phase VFD motor to run the cart up or down.

    Here are some vids of it, but these are a little old.· I've done more to in since then:

    http://www.youtube.com/watch?v=AbFDJBHZUqE
    http://www.youtube.com/watch?v=-jNwK68F8ps
    http://www.youtube.com/watch?v=CLjmnQte-JM

    I'm in the process of programming a stamp to control/redirect inputs to the system because I want to add a center landing, and to do so, I need some logic to determine which way to send the cart when it is "called" (we have it setup like an elevator, you can call it to you if its on the opposite end).
  • skylightskylight Posts: 1,915
    edited 2007-06-12 17:33
    Absolutely brilliant seeing the lift on video, You guys are so lucky to live where you do with so much space, i'd love to build something like that but I don't think the local council would take kindly to granting planning permission for something like that in my 70' garden smile.gif besides i'd get nothing else done around the house i'd be so busy riding up and down on it lol.gif
  • jeffjohnvoljeffjohnvol Posts: 197
    edited 2007-06-12 17:56
    Thanks. It was a fun project. People I worked with didn't believe I would be able to build it. "You're building what?". It was fun to show them when it was done. I just wish I lived there now. Its a summer place and a 6 hour drive.
Sign In or Register to comment.