Memory usage

moninos

New Member
hello,
Am I wrong or if you use a single byte of the eeprom (say to store a calibration value), you loose the whole 255 bytes for program storage (08m2)
it should be possible to use the last bytes for data and allow the program to use the rest of the memory space
or am I missing something
Thanks for your help
 
Last edited:

mrburnette

Senior Member
The way I read the M2 sheet, the eeprom is dedicated storage separate from program memory:

Memory Capacity
The M2 parts now have up to 2048 bytes of program memory, which is 8x larger than the older M parts.
They also contain 256 bytes of data memory (read/write/eeprom commands).



PICAXE Feature BASIC command 08M2 08M 08
EEPROM (bytes) read/write... 256 256-P 128-P
Reference: http://www.picaxe.com/docs/picaxem2.pdf
See page 3
 
Last edited:

moninos

New Member
I don't think it is separated because if the eeprom is used, program space is reduced to 1790 bytes instead of the 2048
 

mrburnette

Senior Member
I don't think it is separated because if the eeprom is used, program space is reduced to 1790 bytes instead of the 2048
Yes, you are correct! I read further... my bad. I simply misread the datasheet table of features and evolution of the model line.

Due to more limited silicon resources on the 08M2/18M2 the upper 256 bytes are shared between program and data (2048 in total). Therefore with programs that are under 1792 bytes long all 256 bytes of data memory are available. Very long programs (over 1792 bytes) start to reduce the amount of data memory available.
(deleted snippet which was not relevant)

- Ray
 
Last edited:

moninos

New Member
that fine but your code is very short. try do add enough (junk) code to it and you will see the 1790 byte blockage although you are one using a single byte of eeprom.
 

mrburnette

Senior Member
Thank you for you mea-culpa. Still why are 254 bytes wasted when you only use one ?
UPDATE:
PE enforces 256 bytes reduction in program size for the single use of an upper eeprom declaration (example: "eeprom 255,(x)" ).

Update: Hippy explains later in this thread that "eeprom 0,(x)" will only reserve 1 byte. Take-away: Upper memory for data is at low-addresses. To get the behavior explained in the documentation, start your data storage and address 0 and move upwards in addresses.

I created a program that infringes on the eeprom space by just a few bytes (1816/2048) and a Syntax check reported no issues. Then adding a single eeprom declaration caused the Syntax checker to report "Error: EEPROM location already used!". Hippy/Technical can likely answer off the top of their head the memory allocation rationale... I have not seen a reference to that in the literature; however, other high level languages often have this type of compiler behavior.

Additional update:
Just because I have not seen a reference to the PE behavior does not mean that it does not exist on the site. The reason this forum is so valuable is there are a lots of eyes connected to good brains that remember a multitude of different things. Together, we as a forum are more knowledgeable than any one member.

- Ray
 
Last edited:

mrburnette

Senior Member
that fine but your code is very short. try do add enough (junk) code to it and you will see the 1790 byte blockage although you are one using a single byte of eeprom.
Only someone at RevEd can tell us the logic in how PE works, maybe Hippy/Technical will chime in later. However, I have seen such behavior in many languages where the compiler will "initialize" a structure upon first use... even if you only utilize a single element of the object. This is typically done because the underlying C code enforces a finite malloc memory allocation for efficiency sake. It may also be done because the PICAXE in-chip interpreter needs to know about boundaries of object abstractions (that is, beginning & ending address pointers to program, data.)

An interesting test that I may perform would be to completely utilize the 08M2 program memory as I did in my little PE test today, leaving maybe 15 bytes at the upper memory and then program a 08M2 chip... then in the code, do a "Write 255, (0)" just to see if the thing bombs. It may be that the PE compiler catches the "write" instruction and forces an allocation just like it did when I used the "eeprom" instruction. Anything beyond this at this time would just be conjecture, so more information is necessary either by testing or by RevEd input before the true reasoning is known. It does beg the updating of the 08M2 datasheet, however, with at least a caveat about PE usage.

- Ray
 
Last edited:

moninos

New Member
Thanks. It seems indeed to be a PE behaviour. for the sake of simplicity it decides to block all the 255 bytes instead of monotoring and managing the eeprom space. Pity
Any chance this could be changed some day?
 

mrburnette

Senior Member
Thanks. It seems indeed to be a PE behaviour. for the sake of simplicity it decides to block all the 255 bytes instead of monotoring and managing the eeprom space. Pity
Any chance this could be changed some day?
As a non-RevEd forum member, I certainly cannot answer that... sometimes Technical will chime in... especially if there has been a significant request for such an enhancement. However, our testing today shows that the compiler is enforcing the behavior so I would think that the interpreter/bootloader that transforms a PIC to a PICAXE expects this behavior and that changes would require a new firmware revision and would not be backward compatible. I'll end my conjecture at this point and will follow the thread to see if definitive rationale and official input is forthcoming.

