A more program space efficient way of doing ta whole heap of IFs????


Closed Thread
Results 1 to 18 of 18

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: A more program space efficient way of doing ta whole heap of IFs????

    OK, so let's go with Steve's idea and put it in EEPROM.

    88 words.
    Code:
    supply_in  VAR BYTE
    max_duty   VAR BYTE
    ItemNo     VAR BYTE
    Temp       VAR BYTE
    '
    supply_Max  DATA 252,250,248,245,240,237,234,231,229,226,223,220,218,215,212,210,207,204,201,199,196,193,187,0
    Set_duty    DATA 154,155,156,157,159,160,161,163,165,167,169,172,175,179,181,182,184,188,191,195,214,238,251,255
    '
    FOR ItemNo = 0 TO (Set_duty - supply_Max)
        READ (supply_max + ItemNo), Temp
        IF supply_in > Temp THEN
            READ  (Set_duty + ItemNo), Temp
            max_duty = Temp
            EXIT
        ENDIF
    NEXT ItemNo
    I haven't tested it, but it looks right.
    Check my work.
    DT

  2. #2
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: A more program space efficient way of doing ta whole heap of IFs????

    Wow....what can I say Darrel....you lost me after the elseif post, but I'm gonna read it again & again until it sinks in!

    (also thank you steve ....all great stuff)

    Edit: Even just rolling with the ELSEIF melarkey ...my program now compiles at 1643 words ...it was maxing out before (greater than 2048 words), so even if I never get to understand the EEPROM method (& the initial indications aren't favourable, lol!) then nevertheless you've saved the day!
    Last edited by HankMcSpank; - 27th May 2011 at 12:49.

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Default Re: A more program space efficient way of doing ta whole heap of IFs????

    PICs have 2 areas of memory: codespace, for your program, and eeprom, you use DATA to store data and READ to get at it (you can also WRITE to it during program execution).

    Eeprom is a simple way to store tables and then use For loops to scan through them later. Three common uses; character definitions for LCDs, conversion tables and saving PIN numbers.

    I think Melanie has a thread somewhere on how to use some of that eeprom area for codespace.
    Last edited by Demon; - 27th May 2011 at 13:26.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  4. #4
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: A more program space efficient way of doing ta whole heap of IFs????

    Quote Originally Posted by Demon View Post
    PICs have 2 areas of memory: codespace, for your program, and eeprom, you use DATA to store data and READ to get at it.

    Eeprom is a simple way to store tables and then use For loops to scan through them later. Two common uses; character definitions for LCDs and conversion tables.

    I think Melanie has a thread somewhere on how to use some of that eeprom area for codespace.
    Thanks Robert (a cool name ;-) )...while I'm fairly clued up on how to get the PIC to work now (as well as being reasonably savvy on the electronics /interfacing aspect), the darned pesky coding world is still totally flat in my eyes!! (this is frustrating as I have a head brimmed with ideas...but no quick way to get them out of my fingertips & into a PIC)

    I'll have to take a night out to get the hang of using EEPROM so I'll have a search for any related threads outlining how to get started with them.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: A more program space efficient way of doing ta whole heap of IFs????

    Quote Originally Posted by Darrel Taylor View Post
    OK, so let's go with Steve's idea and put it in EEPROM.

    88 words.
    Code:
    supply_in  VAR BYTE
    max_duty   VAR BYTE
    ItemNo     VAR BYTE
    Temp       VAR BYTE
    '
    supply_Max  DATA 252,250,248,245,240,237,234,231,229,226,223,220,218,215,212,210,207,204,201,199,196,193,187,0
    Set_duty    DATA 154,155,156,157,159,160,161,163,165,167,169,172,175,179,181,182,184,188,191,195,214,238,251,255
    '
    FOR ItemNo = 0 TO (Set_duty - supply_Max)
        READ (supply_max + ItemNo), Temp
        IF supply_in > Temp THEN
            READ  (Set_duty + ItemNo), Temp
            max_duty = Temp
            EXIT
        ENDIF
    NEXT ItemNo
    I haven't tested it, but it looks right.
    Check my work.
    Option 2:
    Could also shave it a lil more, but use a single and larger Lookup...

    Code:
    DATA @188, ....all duty result from 188........256 bytes available btw
    .
    .
    .
    .
    if supply_in< 188   then 
        max_duty = 255
        else
             READ Supply_in, Max_duty
        endif
    couldn't be more simple I guess

    I know you love challenge Darrel :P
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: A more program space efficient way of doing ta whole heap of IFs????

    Quote Originally Posted by Darrel Taylor View Post
    OK, so let's go with Steve's idea and put it in EEPROM.

    88 words.
    Code:
    supply_in  VAR BYTE
    max_duty   VAR BYTE
    ItemNo     VAR BYTE
    Temp       VAR BYTE
    '
    supply_Max  DATA 252,250,248,245,240,237,234,231,229,226,223,220,218,215,212,210,207,204,201,199,196,193,187,0
    Set_duty    DATA 154,155,156,157,159,160,161,163,165,167,169,172,175,179,181,182,184,188,191,195,214,238,251,255
    '
    FOR ItemNo = 0 TO (Set_duty - supply_Max)
        READ (supply_max + ItemNo), Temp
        IF supply_in > Temp THEN
            READ  (Set_duty + ItemNo), Temp
            max_duty = Temp
            EXIT
        ENDIF
    NEXT ItemNo
    I haven't tested it, but it looks right.
    Check my work.
    I originally shyed away from using suggestion, on account the initial idea provided rescued me back sufficient space, but alas, things have just got too tight, so I've just tried this latter suggestion...it worked first time & has rescued me back a good bit of space (room to breathe again!)

    I'll admit I don't totally understand what's going one (other than we're storing stuff in EEPROM, then cleverly marrying it up), I'll addess my inner "huh?" demons & work this out soon, but for now I'm just chuffed the enigma works...as a bonus it's far easier for me to mate the values (the formatting on here clouds it, but it's as clear as day in reality)

    Many thanks.
    Last edited by HankMcSpank; - 19th June 2011 at 12:51.

Members who have read this thread : 0

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