​ ​ ​ ​ How to make my program smaller?
Results 1 to 7 of 7

Thread: How to make my program smaller?

  1. #1

    Default How to make my program smaller?

    Hi,
    I did not think that my project was very complicated but it has turned out so big that Logicator will not simulate it, telling me that it is far to big. I'm not really sure why this is, the datasheet on the 40X2 said that it can handle up to 3000 lines of code over 4 slots (this I do not get) but my code only goes up to 1100.

    I have attached a cut down version of my program. The basic idea is:
    Open the LCD with a start screen
    Set count loop to 1
    Check RL1 through RL3 to make sure they are open, if not display error & sound alarm
    Turn on RL1 through RL3
    Check RL1 through RL3 to make sure they are closed, if not display error & sound alarm
    add 1 to the count loop & repeat.

    IN this cut down version I am checking 3 inputs for both open & closed states, the full program needs to check 27 inputs.
    I would love to know one of two things(or both) ...... am I doing something wrong where I should have space for 1100 lines of code ...... or am I missing a trick while trying to check & display 54 different errors?
    Attached Files Attached Files

  2. #2
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    23,048

    Default

    Text messages quickly eat up program space and will reduce the number of lines you can have. Each flowchart cell will often generate more than one line of Basic language code and can be less efficient than code written directly in Basic.

    There may be some tips which can help you reduce program code size but it may be that the program is too ambitious for flowcharting.

    I suspect it may be the way you are detecting your 54 conditions.

    It's hard to tell what might be the problem in code which isn't there, so perhaps post your full flowchart even though it is too large to program into the PICAXE.

  3. #3

    Default The big one

    Cheers hippy,
    I didn't want to put the complete thing in here as it is just the same, only more. I guess working out the problem would be 'pretty' hard without it.

    Flowchart & code.

    Sorry, I cannot post the code in this window as it is too big. It is attached.
    Attached Files Attached Files

  4. #4
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    23,048

    Default

    Your "RL1 off" etc subroutines are all very similar and are each eating up quite a bit of memory, using 84 bytes each. You have 68 of those and 68 x 84 is 5718 bytes, plus the rest of the code outside those routines.

    You really need to refactor the code so the testing can be done by indicating what should be tested, what the error message should be, and calling a single subroutine to do that test. For example your current call to the RLY1_OFF test could become -

    [ If pinA.0 <> 0 ]--Yes-->[ LCD "RL1 SHORT" ]-->[ Call ALARM ]

  5. #5

    Default

    Is this something I can do within the flowcharts of Logicator, or will I have to move over to basic to do this?
    (I will be honest and say that although I can sort of understand what that line of code does, I would not know how to implement it in my program)

  6. #6
    Technical Support
    Join Date
    Jan 1970
    Location
    UK
    Posts
    23,048

    Default

    You should be able to do it in Logicator but Basic would probably be easier.

    That 'line of code' was a textual representation of what the flowchart cells would be and what is inside them.

    One of the advantages of Basic is that it's purely textual so easy to say replace -

    Code:
    Main:
      :
      gosub RL1_OFF
      :
    
    RL1_OFF:
      if pinA.0=0 then
        serout A.4, N2400, (254, 128, "     ERROR      ")
        serout A.4, N2400, (254, 192, "    RL1 SHORT   ")
        gosub prc_ALARM
      end if
    return
    With -

    Code:
    Main:
      :
      if pinA.0=0 then
        serout A.4, N2400, (254, 192, "    RL1 SHORT   ")
        gosub ShowTopLineErrorAndSoundAlarm
      end if
      :
    It is harder to do that when the programming language is visual, and what is actually being done is hidden behind those visuals.

  7. #7

    Default

    That was real close.
    While desperately trying to stay inside the Logicator flowchart domain, I did what you suggested. Removing the text line 'error' from each LCD procedure and replacing them with a single gosub has allowed me to get down below the 4096 limit.
    Although I had to remove some 'bells & whistles', it should now fit on the chip.

    Cheers hippy

Bookmarks

Posting Permissions

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