Battery (PRAM?)

Hello. I am using an Arduino Uno, VNH5019 motor driver carrier, a potentiometer, and a metal gearmotor with quadrature encoder. I spoke with Kevin earlier today about this, but I thought of another possible approach. My challenge is that I am using a POT to control the position of a motor, using the built in encoder for feedback. Actually, it works great. The only issue is that when I power down (disconnect the battery), the encoder “forgets” its position. I would prefer not to record position in the EEPROM because it can only record changes a finite number of times. I would also prefer not to change the entire design, although I may have to.

With all of this in mind, I was wondering if I should consider using a more “permanent” battery for the Arduino board (e.g. watch battery?) that maybe gets charged from the main removable battery. Any thoughts? I have never done anything like this, so please be gentle.

Thank you,

Walter

Hello, Walter.

I think that approach is not likely to work well, mainly because it requires a system that can go into a very low-power sleep state, and I don’t expect the Arduino to be capable of this.

EEPROM is intended as a way to save the state after power is disconnected, so it should work fine for what you’re trying to do as long as you have control over the power disconnect sequence. For example, you could connect a “save button” to your Arduino that tells it to save the position to EEPROM whenever the button is pressed. A fancier approach would be to use something like our pushbutton power switch to control power to your system. You would use the power switch to turn power on, and you could set up a separate button to turn power off. When you push it, the Arduino would save the position to EEPROM and then drive the power switch’s OFF pin high, turning off power to the system.

The ATmega328P EEPROM is good for 100k write/erase cycles, so as long as you’re careful about how you use it, you should be fine. For example, even if you turn off your system 100 times a day, you won’t exceed the EEPROM write/erase rating for nearly three years. Additionally, that rating is likely quite conservative, and it applies to each address independently, so if you burn out one location, you can probably just start using another. I have tried to burn out an EEPROM location by writing to it repeatedly, and even after millions of cycles it was working fine (I never succeeded in burning it out).

The one thing to be careful about is that you don’t ever unintentionally set up a loop that just writes to EEPROM repeatedly, as you could then perform a few hundred writes in a second without even knowing it. So if you use a button to trigger a state save, be sure to debounce the button press, and be careful not to use logic like “while button is pressed, save to EERPOM”, since you might be writing repeatedly the whole time the button is pressed.

By the way, an easier solution than all this might be to switch to an absolute encoder. Then you would not have to save the position because reading the encoder tells it to you.

- Ben