I have made myself a simple up/down lift with a shelf I can place stuff on. All electric. It has a motor, and a rotary encoder for counting the pulses and thus the position of the shelf. The favourite-position of the shelf can be saved with a buttonpush, so that when the motor/shelf passes by this position, it halts and you have to lift and press the button to get it going again.
So far so good.
Now, if I turn the machine off. It forgets electronically where the shelf was. And the pulses starts again at Zero no matter where the shelf is situated at. But the favourite-position of where the shelf is supposed to halt is still saved in EEPROM. But because it resets and forgets its current position of the shelf, the saved favourite-position isnt at the same place anymore to where it should be...
The problem is that if I make it f.e. save the shelf-position constantly, after each time I go up and down. It will wear out the memory quite fast.
One good thing is that the lift cannot change its position mechanically without the motor going, so it wont un-calibrate itself especially much. Because it really locks in its position when turned off.
And by the way it is not super-important that it knows exactly where the motor is for months and months onward. If it by time goes outside its limits by some centimeter, I just need to save my favourite-position again. I want to avoid any type of re-calibration, like always going down to a sensor to get its start position or something like that. I need to be able to leave it for 2-3 days, and then just go back to using it like before.
But it is run on battery, 24V 10A, so that is also important in the equation.
The machine dont have a on/off button, its supposed to go into hibernation/sleepmode after a while (currently not in the code) and then wake up when pressing up or down.
So how could a OK solution look like?
I have gotten some suggestions, wich looks like this.
It saves its position everytime i have gone up or down, this will wear out memory faster.
It saves its position when it has been in-active for 5 minutes.
It saves its position before going into sleepmode (currently dont have sleepmode).
It does never save its position, because it never looses it because chip is being kept alive with battery or capacitor connected to it. This MAY draw too much power in the long run.
Now I dont know wich one would be more energy efficent. Or if there exist maybe a more smart solution to this? Or if alternative 4 is even possible, and will run out of power too fast that way.
I want it to somehow remember its position at least 3-4 days after last being used.
Have I missed something important with these suggestions? Or in my way of thinking?
And by the way can sleepmode work with this? I got both interrupts busy with the rotary encoder, and this Arduino UNO dont have more interrupts of that kind of what I understand I need that for sleepmode?
So what do you think I should do? How should I approach this problem?
How can I solve this?
Every time the system is powered up, it needs to go through an initialization that sets the encoder "home" position. Most people do that by driving to "home", using a limit switch to detect the location.
You say you don't want to power it off and put it into sleep mode. If that's the case you're done. As long as you don't power cycle it it will remember it's position just fine
But normal for systems like that is t have some sort of end switch. That's the only way it can nog it's position for sure* Or a switch on every shelf location.
Add a home switch, and move to that position on each power-up.
Ensure it CAN'T move when power is off, save the last known position, and re-load that on power-up.
Your concern about EEPROM life seems WAY over-blown. IIRC, the EEPROM is good for at least 100K writes PER LOCATION. If you use a single byte, and turn the system on 10X/day, EVERY day, 365 days/year,it should last about 27 years! If that is not enough, you can add an external serial EEPROM, for under $1, that will be good for at least a million cycles, or about 270 years.
RayLivingston:
If you use a single byte, and turn the system on 10X/day, EVERY day, 365 days/year,it should last about 27 years! If that is not enough, you can add an external serial EEPROM, for under $1, that will be good for at least a million cycles, or about 270 years.
Or for an extravagent 50c extra, use a Cypress FRAM, They have read write endurance quoted as '100 trillion read/writes', so should last around 27 billion years .........
Since the EEPROM life rating is per cell, you can extend the total number of writes by rotating the writes between EEPROM addresses. You can find some good examples for how to do this. The term is "wear leveling".
septillion:
So in sleepmode it wont loose its memory/position with the pulses?
That is what I was hoping. Then I wont have to deal with memory writing to EEPROM.
But will it keep the memory even en the deepest kind of sleepmode? :o
Are there some limit?
Yes, as long as the chip has power memory is preserved, no matter how deep you let it sleep
And for a real power on I would add a home switch. Only, for safety, I would just start up in "error mode" and require user input to tell it's safe to home aka move. And as long that's not done, just don't move, whatever level is requested.
To help get past this, I would add voltage sensing, so the processor is aware of the supply voltage.
If the voltage drops below x, save the motor position, and ‘lock’ the controller from any further motion until the supply is restored.
When power is back, reload the position counter, and release the controller for operation. You might include a ‘brake’ to stop the carriage moving if needed.
Keep in mind that any manual or unintended movement during the ‘off’ phase will still require recalibration... perhaps a hall sensor at each floor and end limit.
Restoring the position is only good/safe if you're 100% sure the lift can not move during power off.
Voltage sensing and saving the value is indeed an option. Just be sure to have a decoupled buffer for the micro. Only point, a buffer is pretty useless if the micro high side drives loads (like a LED) or you need to try and turn them off as fast as possible after detecting power loss. Not a problem for low side driven loads.