NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Writing into memory while running program
January 24, 2013 by eminthepooh |
Hi, I'm looking to save some variable values after a power cycle. I've read around that this could be achieved by EEPROM but i'm not sure if it's right. I'm looking to have the program running on an m168, for me to define a variable as a certain number thru buttons, and for the avr to save my selection so that when I cycle the power, it remembers my last choice. Of course, I've got the defining a variable and buttons part down, just don't know how to save that variable past power cycling. Thank you, |
---|---|
January 24, 2013 by Rick_S |
The EEPROM is flash memory and it will retain what is written to it through power cycles. You are definitely on the right path. There is even a Library Entry for this to help you see how it can be done. Rick |
January 24, 2013 by pcbolt |
eminthepooh - Just one thing to be aware of using EEPROM. You can read EEPROM as much as you like, but you only get 100,000 "writes". It may seem like you'd never reach this limit but if you accidentally put a EEPROM write statement inside a "while(1)" loop, this limit would be reached very quickly. General rule of thumb is to write to it only when the user changes some state in your program. |
January 24, 2013 by JimFrederickson |
Technically the EEPROM is good for only "AT LEAST 100,000 write cycles"... Some will last much longer. I am pretty sure the EEPROM is "byte oriented" so there are not "page writes". If you are writing "often" you can set aside EEPROM as a buffer that can hold several values. Then you can "write to the next free area" or use a "sequence number" to determine where the write should be. However you do it... As noted by PCBolt though... Be careful, if you do make the mistake of writing data needlessly what seems like a pretty large lifetime can go away pretty quick! |
Please log in to post a reply.
Did you know that Pulse Width Modulation (PWM) can be used to control the speed of a motor digitally? Learn more...
|