- Ray
 

srnet

Senior Member
for sake of simplicity it decides to block all the 255 bytes instead of monotoring and managing the eeprom space
How can it 'manage it' that is the problem.

If you do a;

write variable, data

How would the firmware be able to keep track off which EEPROM location (defined by the variable) you were writing to and then somehow decide to allow the request, deny it, or relocate it ?
 

mrburnette

Senior Member
How can it 'manage it' that is the problem.

If you do a;

write variable, data

How would the firmware be able to keep track off which EEPROM location (defined by the variable) you were writing to and then somehow decide to allow the request, deny it, or relocate it ?
The issue, as I see it and understand moninos, is that the documentation makes reference to being able to utilize less than 256 bytes of eeprom space by using standard declarations and in actuality the PE will not allow the coder to utilize less than 256.

In my example, eeprom 255, (0) forces PE to reduce the program size by a full 256 bytes. The 08M2 documentation suggests (in my reading) that only 1 byte would be lost in program length... not all 256 bytes. So, there is really not "sharing" per se, if you use any eeprom declarations at the end of data addresses, you lose all 256... it is an all or nothing situation.

The exact wording in the M2 PDF states:
Due to more limited silicon resources on the 08M2/18M2 the upper 256 bytes are shared between program and data (2048 in total). Therefore with programs that are under 1792 bytes long all 256 bytes of data memory are available. Very long programs (over 1792 bytes) start to reduce the amount of data memory available.
We are not talking about changing the syntax of any instructions.

- Ray
 
Last edited:

moninos

New Member
Well put, let's wait for the official point of view. I agree, if the interpreter is involved, it is probably hopeless.
John
 

srnet

Senior Member
"Due to more limited silicon resources on the 08M2/18M2 the upper 256 bytes"

Not sure I underastand then.

Is there some confusion between what is EEPROM, and what is normal program space Flash ?

The 08M2 only has 256 bytes of EEPROM, so there cannot be an upper 256 bytes of EEPROM ?
 

moninos

New Member
For the sake of terminnology compatibility with the industry, they call it EEprom but IT IS NOT, modern chip do not use EEprom, it is all flash memory.
And yes there is the upper part of the general flash memory that can be reserved for data. Calling it eeprom in the case of shared code/data space is confusing.
 

hippy

Technical Support
Staff member
The "upper 256 bytes" refer to the upper 256 bytes of program code. There are 1792 bytes of Flash memory and a separate 256 bytes of Eeprom. The program code fills Flash first and then extends into Eeprom if more than 1792 bytes.

Using EEPROM commands should not block programs from extending into Eeprom but it depends on which bytes are used. EEPROM 255, ("X") will but EEPROM 0,("Y") will not, will allow 2047 bytes plus 1 byte of Eeprom. If there is an issue with that we will investigate it.

Writing to Eeprom when it holds program code will likely corrupt the program stored there; you should only write to Eeprom which has been defined in EEPROM statements and EEEPROM commands should be added for all locations to be written to.
 

mrburnette

Senior Member
The "upper 256 bytes" refer to the upper 256 bytes of program code. There are 1792 bytes of Flash memory and a separate 256 bytes of Eeprom. The program code fills Flash first and then extends into Eeprom if more than 1792 bytes.

Using EEPROM commands should not block programs from extending into Eeprom but it depends on which bytes are used. EEPROM 255, ("X") will but EEPROM 0,("Y") will not, will allow 2047 bytes plus 1 byte of Eeprom. If there is an issue with that we will investigate it.
<...>
Code:
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
inc b0
'inc b0      ' 774
'inc b0      ' 775
'inc b0      ' 776
'inc b0      ' 777
'inc b0      ' 778
'eeprom 0, (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14)     '779
Load the code into PE for 08M2. Click Syntax - I got 2033 bytes used. Now, start un-remarking lines beginning with line# 779 and click Syntax after each. Below is what I got:

; Memory used = 2033 bytes out of 2048
;779: Memory used = 2033 bytes out of 2048
;778: Memory used = 2037 bytes out of 2048
;777: Memory used = 2038 bytes out of 2048
;776: Memory used = 2042 bytes out of 2048
;775: Error: EEPROM location already used!

My confusion in the previous post came because PE reserves all EEPROM 256 bytes when a reference to eeprom address 255 is created... one byte of storage (Like the original Lotus 1-2-3 RAM usage before sparse matrix.) I had expected PE to relocate the reference to address 255 to physical location eeprom 0 and adjust pointers to reflect the relocation. Obviously, I was mistaken in my assumption. I have to remind myself that I am working with a uC and not a RISC mpu... I do recognize that even a single additional pointer in the interpreter is a major concern.

