View previous topic :: View next topic |
Author |
Message |
Steam
Joined: 03 Nov 2011 Posts: 7
|
out of rom!! |
Posted: Thu Nov 03, 2011 6:07 am |
|
|
Hi, I'm developing a firmware for a pic 18F252, and I'm out of rom.
The thing is, that the firmware use a lot of printf and lcd_putc. I managed to use only a few functions to print the info.
Do you have some tips and tricks to compress the code?
If I define global variables, this variables use ROM space?
If I define them as local function variables, this variables use RAM instead of rom???
thanks! |
|
![](templates/subSilver/images/spacer.gif) |
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Thu Nov 03, 2011 8:52 am |
|
|
Have you tried searching for posts on this subject? There are boat-loads of threads regarding this.
Ronald |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9171 Location: Greensville,Ontario
|
|
Posted: Thu Nov 03, 2011 10:06 am |
|
|
By their nature ALL variables are stored in RAM.
If defined 'globally' the RAM locations where the data is stored only gets used for that unique purpose.
If 'locally' defined, then RAM is used, as required, by whatever functions or operations require RAM.
How you configure or utilize RAM is dependent upon how you cut code. 'local' RAM will be 'reused' as required, 'global' for one variable. PICs with lots of RAM allow programmers to get 'sloppy' and less efficient in overall code cutting. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Fri Nov 04, 2011 3:28 am |
|
|
One of those links says that "printf and lcd_putc" hog rom as they are particularly code size inefficient. Your code has "a lot" of them....
When you're out of rom then essentially your code has got too big and/or too complicated. Instead of taking forever to slim it down, the best solution, and the one which gives you a future upgrade path, is often simply to get a bigger PIC.
RF Developer |
|
![](templates/subSilver/images/spacer.gif) |
Steam
Joined: 03 Nov 2011 Posts: 7
|
|
Posted: Fri Nov 04, 2011 5:41 am |
|
|
Thanks for the answer, i will take a look at the thread.
I cant use a bigger pic because its an upgrade for an existing product, so i cant change anything in the hardware, just an upgrade on the firmware.
thanks! |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9171 Location: Greensville,Ontario
|
|
Posted: Fri Nov 04, 2011 6:03 am |
|
|
Sounds like you fallen for the 'spare a few pennies, don't use a socket for the PIC' problem.Decades ago I learned to socket most ICs, especially the PIC. I know, too late now but in the future, consider the overall cost savings.
Seems bigger( more features,more ROM,RAM,etc) but pin compatible PICS are arriving every week unlike 2 decades ago making it hard to properly choose or 'keep up'.It'll cost less than a buck now to save 10s or 100s down the road when the 'feature creep' comes,it always does.
In your case, I'd print the entire listing and highlight potential code that is common and turn into functions.Perhaps there's redundant code( same stuff in several functions) that can be eliminated.Reorganizing variables(more local, less global ) might trim a few bytes here and there.
Maybe you've got same or similar code in 'header' files that are also in 'main'.Look for multiple 'defines' or similar lines of code.
I find looking at the program on paper,getting the whole picture, can show obvious,'why did I do that !' stuff quickly.
Shaving a few bytes here, some more there does add up and you might be able to squeeze in what you need, but it'll take time. |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Fri Nov 04, 2011 6:46 am |
|
|
I don't understand why you have so many printf's if you have already put it
into a function.
In one of my programs I created a function for my printf that had three
parameters and reduced my printfs from over 30 down to 2 and my ROM
usage almost 50%
The same for lcd_putc. _________________ Google and Forum Search are some of your best tools!!!! |
|
![](templates/subSilver/images/spacer.gif) |
|