Shop OBEX P1 Docs P2 Docs Learn Events
BS2 code file size limits? — Parallax Forums

BS2 code file size limits?

Otaku1031Otaku1031 Posts: 34
edited 2011-03-22 15:02 in General Discussion
Hi all,
Quick question on BS2 file size limits. The documentation says a limit of 2KB (~500 lines), but I'm currently running a file that's reported by Windows to be 9KB. There's about 350 lines in the program. What's the real file size limit in KB, or is it based on the number of lines only?

Comments

  • Tracy AllenTracy Allen Posts: 6,666
    edited 2011-03-07 17:33
    The 2k has to do with the size of the final tokenized code when it is loaded into the Stamp with a RUN command. The file size on the Windows PC in the development environment will be much larger.

    You can see how memory on the Stamp is filling up by pressing the Ctrl-M (for Memory) option. There is a display on the left that shows the program space, with your DATA statements working down from the top and the program itself working up from the bottom. A display on the right shows how you are using the RAM memory where your variables are stored.
  • Otaku1031Otaku1031 Posts: 34
    edited 2011-03-08 16:55
    Thanks, Tracy. I did bump my head today trying to upload a program. The reported file size (not the disk space used per Windows) was just a bit over 9KB. I had to trim it down to < 9KB to get it to load. I'll check out the Ctrl-M feature in the morning; sounds like a very useful tool.
  • Mike GMike G Posts: 2,702
    edited 2011-03-08 18:12
    Adding comments to a BS2 file will increase the file size. Comments are no included in tokenized code. What you're reporting does not make sense or there is no enough information. Post your source code if you still need help.
  • Otaku1031Otaku1031 Posts: 34
    edited 2011-03-10 08:45
    I've been going through some posts from 2003, and I think I found the problem. I have several For-Next loops in the code that cycle every 20ms. The loops are set to run 500X for a total time of 10s. They don't always need to run the full 500X but I had to declare the Variable ("Counter") as Word because the next available variable type is Byte which only allows a max of 255. Is the type of variable I'm using for the loop count register causing the BS2 to reserve large amounts of memory, thus reducing the maximum file size? Is there a better way to allocate memory resources so that the file size won't be so restricted? I'll be happy to post the code if it will help, but not sure how to do that.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-10 08:51
    Using word variables will not make the code size significantly different (from using byte variables).

    To attach code to a message, you can use the "+ Reply to Thread" button, but then click on the "Go Advanced" button. You'll get a large, complex window that includes a "Manage Attachments" button. That will let you attach one or more files to your message.

    There's no way to increase the 2K compile code size limit. You can break your program up into 2K pieces and, with some Stamp models, have several 2K pieces that work like overlays, but it requires some work on your part and isn't the same as having one large program.

    Usually there's a lot of code space to be saved by separating out repeated pieces of code as subroutines so the code isn't duplicated multiple times. Also, strings in I/O statements take a lot of memory (at least the length of the string ... and duplicates are not combined).
  • Otaku1031Otaku1031 Posts: 34
    edited 2011-03-10 09:25
    Thanks for the reply, Mike. I am using several subroutines to minimize code repetition, and there are more opportunities in the program to do that. I'll revise the code to include the new subs and see what happens. I'll post the revised code.
  • Otaku1031Otaku1031 Posts: 34
    edited 2011-03-22 10:06
    Hi all,
    Here's the code I'm running. If I go above ~9KB on the file size I get an error msg "EEPROM Full" or something to that effect. Any ideas as to why this is happening? Thanks for all advice!

    Gary
  • Mike GMike G Posts: 2,702
    edited 2011-03-22 10:22
    The file size is not directly related to EEPROM size! Comments take up space too.

    You have tons of single PIN commands that could be combined using the dedicated pin registers like IN DIR and OUT.
     HIGH 6
     HIGH 7
     HIGH 8
     HIGH 3
     HIGH 4
     HIGH 5
    
      DIRS = $FF  'Make all pins outputs
      OUTS = %0000000111111000  'Set 3, 4, 5, 6, 7, & 8 high or $FC
    

    Run this as an example
    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    
    counter   VAR   Nib
    value     VAR   Nib
    
    counter = 0
    value = 0
    
    
    Main:
      ' Init
      DIRS = $FF  'Make all pins outputs
      OUTS = $00  'Set pins low
    
      GOSUB WritePins
      PAUSE 100
      GOSUB ReadPins
      PAUSE 100
      GOSUB DisplayPins
      PAUSE 1000
    
    GOTO Main
    
    ' Increment
    WritePins:
      OUTA = counter
      counter = counter + 1
    RETURN
    
    ' Read pins
    ReadPins:
      value = INA
    RETURN
    
    
    'Display pins
    DisplayPins:
      DEBUG CLS
      DEBUG BIN ?value
    RETURN
    
  • Otaku1031Otaku1031 Posts: 34
    edited 2011-03-22 10:26
    Cool, thanks Mike! I'll do some studying on the commands you listed (IN DIR, OUT). More to come.
  • Mike GMike G Posts: 2,702
    edited 2011-03-22 10:33
    You should have only one NTC_Relays: routine. Just set the variables and call the routine. At first glance, your code can be reduced to very small footprint.
  • Otaku1031Otaku1031 Posts: 34
    edited 2011-03-22 15:02
    The NTC_Relay and STC_Relay routines use eight different variable settings for pins 0, 1, and 2 in various combinations. These are the decoded outputs for a CD4051E multiplexer. I'll look into how to set those high/low pin conditions. Thanks again!
Sign In or Register to comment.