Based upon the sample program provided, I do find it interesting that I can reference the upper 15 bytes of eeprom with out affecting program memory space.

- Ray
 
Last edited:

mrburnette

Senior Member
hello,
I am wrong or if you use a single byte of the eeprom (say to store a calibration value), you loose the whole 255 bytes for program storage (08m2)
it should be possible to use the last bytes for data and allow the program to use the rest of the memory space
or am I missing something
Thanks for your help
For grins, try using eeprom 0,(0,1,2,3,4,5,6,7) in your code and check the storage. It appears that 8 bytes are available without program storage impact.

-Ray
 
Last edited:

westaust55

Moderator
For the sake of terminnology compatibility with the industry, they call it EEprom but IT IS NOT, modern chip do not use EEprom, it is all flash memory.
And yes there is the upper part of the general flash memory that can be reserved for data. Calling it eeprom in the case of shared code/data space is confusing.
Who are “they”?
The Microchip datasheets as at 2011 are still describing Flash Memory for the PIC program area and EEPROM for DATA memory – see a typical datasheet here: http://ww1.microchip.com/downloads/en/DeviceDoc/41441B.pdf
 

Technical

Technical Support
Staff member
My confusion in the previous post came because PE reserves all EEPROM 256 bytes when a reference to eeprom address 255 is created... one byte of storage (Like the original Lotus 1-2-3 RAM usage before sparse
We've lost track of what you actually think the problem is, can you be more specifc?

When the program overlaps into the data memory area it will start using the bytes backwards from 255 downwards for the program.
So a program that overlaps by one byte will use byte 255, with bytes 0-254 still available for read/write/eeprom. It does not reserve all 256 bytes, the others are free to use.
So if your program overlaps data memory by a small amount use address 0 upwards for read/write/eeprom.

And yes, this line
eeprom 0,(0,1,2,3,4,5,6,7)
will have no affect whatsoever on program length, as it is simply preloading data eeprom values at download time - it is not part of the program (use read/write at runtime, not eeprom).
 

mrburnette

Senior Member
We've lost track of what you actually think the problem is, can you be more specifc?
The original concern (and my confusion) was that writing a byte to the high (255) eeprom address consumed the entire 256 bytes of available program space and this seemed somewhat contradictory to what the manual states in the document picaxe-M2 Series Overview.pdf Page 3, reference table row #7, "Data EEPROM (bytes)" which states (or appears to state) a dedicated 256 bytes. Later on in the document, the statement is made about limited silicon resources and program/eeprom overlap.

I now understand the consumption of all of eeprom by writing to the last eeprom address.
From my understanding, moninos was inquisitive if this would change in a future release; which is to say that many compilers are "smart enough" to recognize net storage requirements and adjust pointers accordingly - in such a scenario, coding a single byte at eeprom address 255 would be optimized by the compiler to address 0 and the firmware would actually never know the difference because access to the eeprom would be through a pointer that contained an offset.

I understand the manual workaround by using eeprom low-address space first and working upwards. It would be nice if the aforementioned document was a bit clearer, however:
Memory Capacity
The M2 parts now have up to 2048 bytes of program memory, which is 8x larger than the older M parts.
They also contain 256 bytes of data memory (read/write/eeprom commands).

Due to more limited silicon resources on the 08M2/18M2 the upper 256 bytes are shared between program and data (2048 in total). Therefore with programs that are under 1792 bytes long all 256 bytes of data memory are available. Very long programs (over 1792 bytes) start to reduce the amount of data memory available. (something at this point about how EEPROM usage is calculated would be beneficial in my opinion)​


In the case of the sample code, loading the entire sample into PE and clicking on syntax shows 2033/2048 program usage. Un-commenting the eeprom last line and clicking on syntax also shows 2033/2048 program usage. Edit the eeprom line to utilize only 1 more data byte:
eeprom 0, (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
and click the Syntax button. The error message displayed is:
Error: Memory location already used! (Byte 15)

There is not really a question here, just that the math (syntax checker) seems a bit strange.

- Ray
 
Last edited:

Technical

Technical Support
Staff member
...coding a single byte at eeprom address 255 would be optimized by the compiler to address 0 and the firmware would actually never know the difference because access to the eeprom would be through a pointer that contained an offset.
So what would happen if you then used both eeprom 0 and eeprom 255?

The eeprom/read/write use physical addresses, not pointers, of the internal 256 bytes of data eeprom memory space in the PIC chip.
The current scenario is very straight forward with shared memory space, simply use eeprom from address 0 upwards, as the vast majority of people already do. It is quite unusual to start at address 255 instead - it is not a 'workaround' to start at address 0, most people do this by default.
 
Top