Memory use - how much do you use?


Closed Thread
Results 1 to 17 of 17
  1. #1

    Default Memory use - how much do you use?

    Hi!

    Using:
    PBP 2.50b
    Microcode Studio 3.0.0.5
    Microchip USB HID bootloader v2.2
    PIC18F4550

    When you compile via Microcode Studio you can see how much space your code will take. I think it would be very informative if you could also see how much there still is space to increase your code before you code memory is full. So, instead of seeing "Success: 22384 bytes used" you would see "Success: 22384/32768 bytes used" or something like that...

    But you use data memory also! It would be technically easy to add the use of it also on the same line where the use of the used code is shown, however, this is not how things are today.

    Where can one see how much you use data space?
    In 4550 there is 2k.
    Where is that data of used memory hidden? In a linker file or where? Tried to search around but could not find it. I know I'm kind of a blind guy

    Thank you in advance...

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


    Did you find this post helpful? Yes | No

    Default

    If you compile using something like Microchips Assembler (which you would do for things like the 18F series), then looking at the end of the generated .LST file you will find a couple of lines like...

    Program Memory Bytes Used: 15998
    Program Memory Bytes Free: 386

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie View Post
    If you compile using something like Microchips Assembler (which you would do for things like the 18F series), then looking at the end of the generated .LST file you will find a couple of lines like...

    Program Memory Bytes Used: 15998
    Program Memory Bytes Free: 386
    Thank you Melanie

    But where can I see how much my variables need/consume space? Perhaps the same way as program memory bytes used are showed...

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


    Did you find this post helpful? Yes | No

    Default

    I don't know if it is valid, but it seems to work for me -

    To figure how much free RAM I have, I create a dummy aray variable and compile.

    dummy var byte (1000)

    If there is no compile error, I figure I have at least 1000 bytes of free memory. I delete the line and go on.


    I use MCLoader often in my programs. It occupies some space in high memory. I used to find that I would compile a program and get no errors, only to find that when I actually loaded the code in the part (that already had MCLoader in it), I got an over-run error. I solved that problem by including the following lines at the very end of my program -

    Code:
    ASM
         ORG 0x1fcee        ; a few bytes below MCLoader when used in a 128K part
         nop
    ENDASM
    You can put any address you want after the ORG statement. If your program gets bigger than that, you will get a compile error. I have found this technique to be useful in lots of ways.
    Charles Linquist

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    This might help.
    It is a little program I have been playing with that reads the LST file and pulls some info from it.

    It is a work in progress so it may not be 100% accurate and it seems to work better on 18Fs.
    Some of those LST file can be quite large.

    Click on the link below and save. The is nothing to install. Just click and run.
    http://www.mac.mf3x3.com/downloads/lst/LST_V.exe

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3098&stc=1&d=123165757 1">
    Attached Images Attached Images  
    Dave
    Always wear safety glasses while programming.

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    This might help.
    It is a little program I have been playing with that reads the LST file and pulls some info from it.

    It is a work in progress so it may not be 100% accurate and it seems to work better on 18Fs.
    Some of those LST file can be quite large.

    Click on the link below and save. There is nothing to install. Just click and run.
    http://www.mac.mf3x3.com/downloads/lst/LST_V.exe
    Thank you Charles and Dave!

    The List View seems to work just perfectly ...
    I just don't understand why not PBP do show more info especially when it would be quite easy to incorporate all that info into the compilation output... Perhaps the time is not ready yet?

    Thank you all for the help on this matter

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink With MPLAB, now ...

    Hi,

    Thanks, Dave ... nice tool. ( heuuu .. could you just keep the last opened folder in the "open" window ??? )

    Another way in MPLAB ... the "Memory usage gauge" works with PBP !!!

    just open the "mem usage Gauge" and use " File \ Import \ Myfile.hex " in the menu ... the program "Camembert" ( understand : meter ) will work as it should ... but not the Data one ...

    Alain
    Last edited by Acetronics2; - 11th January 2009 at 14:32.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Thanks, Dave ... nice tool. ( heuuu .. could you just keep the last opened folder in the "open" window ??? )
    Thanks.
    That is one of the things I will add on the next version (someday).

    BTW. Here is the source code, written in Liberty Basic.
    I will most likely use Python the next time.
    Code:
    [setup.main.Window]
    
        '-----Begin code for #main
    
        nomainwin
        WindowWidth = 550
        WindowHeight = 225
        UpperLeftX=int((DisplayWidth-WindowWidth)/2)
        UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    
    
        '-----Begin GUI objects code
    
        statictext #main.statictext1, "Code Path and Name",   5,  47, 155,  20
      '  TextboxColor$ = "white"
        textbox #main.name,   5,  67, 530,  25
        statictext #main.statictext3, "Program Memory",   5, 122, 120,  20
        statictext #main.statictext4, "Chip",  10,  17,  27,  20
        textbox #main.chip,  45,  17, 100,  25
        statictext #main.statictext6, "Free", 240, 102, 105,  20
        textbox #main.ByteWord, 130, 122, 50,  25
        textbox #main.FreeWord, 210, 122, 100,  25
        statictext #main.statictext8, " Used", 355, 102,  55,  20
        textbox #main.UsedWords, 325, 122, 100,  25
        statictext #main.statictext12, "Percent Used", 440, 102,  82,  20
        textbox #main.PercentWord, 435, 122, 100,  25
        button #main.btOPEN,"OPEN",[btOPEN], UL, 345,  17,  80,  25
        button #main.btREFRESH,"REFRESH",[btREFRESH], UL, 440,  17,  95,  25
        statictext #main.statictext16, "SRAM (BYTES)",  35, 152, 120,  20
     '   statictext #main.statictext15, "EEPROM (BYTES)",  30, 177, 140,  20
        textbox #main.ramF, 210, 152, 100,  25
     '   textbox #main.eepF, 210, 182, 100,  25
        textbox #main.ramU, 325, 152, 100,  25
     '   textbox #main.eepU, 325, 182, 100,  25
        textbox #main.ramP, 435, 152, 100,  25
     '   textbox #main.eepP, 435, 182, 100,  25
        statictext #main.txtWORKING, "WORKING", 185,  17,  85,  20
        statictext #main.txtFINISHED, "FINISHED", 185,  17,  75,  20
    
    
        '-----End GUI objects code
    
        open "LST VIEW" for window as #main
        print #main.UsedWords, "!font ms_sans_serif 10 bold"
        print #main, "font ms_sans_serif 10"
        print #main.statictext3, "!font ms_sans_serif 10 bold"
        print #main.statictext16, "!font ms_sans_serif 10 bold"
     '   print #main.statictext15, "!font ms_sans_serif 10 bold"
        print #main.txtWORKING, "!font ms_sans_serif 10 bold"
        print #main.txtFINISHED, "!font ms_sans_serif 10 bold"
        print #main, "trapclose [quit.main]"
    
        [main.inputLoop]   'wait here for input event
       ' print #handle.ext, "!hide"
        print #main.txtWORKING, "!hide"
        print #main.txtFINISHED, "!hide"
        wait
    
        [btOPEN]   'Perform action for the button named 'btOPEN'
        filedialog "OPEN ","C:\*.lst", openfile$
        if openfile$ = "" then wait
        [rFresh]
        open openfile$ for input as #Lfile
        print #main.name, openfile$
        print #main.txtWORKING, "!show"
        print #main.txtFINISHED, "!hide"
        [LOOPcn]
        line input #Lfile, line$
        if mid$(line$,29,9)= "RAM_START" then RS$ = mid$(line$,68,6)
        if mid$(line$,29,7)= "RAM_END" then RE$ = mid$(line$,68,6)
        if mid$(line$,69,11)= "RAM_START +" then RFIN$ = mid$(line$,81,6)
       ' if mid$(line$,29,9)= "RAM_START" then #main.ramF,mid$(line$,68,6)
       ' if mid$(line$,29,7)= "RAM_END" then #main.ramU,mid$(line$,68,6)
        if mid$(line$,1,26)= "Program Memory Bytes Used:" then #main.UsedWords,mid$(line$,27,92)
        if mid$(line$,1,26)= "Program Memory Words Used:" then #main.UsedWords,mid$(line$,27,92)
        if mid$(line$,1,26)= "Program Memory Bytes Free:" then #main.FreeWord,mid$(line$,27,92)
        if mid$(line$,1,26)= "Program Memory Words Free:" then #main.FreeWord,mid$(line$,27,92)
        if mid$(line$,1,2)= "__" then #main.chip,mid$(line$,3,12)
        if eof(#Lfile) = -1 then [closeFILE1]
        goto [LOOPcn]
        '###################################################
        [closeFILE1]
        close #Lfile
        open openfile$ for input as #Lfile
        [LOOPpm]
        line input #Lfile, line$
        if mid$(line$,1,26)= "Program Memory Bytes Used:" then #main.ByteWord,mid$(line$,16,5)
        if mid$(line$,1,26)= "Program Memory Words Used:" then #main.ByteWord,mid$(line$,16,5)
        if eof(#Lfile) = -1 then [closeFILE2]
        goto [LOOPpm]
        '####################################################
        [closeFILE2]
        close #Lfile
        print #main.chip, "!contents? cName$"
        bFile$ = "C:\PBP\";(trim$(cName$));".bas"
      '  print #main.eepP,bFile$
       goto [closeFILE]
        wait
    
        [btREFRESH]   'Perform action for the button named 'btREFRESH'
        if openfile$ = "" then [rfERROR]'notice "SELECT FILE"
        goto [rFresh]
        wait
    
        [closeFILE]
      '  close #Lfile
        print #main.UsedWords,"!contents? UW"
        print #main.FreeWord,"!contents? FW"
        TW = UW + FW
        PW = (UW / TW) * 100
        print #main.PercentWord,using("###.##",PW)
        ramS = hexdec(RS$)
        ramE = hexdec(RE$)
        ramT = ramE - ramS + 1
        ramF = hexdec(RFIN$)
        ramU = ramF - ramS
        ramFree = ramT - ramU
        ramP = (ramU / ramT) * 100
        print #main.ramF,ramFree
        print #main.ramU,ramU
        print #main.ramP,using("###.##",ramP)
        print #main.txtWORKING, "!hide"
        print #main.txtFINISHED, "!show"
        wait
    
        [rfERROR]
        notice "SELECT FILE"
        goto [main.inputLoop]
        wait
    
        [quit.main] 'End the program
        close #main
        end
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Talking

    Hi, Dave

    You will laugh, but ...

    I decided long time ago to be ONLY a Computer USER !!! ...

    MUCH better for Health ... lol

    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 " !!!
    *****************************************

  10. #10
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Dave

    You will laugh, but ...

    I decided long time ago to be ONLY a Computer USER !!! ...

    MUCH better for Health ... lol

    Alain
    Yep, got a chuckle hearing that from you
    I think sometimes I should decide as you did.
    Dave
    Always wear safety glasses while programming.

  11. #11
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    I have some code that I have been working on for a PIC12F675. When I try to add another variable to it and then compile, I get - Error: Unable to fit variable y -. I am using the latest pbp, microcode studio, and mpasm v8.15. When I use Mackrackit's LST View program, it shows my successful compile (one less variable) as using about 70 percent of the code space, and 48 percent of the sram space. What would be stopping me from being able to use the other half of my sram? I looked in the 12F675.BAS file, and my memory map is BANK0 $0020, $005F, which is correct in the data sheet. 12F675 is selected in mcs.

    Confused....
    http://www.scalerobotics.com

  12. #12
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Can you post your code?
    Dave
    Always wear safety glasses while programming.

  13. #13
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    My code isn't really this, but I get similar results using this example:

    Code:
    myvar1 var byte
    myvar2 var byte
    myvar3 var byte
    myvar4 var byte
    myvar5 var byte
    myvar6 var byte
    myvar7 var byte
    myvar8 var byte
    myvar9 var byte
    myvar10 var byte
    myvar11 var byte
    myvar12 var byte
    myvar13 var byte
    myvar14 var byte
    myvar15 var byte
    myvar16 var byte
    myvar17 var byte
    myvar18 var byte
    myvar19 var byte
    myvar20 var byte
    myvar21 var byte
    myvar22 var byte
    myvar23 var byte
    myvar24 var byte
    myvar25 var byte
    myvar26 var byte
    myvar27 var byte
    myvar28 var byte
    myvar29 var byte
    myvar30 var byte
    myvar31 var byte
    myvar32 var byte
    myvar33 var byte
    myvar34 var byte
    myvar35 var byte
    myvar36 var byte
    myvar37 var byte
    myvar38 var byte
    myvar39 var byte
    myvar40 var byte
    myvar41 var byte
    I admit this is more than 48.44 percent of the 64 bytes of SRAM. I am not clear how to check SRAM use in any other way than using your program. Perhaps PBP uses the other bytes for itself. But then, your program should account for actual use, since it is using the lst file.

    Let me know what you think.

    Thanks,

    Walter
    Last edited by ScaleRobotics; - 9th June 2009 at 20:43.
    http://www.scalerobotics.com

  14. #14
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I played with this some last night, did some reading and could not find a solution.
    Maybe Darrel or Bruce will chime in...
    Dave
    Always wear safety glasses while programming.

  15. #15
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    I played with this some last night, did some reading and could not find a solution.
    Maybe Darrel or Bruce will chime in...
    DING!

    PBP's system vars use a minimum of 24 bytes.
    Complex formulas can increase that, but it appears you don't have any of those yet.

    So you create 40 additional byte variables and it's full. (24 + 40 = 64)

    As for "LST View" ...

    It apparently just looks for the last occurrence of "RAM_START +" and uses that address to calculate how much RAM was used.

    That address is already referenced to RAM_START, but in the program, this line subtracts the start address again, which leaves the count too low.
    Code:
    ramU = ramF - ramS
    Add 20h (32) to the 31 bytes reported and you get 63, the last address in RAM.

    I think that line should be ...
    Code:
        ramU = ramF + 1
    However, RAM assignments are not always contiguous. You could have a single variable in BANK3 (chip other than 675) and it'll show almost all the RAM has been used, when there's only a few bytes being used. Or the last address may be the beginning of an array, which it won't count either.

    It's a difficult task to count RAM bytes used.
    <br>
    DT

  16. #16
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel.

    I saw where LST View was giving some "funny" results last night also. Now I know why. Time to do a "bug" fix. If possible...
    Dave
    Always wear safety glasses while programming.

  17. #17
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Dave,

    Just a little more info for updating LST View.
    It calculates the Total RAM by taking (RAM_END - RAM_START + 1)
    As an example this is from a 16F877 ...
    Code:
      00000020            00012 RAM_START                       EQU     00020h
      000001EF            00013 RAM_END                         EQU     001EFh
      00000004            00014 RAM_BANKS                       EQU     00004h
      00000020            00015 BANK0_START                     EQU     00020h
      0000007F            00016 BANK0_END                       EQU     0007Fh
      000000A0            00017 BANK1_START                     EQU     000A0h
      000000EF            00018 BANK1_END                       EQU     000EFh
      00000110            00019 BANK2_START                     EQU     00110h
      0000016F            00020 BANK2_END                       EQU     0016Fh
      00000190            00021 BANK3_START                     EQU     00190h
      000001EF            00022 BANK3_END                       EQU     001EFh
    (RAM_END - RAM_START + 1) = 1EFh - 20h + 1 = 464 bytes
    But the 16F877 only has 368 bytes.

    The extra count is from the SFR's that are at the top of each bank.

    GP RAM in each bank doesn't start at the same place on every 16F, so I think you'll need to find the amount in each bank and add them together to get the total RAM.
    Code:
    (BANK0_END - BANK0_START + 1) + (BANK1_END - BANK1_START + 1) + (BANK2_END - BANK2_START + 1) + (BANK3_END - BANK3_START + 1)
    (  0007Fh  -   00020h    + 1) + (  000EFh  -   000A0h    + 1) + (  0016Fh  -   00110h    + 1) + (  001EFh  -   00190h    + 1)
    (            60h            ) + (            50h            ) + (            60h            ) + (            60h            )
    = 170h = 368
    Then it's the same for the Used RAM. You need to subtract the SFR space from the variables address, or somehow reference it to the BANKx_START of the bank that it's in to find out how much has been used.

    hth,
    DT

Similar Threads

  1. Need the code to write to a memory
    By Hamlet in forum General
    Replies: 0
    Last Post: - 20th August 2007, 00:22
  2. Replies: 4
    Last Post: - 2nd March 2007, 06:12
  3. sample code for M25P32
    By Pedro Santos in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th January 2007, 02:37
  4. Use internal program memory like DATA memory
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th December 2006, 18:38
  5. memory button
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 12th February 2006, 09:47

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