View previous topic :: View next topic |
Author |
Message |
NoraANDnora Guest
|
% ROM, % RAM |
Posted: Sun Mar 23, 2008 10:22 am |
|
|
Upon compiling my code, written for PIC16F877A, I see some memory percentages.
ROM=62%
RAM=46%-100%
Where does the actual code reside?
What resides in RAM?
Do global variables reside in one place and local another?
Can I see this information in the LST file?
Which does the EEPROM section of this PIC refer to?
Which does the FLASH section of this PIC refer to?
Apologies in advance if this has been discussed on this forum (and I am sure it has been), I have not been able to find this discussion.
Thank you!
NN |
|
|
baltazar_aquino
Joined: 16 Mar 2008 Posts: 27
|
|
Posted: Sun Mar 23, 2008 11:23 am |
|
|
The code will reside in ROM. No way will the code be read from the RAM because the program counter is designed to access the flash area only.
Constants as well resides in ROM. The RAM holds the variables. The EEPROM statistics is normally not reported by the compiler because this is usually under the control of the programmer. The flash is your ROM. Hope it answered all your questions.
|
|
|
Nora
Joined: 23 Mar 2008 Posts: 50
|
|
Posted: Sun Mar 23, 2008 11:56 am |
|
|
Thanks for the reply.
So how will I know how much memory I am using in EEPROM?
-N_N |
|
|
Nora
Joined: 23 Mar 2008 Posts: 50
|
|
Posted: Sun Mar 23, 2008 11:57 am |
|
|
I guess I will just know how much EEPROM I'm using because of how many bytes I store? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Mar 23, 2008 12:00 pm |
|
|
Nora wrote: | I guess I will just know how much EEPROM I'm using because of how many bytes I store? | Yes, that's it. The compiler is not using the EEPROM for internal use, so you are the only one storing data in the EEPROM. |
|
|
Nora
Joined: 23 Mar 2008 Posts: 50
|
|
Posted: Sun Mar 23, 2008 12:15 pm |
|
|
So what kind of data would I be storing in EEPROM?
In my program code, I have variables that are read in from RS232 and A2D.
I have some constants.
And I have calculations that use up lots of memory (pwr with floats)- these calcs use the variables I mentioned before.
Should I store any of this in EEPROM? Where should the calculations reside? What if I need to access it quickly- then just leave it in the program code?
Thanks!
N_N |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Mar 23, 2008 12:38 pm |
|
|
Here a small overview of the different memory types:
- RAM is used for the variables in your program.
- ROM is used for program memory and data that never changes.
- EEPROM is used to store data that changes not very often and that you want to remember after a power loss. Examples of this are configuration and calibration data, passwords, a counter for number of device resets, serial number, etc.
A bit confusing might be that most PIC processors have Flash EPROM memory. This is the ROM memory used for storing the program. The difference between Flash EPROM and EEPROM is that Flash EPROM has a large capacity but can only be programmed in large blocks, while the EEPROM memory has small capacity but allows changing a single byte.
EEPROM is not used very often and certainly not for the variables in your calculations. EEPROM is slow and has a lot of overhead.
Quote: | Where should the calculations reside? | Calculations are program code. These are _always_ stored in (flash)ROM. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Mar 23, 2008 12:43 pm |
|
|
What is your real problem? Is your memory full and you want to know how to optimise? |
|
|
Nora
Joined: 23 Mar 2008 Posts: 50
|
|
Posted: Sun Mar 23, 2008 1:34 pm |
|
|
No problem- yet. Starting a new design and trying to optimize beforehand
*edit: And yes, I'm finding the difference between Flash EEPROM and EEPROM to be very confusing.
I've used an external EEPROM to store data, and am now trying to fit it all into one chip (PIC).
N_N |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Mar 23, 2008 2:39 pm |
|
|
Nora wrote: | ... and trying to optimize beforehand | You did mention calculations using floating point variables. As you already noticed these take up a lot of program memory. As a tip: are you aware of the technique called 'scaled integers'? This technique is also known as 'fixed-point' arithmetic and is using much less resources. |
|
|
Nora
Joined: 23 Mar 2008 Posts: 50
|
|
Posted: Sun Mar 23, 2008 2:45 pm |
|
|
I am not aware of the technique.
Can you point me in the right direction?
Thanks!
N_N |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Mar 23, 2008 3:52 pm |
|
|
A scaled integer means you use a regular integer to store decimal values. When you need the "real" value, divide the number by a correction factor. For example, if you need to store a price in the range $0.00 to $327.67, you can store it in a 2-byte int16 as 0 to 32767. You just divide it by 100 when you need to show the dollar value to the user. Or even better, don't actually divide by 100 but just insert the dot at the second decimal using the %w format specifier of printf.
Another way to phrase the above example is: Instead of calculating in dollars with two decimals (floating point) you can do the same arithmetic in dollar cents (integer).
Note that floating point data in the PIC is only exact up to the 6th or 7nd decimal (source)
As a last thing I like to re-post a very nice practical example posted some time ago on this forum: Sherpa Doug wrote: | Floats are painfull and waste huge amounts of resources. Don't use them unless you really really really need to (like a foolish edict from management). Instead work with AD counts or integer millivolts or the like.
I did a project measuring ship hulls looking for warps, dents etc. We started our measurements with clock ticks (@10MHz) and multiplied by the speed of sound in water to get millimeters. With 24 bit integer math we could measure a supertanker in integer millimeters. Only when we formatted our output for stinking humans did we insert decimal points using string functions to give an output in meters. |
|
|
|
Safvi Guest
|
pre processor eeprom?????? |
Posted: Fri Apr 11, 2008 6:04 am |
|
|
Its been over 7years, that i've been using CCS C compilers. I'm encountering a problem that I could not find a solution ??
Need Help......
how do I store data in the internal eeprom, as pre processor directive, that is, I donot want to declare it as constant, as it takes up Code memory. I wouold like to store it directly in the internal eeprom, and I'll access it while the program is running (with read_eeprom( X ) command )
Help needed urgently!!! |
|
|
Matro Guest
|
Re: pre processor eeprom?????? |
Posted: Fri Apr 11, 2008 7:26 am |
|
|
Safvi wrote: | Its been over 7years, that i've been using CCS C compilers. I'm encountering a problem that I could not find a solution ??
Need Help......
how do I store data in the internal eeprom, as pre processor directive, that is, I donot want to declare it as constant, as it takes up Code memory. I wouold like to store it directly in the internal eeprom, and I'll access it while the program is running (with read_eeprom( X ) command )
Help needed urgently!!! |
It depends on the chip you are using :
For PIC16 :
#ROM 0x2100={0x01,0x02,0x03,..} (stored as bytes, 0x2100 is address 0x0000 of EEPROM
For PIC18 :
#ROM [int8] 0xF00000 = {0x01,0x02,0x03,...} (stored as words unless int8 is present, 0xF00000 is the address 0x0000 of EEPROM).
Matro. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Fri Apr 11, 2008 8:03 am |
|
|
ckielstra wrote: |
As a last thing I like to re-post a very nice practical example posted some time ago on this forum: Sherpa Doug wrote: | Floats are painfull and waste huge amounts of resources. Don't use them unless you really really really need to (like a foolish edict from management). Instead work with AD counts or integer millivolts or the like.
I did a project measuring ship hulls looking for warps, dents etc. We started our measurements with clock ticks (@10MHz) and multiplied by the speed of sound in water to get millimeters. With 24 bit integer math we could measure a supertanker in integer millimeters. Only when we formatted our output for stinking humans did we insert decimal points using string functions to give an output in meters. |
|
That is from a while back. Since then I have grown older, more tactful, and more respectful of those who sign my paycheck. It's too bad... _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|