Log in

View Full Version : Save a variable


dawonn
15-04-2005, 23:41
Is there a way to save a value in a program after the power had been lost and then recover the value after the power is reaplied? :ahh:


Thanks ^_^'

Dave Flowerday
16-04-2005, 00:06
Yes, you can use the EEPROM on the RC. Check out this thread (http://www.chiefdelphi.com/forums/showthread.php?t=22655) for details and code that will let you do it. Be aware that you can't write to the EEPROM every loop in the RC or you'll wear it out.

RyanMcE
16-04-2005, 01:43
As far as I know (not an expert by any means), most EEPROMs are good for at least a million write cycles. So don't go writing to it every cycle, but every second should be fine.

ConKbot of Doom
16-04-2005, 12:11
As far as I know (not an expert by any means), most EEPROMs are good for at least a million write cycles. So don't go writing to it every cycle, but every second should be fine.

Ok lets do the math, 1,000,000/(38cycles/sec*3600 seconds/hr)=7.3 hours. not a lot of time.

Once per second gives 277 hours, longer, probably longer than you will need for the robot. But depending on the variable, it could be longer.

How often does the variable change? if it is not that often, you could detect when it changes, and then save it.

RyanMcE
16-04-2005, 13:45
Ok lets do the math, 1,000,000/(38cycles/sec*3600 seconds/hr)=7.3 hours. not a lot of time.

Once per second gives 277 hours, longer, probably longer than you will need for the robot. But depending on the variable, it could be longer.

How often does the variable change? if it is not that often, you could detect when it changes, and then save it.

Good points - it seems to me) that 277 hours is longer than most robots are on, in their lifetimes. Nevertheless, you are right - only writing when you need to is a better solution than writing periodically.

What I had in mind, however, was a variable that is constantly changing (like position, for example), but you don't want to exhaust your EEPROM. So you write only every second. That gives you reasonably up-to-date information, but many fewer write cycles, greatly extending the life of your EEPROM.

Kyle T
17-04-2005, 15:50
honestly, i think your best bet would be to have a button to save the value that you should press before you turn it off-- that saves a lot of writes, even though it requires user intervention

Astronouth7303
22-04-2005, 16:07
honestly, i think your best bet would be to have a button to save the value that you should press before you turn it off-- that saves a lot of writes, even though it requires user intervention
I would say to save it if the main battery voltage dips below a certain point. As long as the backup is installed, you should be OK with this.

Dave Flowerday
23-04-2005, 08:30
I would say to save it if the main battery voltage dips below a certain point. As long as the backup is installed, you should be OK with this.
I wouldn't recommend this. If your battery dies while writing to EEPROM you could corrupt it. Using the voltage dropping as a trigger will greatly increase the odds that you're trying to write as the power dies, obviously. Plus, if you suddenly cause a large current drain on your robot (for example, at the beginning of the match with both sticks forward), you could end up trigger ing your write routine, which personally I wouldn't want running at all during a match in case something goes wrong with it and because it wouldn't get the same level of testing as the rest of your code.