Running Out of Programing Memory


Closed Thread
Results 1 to 16 of 16
  1. #1
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    644

    Default Running Out of Programing Memory

    Hi all,

    Yes, I ran out of program memory. I'm using a PIC16F727, which has 8192 words in program memory. I've already used it all and I need like 300 or 400 more words to finish my project.

    I have replaced a bunch of IFs by LOOKUPs to save memory space and I have erased some parts of the code that I don't really need. I use a lot of sub-routines with GOSUB, so there is no need to rewrite the same code over an over. But, I still need from 300 to 400 additional words.

    Is there any good programming technique to save program memory? Do you have any programming tips that I can use? Any comments?

    Thank you all,

    Robert

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Do you have any programming tips that I can use?
    For an usefull answer you must post a sample of your code.

    Al.
    All progress began with an idea

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default

    Have a look here but be very carefull with direct ASM commands.

    http://www.rcfaq.com/PIC/optimize.htm#morefornext

    Ioannis

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Question just to see what we are talking about ...

    Quote Originally Posted by aratti View Post
    For an usefull answer you must post a sample of your code.

    Al.
    + 500 !!!

    first: do you use V2.60 ??? ( some good " room saving " enhancements included )

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Change the location of subroutines in the program.

    Also, if you are comparing bytes to words (or the other way), just compare the low.byte of the words.

    Also, if you are using AND, OR etc in the IF condition, remove them and use separate IF condition for each AND or OR.

    Also, if you are using an IF condition similar to the one as follows,
    IF a+b = c THEN x=y.
    Change it to something like
    temp = a+b
    IF temp = c THEN x =y

    _____________________________
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Tip1.

    In your program you will probably have variables that are used often... put those variables in BANK ZERO...

    For example, you have a variable called CounterA, you would normally deline it as...

    CounterA var Byte Bank0

    ...all you have to do is change that to...

    CounterA var Byte Bank0

    I did that in one program and recovered close to 2K... so it's really worth doing.

    Eventually, you'll fill up Bank0 and can't fit any more variables into it, so there's a limit here, therefore pick the variables you use MOST OFTEN to go into Bank0.

    Come back and tell us how much you saved just by doing this...

    Tip2.

    Put your SUBROUTINES at the start of your program and your first instruction is a jump over them... eg GOTO START. The more commonly used subroutines and variables that you can stuff into the first Bank of Memory in your PIC the better for the overall compactness of your program when it starts to grow.

  7. #7
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    644


    Did you find this post helpful? Yes | No

    Default

    Hi,

    I will try all of your recomendations and will keep you posted.

    My program is 8100 words when compiled, that is closed to 40 pages if you print it out, so posting it in here would be too much.

    I am using PBP 2.50, and I don't know if that really makes a difference when compared to PBP 2.60.

    I will try Sayzer and Melanie recomendations and will keep you posted.

    Any other tips? Thank you,

    Robert

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Lightbulb

    Hi, Robert

    A simple trick in the Manual ...

    disable the watchdog ... see CLRWDT command.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  9. #9
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    One thing that will save you a lot of code is replacing repeated segments of code like for example - SEROUT ..... or LCDOUT. So, if you have a LCDOUT "Hello World" maybe 5 times in your code, it would be better to replace 4 of them with a gosub ShowHelloWorld and keep the LCDOUT "Hello World" in that subroutine.
    Last edited by Jerson; - 8th November 2009 at 02:34.

  10. #10
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    644


    Did you find this post helpful? Yes | No

    Default

    Jerson,

    Yes, I already use a lot of sub-routines.

    Melanie,

    Using the BANK0 next to the variables declarations didn't help. I think that I read somewhere that newer versions of PBP already take care of this BANK issue. However, moving sub-routines to the beginning of the program after the variables declaration help me free about 60 words.

    Ioannis,

    The link that you provided was very helpfull. I used in my program a lot of (with different variables all the time)

    Code:
    IF (VAR_0=0) AND (VAR_1=1) AND (VAR_2=2) AND (VAR_3=3) THEN
       ........
    ENDIF
    
    IF (VAR_0=0) OR (VAR_1=1) OR (VAR_2=2) OR (VAR_3=3) THEN
       ........
    ENDIF
    And according to the link that you posted you can save a lot of space by changing the above lines by

    Code:
    IF (VAR_0=0) THEN
       IF (VAR_1=1) THEN
          IF (VAR_2=2) THEN
             IF (VAR_3=3) THEN
                ........
             ENDIF
          ENDIF
       ENDIF
    ENDIF
    
    IF (VAR_0=0) THEN ........
    IF (VAR_1=1) THEN ........
    IF (VAR_2=2) THEN ........
    IF (VAR_3=3) THEN ........


    Well by using this technique I was able to go from 8118 words down to 7216 words. Enough to do what I need to finish my project. It would be nice to see an improved version of this link here in this forum. I'm sure that there are many techniques and tricks to save a lot of space that we don't know about.

    Robert

  11. #11
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default

    I am glad it helped.

    The best way to reduce size is to do it in ... assembly.

    Ioannis

  12. #12


    Did you find this post helpful? Yes | No

    Default Move ascii strings out to EEROM

    Each ASCII character included in a SEROUT, LCDOUT, DEBUG or SEROUT2 takes at least two characters in program memory for each ASCII character in the string.

    Keep any user prompts as terse as possible.

    HTH
    BrianT

  13. #13
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    This brings up an issue that I have long harped on.

    Unless you are building a huge quantity of something, where the cost of the coding can be amortized across a large number of units, ALWAYS

    Use an 18F part
    Use a part that has at least twice the codespace you need.

    And, if you want to know if you have exceeded any particular memory size, use

    Code:
    ASM
         ORG 0x1fcee        ; put your limit here
         nop
    ENDASM
    at the end of your program. The compiler will give you an error if you exceed the size given in the ORG statement.
    Charles Linquist

  14. #14
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    644


    Did you find this post helpful? Yes | No

    Default

    Hi all,

    Thank you all for your help. This post is an update for this thread. When giving the final touches to my program, I found out one more time that I was running out of programming memory space. Luckily, I was able to reduce the size of my program by almost 1K words . I don't know assembly so; this is how I did it.

    Before, I was using only one variable I that was declared as a word for all my FOR I = ... NEXT I loops and whenever I needed a counter I = I + 1.

    Code:
    I VAR WORD
    Sometimes the value of I went well over 255 but must of the times it didn't go over 255. So, I created a new variable J and declared it as a byte.

    Code:
    I VAR WORD
    J VAR BYTE
    I replaced J by I wherever it was possible and BINGO, the size of the program went down by almost 1K words.
    Again, Thank you all for your help.


    Robert

  15. #15
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default

    Also a 0 to x instead of 1 to x may help too in a for-next loop.

    Ioannis

  16. #16
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    644


    Did you find this post helpful? Yes | No

    Default

    Also a 0 to x instead of 1 to x may help too in a for-next loop.

    Ioannis
    Yes, I read that in the link that you posted earlier. Thank you.

    Robert

Similar Threads

  1. fatal error out of memory (pbpw.exe)
    By hardcore in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 14th March 2010, 19:13
  2. Need the code to write to a memory
    By Hamlet in forum General
    Replies: 0
    Last Post: - 20th August 2007, 00:22
  3. Replies: 4
    Last Post: - 2nd March 2007, 06:12
  4. sample code for M25P32
    By Pedro Santos in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th January 2007, 02:37
  5. Use internal program memory like DATA memory
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th December 2006, 18:38

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts