How to deal with counters on a range of millions and save value to EEPROM

Hello to all,

Im working on a project that requires counting cycles on the order of millions and saving the value in case there is a power failure or in case the machine is turned off at the end of the day and restarted in the morning, to continue counting from where it left.

The set up consist on an absolute encoder coupled to a shaft of the machine. That gives the angular position of the shaft, needed to take certain decisions. (that part is up and running no problem) Th same encoder is used to count the cycles, every time it crosses zero degrees, adds one to the counter. (no problem with that part it is up and running) I need the value of the counter saved to the EEPRMO (or other device) and read it back at power up so that the counter can continue where it left. (no problem with that, it is up and running)

The problem that Im not sure how to dela with, is the number of write cycles of the EEPROM (100,000).
The machine Im working on, runs aprox. 60,000 cycles per day, so 100,000 will be reached aprox. in one and a half days.

I researched on EEPROM ware leveling, but it is hard for me to understand how it works and how to write de code. (not a lot of experience programming)

I have though on using an external EEPROM which can be changed when worn. (not very elegant solution)

I have though on using an external storage devices that can handle way over 100,000 cycles (not sure which)

Im sure there are better ways to handle this, but my knowledge is very limited.

I will very much appreciate if someone can point me in the right direction.
Thanks so much in advance,
Regards
Felipe

Your project has been asked questions about before, especially the count saving part. Search for that proj!

External FRAM

You might want a non-volatile, unlimited write endurance storage.

Say hello to MRAMs

I myself would like to have one of this for testing and write drivers for. These can come very handy for applications such as yours.

Worth a look - post #5: Arduino Forum

Can you describe your plan to tell the Arduino that the power is going to fail or the machine is going to be turned off?

Will your machine ALWAYS be at the same state as when the power went off?

Paul

Are you talking about 1 cycle per second? (60.000 -- 86.400 seconds/day)

Here´s an idea, maybe it´s useful:

You could use 2 bytes of EEPROM per day, saving unsigned integers (up to around 65.5K) every 2 bytes of EEPROM.

The next day, shift the saving to the next 2 bytes... and so on.

You could use the first bytes of EEPROM as a) pointer to where in EEPROM are you storing data for the current day, plus b) a long integer with total of the cycles stored (you only increment it once a day, with the current day total, before shifting to the next pair oy bytes in EEPROM).

With 1024 bytes of EEPROM you could save about 500 days of data. Then, you just replace the Arduino! :slight_smile:

Saludos!

Thank you so much to all fo you for the super fast answers and ideas.

Paul_KD7HB:
Can you describe your plan to tell the Arduino that the power is going to fail or the machine is going to be turned off?

Paul, excellent question, I do not have a plan to tell the Arduino the power is going to fail. Actually I did not know I needed one.

Paul_KD7HB:
Will your machine ALWAYS be at the same state as when the power went off?

Paul

Im sorry but I do not understand you question.

hzrnbgy:
You might want a non-volatile, unlimited write endurance storage.

Say hello to MRAMs

https://www.mouser.com/ProductDetail/Everspin-Technologies/MR10Q010SC?qs=NK6InXoXhq6oeIhNR5InTA%3D%3D

I myself would like to have one of this for testing and write drivers for. These can come very handy for applications such as yours.

This is something I will definitely investigate Tanks !!!

dougp:
Worth a look - post #5: Arduino Forum

This post really opened my eyes. Can I instal a very small Lipo battery as a back up to have a chance to save to the EEPROM whenever the power goes off, either for a power failure or for machine turned off.
In that way, I will only write to the EEPROM 1 or maybe 2 times per day.
Right now I write to the EPPROM every cycle, about every second.

Thanks again.
Felipe