WRITE Command on 18M2+ - ??

dgc188

New Member
Hi all,

Forgive me but I'm a bit of a newbie to this (a bit of a numpty as well with this command).

I've read through the manuals and can find no real definitive answer relative to the 18M2+ specific chip.

In some of the chips I see that the NVM/EEPROM locations are shared with the program itself (it states "not 18M2+"). This is where I'm baffled.

I'm trying to save a variable to NVM so that it is saved during a power off/restart.

If my program is, say, 1900 bytes in length, how do I save - and where is - the variable.

The command pages say:
write b0,b1 ; save value of b1 into location b0

In the PICAXE Editor, Memory popout, I can see locations b0 up to b27 then it shows location (RAM address) 28 through to 511. Theoretically, how do I (or even can I) address/write to locations above b27 and, more specifically, what overlap is there between the program data stored and the available memory locations used in the WRITE command on this chip?

Another comment I read along the way is that there is a finite number of writes the PICAXE chips can use the WRITE command. What limit is there on the 18M2+ chip? Again, I read some ambiguity on this; maybe there's a limit on the older chips but not on the newer versions such as this?

Thanks for reading and I hope I can get some clarity into this befuddled mind of mine. ;)
 

westaust55

Moderator
With the exception of the 08M2, it is primarily only the older PICAXE chips where the program and EEPROM memory space is shared.

The PICAXE chips have three or four (depending on specific chips) separate memory areas:
1. Program memory

2. EEPROM – non volatile and with a minimum of around 0.1 million writes (found in the corresponding Microchip PIC datasheets)
3. RAM – volatile (data lost on power disconnection or reset) and where the variables such as B0 to B27 are held and extra space above which can be accessed with PEEK and POKE or the bptr pointer. These commands can access from B0 through B27/B55 (depending upon which chip) and on up to the upper RAM limit at 127/255/511 bytesw depending upon the chip used.

4. SCRATCHPAD (another section of RAM) for the older X1 and newer X2 parts - which uses the GET and PUT commands or the ptr pointer.
 
Last edited:

lbenson

Senior Member
write b0,b1 ; save value of b1 into location b0
The comment is ambiguous. The value of b1 is written to the eeprom address which is the value of b0. If b0 has a value of 2 and b1 has a value of 5, after executing this statement eeprom address 2 will contain 5. You can see this in the simulator.

The newer chips still have a limit on the number of writes. If I recall correctly, someone someone wrote to failure on some variety of picaxe chip, and got to the hundreds of thousands before seeing errors.

What is your application that you fear that you might write to eeprom too many times? If that is a valid concern, search the forum for FRAM--a nonvolatile memory with effectively unlimited writes allowed.

In addition to the 4 types of memory described by westaust55, there is also TABLE memory. See this recent thread for some insights: http://www.picaxeforum.co.uk/showthread.php?29866-14M2-TABLE-data
 

srnet

Senior Member
Another comment I read along the way is that there is a finite number of writes the PICAXE chips can use the WRITE command. What limit is there on the 18M2+ chip? Again, I read some ambiguity on this; maybe there's a limit on the older chips but not on the newer versions such as this?
Write endurance is specified as 100,000 writes in the data sheet.

Not sure there is any ambiguity here, its always been 100,000 as far as I am aware.

Some people may have tested chips and got more than 100,000 writes, but any application needs to plan according to the data sheet specs and not what someone has reported you might get.
 

dgc188

New Member
Thanks guys, useful information.

To Ibenson and your comment that my quote of "write b0,b1 ; save value of b1 into location b0" was ambiguous - that was taken straight out of the manual as an example. And you or anyone else might wonder why I'm confused! Hmmm. I did read somewhere that manuals (not just for this system) ought to be written by folk like me that do not have the in-depth knowledge that can allow assumptions, ambiguities and whot-not, as seen by the likes of myself, to creep in.

However, I did re-read the page on the WRITE command and the example given, and my quote of it, was probably taken in isolation and, therefore, out of context. I can now see that if I effectively use "WRITE 127,b1" then that would probably do what I need and write variable b1's contents into EEPROM location 127. This I have now tried and also observed the additional tabs at the bottom of the memory pop-out that distinguished between RAM, EEPROM, etc. and it does indeed go where it's needed - when I look at the right tab. I never spotted those tabs before - must get my eyes checked ;) I wonder what else I've not seen that is in front of me on the page! I've spent no end of time trying this write command and searching the web and forums and not getting anywhere. Now the light shines brightly.

As for the number of writes to NVM, I guess I might have an older copy of the manuals (probably at around the time the 18M2+ and similar came out) where, again, there appears to be some ambiguity as to certain chips not having the (approx) 100,000 write limit. I guess this must now be regarded as a standard across all the devices. Thanks also to westhouse55 and srnet for the clarification on this.

Interesting to note the use of TABLE memory (that's a new one to me!) - that might make things a little less risky if there's the possibility of over-running the write limit - not that I'm likely to....but you never know. And yes, the use of the WRITE command was to overcome the loss of a variable on power-down so that I could pick straight back up from where I left off without going through an initialisation routine. I'll look a little closer into this. Thanks for that.

Again, thanks guys for your valued input.
 

westaust55

Moderator
Be aware that TABLE memory is only written to during a program download. After that a program can read from (but not write to) Table memeory.
 

hippy

Technical Support
Staff member
I did read somewhere that manuals (not just for this system) ought to be written by folk like me that do not have the in-depth knowledge that can allow assumptions, ambiguities and whot-not, as seen by the likes of myself, to creep in.
Indeed. We do try our best but there is a lot of documentation and we are not infallible. Sometimes things may end up less clear than they could be, more ambiguous that we would like, or can be interpreted in ways we never expected they would be.

We do our best to improve things where those issue are identified and we have already updated the online documentation to make the intent of that command operation clearer ( Example 1 ) -

http://www.picaxe.com/BASIC-Commands/Variables/write

"write b0,b1 ; write value of b1 into location specified by value in b0"
 
Top