Memory map confusion

I've been trying, with only partial success, to understand the M2 series devices' memory maps, and in particular exactly where various commands such as "TABLE" and "WRITE" actually write their data, so that I don't risk over-writing things.

I've looked at various threads on this forum (14M2 TABLE data is particularly useful and interesting) as well as the descriptions of the commands, but the more I look the more confused I get!

Based on the tables shown in PICAXE Chip Sizes, I've drawn up this simple diagram which, on the face of it, should represent the --M2 chips .....
PicAxe Memory Map.png

However, when reading the "TABLE" command details, it states
M2 parts have 512 locations (0-511).
These are separate to the 2048 bytes of program memory, so do not affect program length.
This would seem to conflict with the description of the M2 chips (except the 8M2) having a separate 2048 byte flash/EEPROM memory?

Another point from the aforementioned thread; are flash and EEPROM memory just different names for the same type of memory having the same read/write speed etc?

What I find a bit confusing is exactly where commands such as "EEPROM" will actually write to. If I understand correctly, up to 256 bytes can be written as "EEPROM 0, byte1,..." etc and this will write to the main program flash memory starting at location &7FF and filling in the memory by decrementing from the top. Is this correct? Note, I presume this is case from the comment on the above page saying:
Program 1792 up to 2048 is EEPROM 255 to 0
Then there's the table memory command. Superficially it looks much the same as the eeprom command. I presume that "TABLE 0, byte1,..." writes to the second block of flash memory starting at &000? But if only 512 bytes can be written with the "TABLE" command, is the rest of the 2nd block of 2048 bytes wasted?

The other associated command is "WRITE". The description again doesn't make it at all clear (to me) where the command "WRITE 0, byte1,..." actually puts the bytes/words in the program/data memory. In particular, I'm worrying about a large program approaching 1792 bytes of code getting overwritten by data generated when the program runs? If the code takes 1792 bytes and all 256 spare bytes are written using EEPROM, is there any space left for WRITE data?

Apologies if the information I'm looking for (especially a memory map diagram) is available somewhere, but if it is I haven't managed to find it.
 

AllyCat

Senior Member
Hi,

I'm not an expert on this (because most of these features are not available, or different, in the 08M2), but it appears that the (512 bytes) "TABLE" is basically an "extension" of the 2048 bytes of Program memory. Like the program, it can be written ONLY by the Program Editor (PE5/PE6), it cannot be changed by a "Write" command from the program itself.

Then, PE6 offers a "bonus" that with M2 chips (14, 18+ and 20 only) the whole program and table area is duplicated in a second "Slot". But moving between these slots is not easy, it's similar to running a different program.

EEPROM and DATA are different names which refer to the same area of 256 bytes of "non-volatile" memory (but different to the TABLEs), which again can be written when programming the PICaxe. But the difference is that it also can be "updated" by the program itself, using the WRITE command. AFAIK it's the same data area, when accessed via either program slot.

The RAM is a completely different area of memory (where all the data is lost when power is removed), but is also 512 bytes in size for most M2s. It can be accessed by both the PEEK/POKE and @BPTR commands (and the lowest few bytes also by the pre-defined bitx, Bx and Wx variable names).

The TABLECOPY command is interesting because it can very quickly transfer pre-defined data into RAM, but very limited because an "Offset" address cannot be specified. To me, it looks most useful as a very fast way to clear (to zeros) any large RAM data buffer (e.g. as used for wireless/serial data) if you don't want the complication of implementing a Circular Buffer.

Cheers, Alan.
 
Last edited:

hippy

Technical Support
Staff member
Flash and Eeprom are separate.

Flash holds program plus table data which can only be set at download time.

Eeprom holds data which can be set at downloaded time and also accessed using READ and WRITE.

There is usually separate program memory and table memory in Flash. Some times the program and table memory share Flash but you don't have to worry over that as the compiler will report any issues if there are any. If a program passes Syntax Check you can consider them separate.

For the 08M2 the memory is 1792 bytes in Flash for program plus 256 bytes of Eeprom for program or data. So yes, if you have a large program, Flash will be full, some or all of Eeprom will be used as program memory, so in that case you can't use all of Eeprom for data.

So long as you have DATA or EEPROM statements for all Eeprom locations you use the compiler will tell you if there is a problem.
 

Attachments

tommo_NZ

New Member
Hi Hairy Aminal, I too was a bit confused about the memory mapping, but then I read a msg in the forum that said the flaming obvious. Use the memory tab at right of the editor, particularly the 4 tabs 'RAM", 'EEPROM", 'SCRATCHPAD" and 'TABLE'. All will be revealed as you play with peek, poke and various methods of storing and retrieving data. Certainly helped this old memory challenged coder.
Regards, tommo_NZ.
 
I haven't looked at that beyond viewing the defined variables, so I'll try that, many thanks. I also recently discovered how useful the onscreen terminal is thanks to this forum.
 
Top