memory confusion

technokid

Member
Hi,

I have a PICAXE 20m2 and I have a delicate problem.
Besides the script that the chip is running, is there a way to have variables stay the same when I turn the power to the chip off without changing the script, like a save in a computer game?

Thanks.
 

Phil bee

Member
Hi,
the best way keep the variables over a power cycle is to save them in eeprom and reload at start up, see the EEPROM or DATA command in manual 2 for more details.

Hope this helps.

Phil
 

Goeytex

Senior Member
Yes,

Before the Picaxe is powered down, the program WRITES the current variable data to EEPROM memory. When the Picaxe is powered up, the program READS the EEPROM data and moves it into user ram (Variables) using either POKE or @BPTR =.

Example:
Code:
#Picaxe 20M2
#No_Data          '//do not erase stored data  

Init:
 gosub restore_variables

Main:
do
 
    'Main program here

   if pinc.5 = 1 then gosub save_variables  

loop   

restore_variables:          '// Read saved data into variables  
     for bptr = 0 to 10
          read bptr,@bptr
    next  
return 

Save_variables:           '// save b0 - b10 to EEPROM  

  for bptr = 0 to 10
      write bptr, @bptr
  next 
return
 

westaust55

Moderator
How often will the variable values change and be updated?

From the datasheets, EEPROM has a finite number of write cycles.
Number of Total Erase/Write Cycles before Refresh(2) is typically 10 million erase/write cycles.


At a variable values update rate of once per second that equates to around 115 days continuous operation. So if infrequent use, then will likely last some years.
If trying to retain values that can be changing 100 times a second, then your may just incur EEPROM errors after around 24 hours continuous operation
Keep in mind the 10 Million write cyclkes is typical and some on this forum have deliberate done tests and achieved far better results but no guarantees apply.
 
Top