View previous topic :: View next topic |
Author |
Message |
Salenko
Joined: 08 Sep 2008 Posts: 84
|
out of ROM ! [solved] |
Posted: Wed Sep 23, 2009 2:52 pm |
|
|
Hi,
I was out of ROM when I added those two instructions to my program:
Code: |
printf("\n\r Buffer full");
buffer[5]=0;
|
in the previous compiling, the program used only 65% of the ROM and 22% of RAM. How can two instructions overflow the ROM then ?
is there a limit for the number of lines in the main ?
PICmicro : 16F876
CCS version : PCW 4.057
thanks for any clarification.
Last edited by Salenko on Fri Sep 25, 2009 1:50 pm; edited 2 times in total |
|
|
Ttelmah Guest
|
|
Posted: Wed Sep 23, 2009 2:58 pm |
|
|
A search on the forum, would find lots of answers about this.
Not directly a limit on 'main', but a limit on any _single_ block in the program. The 876, has it's ROM organised in pages. Four in all. No one consecutive block of code can be larger than a page. Since the pages are 25% of the actual ROM size, it suggests your code is pretty much one lump, rather than being written in sections, so is all going into one page, and you are running out of space, when effectively, it grows to > 25%.
You need to split your code into subroutines, and flag these as #separate, so the compiler can split the program up.
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Sep 23, 2009 3:03 pm |
|
|
Break up the code in main() into two or more smaller routines, and
call them from main().
By using several routines, instead of one big main(), the compiler can
fit the routines into the available ROM space in the PIC. The 16F876
has 4 ROM pages that can each hold 2K words. A routine (a function) can
not be larger than 1 ROM page. That's a requirement of the CCS
compiler. So, the solution is to break up your main() into smaller
routines, and let the compiler put them into the available ROM pages.
--
Edit:
Ttelmah, you are fast on the draw today. Beat me by 5 minutes. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Wed Sep 23, 2009 3:31 pm |
|
|
Just to add another perspective:
The memory, in each PIC, is organized like a blank book with dividers already placed in it. You can write whatever you want into each section but once that section is full you must start writing in another section. One problem is that you can't simply carry over into the next section. If the topic, that you are writing about, won't fit into the section that you've been writing to then you have to start writing into a different section.
If a function, or main(), is too large to fit into one bank(section) then it must be split up into smaller portions so they can fit somewhere. The functions cannot bleed over the physical bounderies of the memory bank.
Ronald |
|
|
Guest
|
|
Posted: Wed Sep 23, 2009 7:18 pm |
|
|
What does #separate ACTUALLY guarantee -
If your program is already broken up into sub functions - from the get go ?
How does it exactly help ? |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Sep 23, 2009 8:30 pm |
|
|
If a function is only called once the compiler will try to optimize things by converting it from a subroutine to inline code. A subroutine call can cross page boundaries but the inline code can't, so this defeats the purpose of splitting the code into parts to use multiple pages. The #separate directive prevents the compiler from inlineing the code. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Salenko
Joined: 08 Sep 2008 Posts: 84
|
|
Posted: Fri Sep 25, 2009 11:04 am |
|
|
thank you all the participants of this thread, thank you Ttelamh and PCM for being part of this forum.
I understood and did what you recommend me. I broke up the main() into five procedures and called them, but the error remains (OUT OF MAIN). So I put #separate before the two longest procedures and compiled without warnings with 64% of ROM used.
a question pops into my mind : can I use #separate as much as I like ?
with all my respect. |
|
|
Ttelmah Guest
|
|
Posted: Fri Sep 25, 2009 2:39 pm |
|
|
The keyword is in SherpaDoug's reply _optimise_. It takes slightly more space, and time, to call a routine that is actually 'separate', than the same code 'embedded' as an 'inline block inside an existing routine. Hence the compiler tries to inline everything, and leaves it up to you to separate as needed/wanted. Doing it unecessarily, will cost perfromance.
Best Wishes |
|
|
Salenko
Joined: 08 Sep 2008 Posts: 84
|
|
Posted: Fri Sep 25, 2009 3:26 pm |
|
|
Ttelmah wrote: | The keyword is in SherpaDoug's reply _optimise_. It takes slightly more space, and time, to call a routine that is actually 'separate', than the same code 'embedded' as an 'inline block inside an existing routine. Hence the compiler tries to inline everything, and leaves it up to you to separate as needed/wanted. Doing it unecessarily, will cost perfromance.
Best Wishes |
Thank you again Ttelmah, now it's more clear. |
|
|
|