picbasic +12c508a+soft_stack error


Closed Thread
Results 1 to 37 of 37

Hybrid View

  1. #1
    Join Date
    Dec 2007
    Posts
    7

    Default picbasic +12c508a+soft_stack error

    Hi
    I wrote a simple basic program for my PIC (12c508A) in a Picbasic Pro compiler
    but I have this error after compilation "unable to fit variable soft_stack"
    please see my program below and tell me the errors as I am beginner in PIC programming .
    Thanks


    lowinput VAR GPIO.0
    overtemprature VAR GPIO.1
    overload VAR GPIO.2
    outputpin VAR GPIO.3
    green VAR GPIO.4
    red VAR GPIO.5
    count1 var byte
    i var byte

    OUTPUT outputpin
    input lowinput
    input overtemprature
    input overload
    OUTPUT green
    OUTPUT red

    while i=0
    if (lowinput=0) and (overload=0) and (overtemprature=0) then

    outputpin =0
    High green
    Pause 500
    Low green
    Pause 500

    ENDIF


    if (lowinput=0) and (overload=1) and (overtemprature=0) then

    while count1<2
    gosub overloadmode
    count1=count1+1
    wend
    outputpin =1

    while count1<7
    gosub overloadmode
    count1=count1+1
    wend

    outputpin =0
    count1=0
    ENDIF

    if (lowinput=1) and (overload=0) and (overtemprature=0) then

    while count1<5
    gosub lowinputmode
    count1=count1+1
    wend
    outputpin =1
    count1=0
    ENDIF
    if (lowinput=0) and (overload=0) and (overtemprature=1) then

    while count1<5
    gosub overtempraturemode
    count1=count1+1
    wend
    outputpin =1
    count1=0
    ENDIF
    if (lowinput=1) and (overload=1) and (overtemprature=0) then

    while count1<5
    gosub overtempraturemode
    count1=count1+1
    wend
    outputpin =1
    count1=0


    endif


    wend


    overloadmode:
    High green
    low red
    Pause 500

    Low green
    high red
    Pause 500
    return

    lowinputmode:
    High green
    low red
    Pause 500

    Low green
    high red
    Pause 500
    return

    overtempraturemode:

    High green
    high red
    Pause 500

    Low green
    low red
    Pause 500

    return

    end

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


    Did you find this post helpful? Yes | No

    Default

    you may need to move on a bigger RAM PIC such as PIC12C509. 12C508 have 25 bytes of RAM, while 12C509 have 41 + twice the program space size.

    The compiler use between 20 & 22 bytes of RAM itself.. so... no real space for more variables
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    A 12F might be a good choice. Cheaper too.

    However, what you have should fit, with a little modification.


    The complex IF statements are creating 3 (T)emp vars, which are word sized. (even though it's only using 1 bit per WORD)
    So it's using 6 bytes that it doesn't really need too.

    If you change all the IF statements to something like this for the first one, I believe it should fit.

    Code:
        ;if (lowinput=0) and (overload=1) and (overtemprature=0) then
        if (lowinput=0) THEN
            if (overload=1) THEN
                if (overtemprature=0) THEN
                    while count1<2
                    gosub overloadmode
                    count1=count1+1
                    wend
                    outputpin =1
                    
                    while count1<7
                    gosub overloadmode
                    count1=count1+1
                    wend
                    
                    outputpin =0
                    count1=0
                ENDIF
            ENDIF
        ENDIF
    hth,
    DT

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


    Did you find this post helpful? Yes | No

    Default

    i was thinking of a select case and GPIO mask. mmm...

    edit: Seems to work
    Code:
    lowinput VAR GPIO.0
    overtemprature VAR GPIO.1
    overload VAR GPIO.2
    outputpin VAR GPIO.3
    green VAR GPIO.4
    red VAR GPIO.5
    count1 var byte
    Mask var byte
    
    
    OUTPUT outputpin
    input lowinput
    input overtemprature
    input overload
    OUTPUT green
    OUTPUT red
    
    Start:
            mask=GPIO & 7
            select case mask
                    case %000 ;if (lowinput=0) and (overload=0) and (overtemprature=0) then
                        outputpin =0
                        High green
                        Pause 500
                        Low green
                        Pause 500
    
                    case %100 ;if (lowinput=0) and (overload=1) and (overtemprature=0) then
                        while count1<2
                            gosub overloadmode
                            count1=count1+1
                            wend
                        outputpin =1
                        
                        while count1<7
                            gosub overloadmode
                            count1=count1+1
                            wend
                        
                        outputpin =0
                        count1=0
    
                    case %001 ;if (lowinput=1) and (overload=0) and (overtemprature=0) then
                        while count1<5
                            gosub lowinputmode
                            count1=count1+1
                            wend
                        outputpin =1
                        count1=0
                    
                    case %010 ;if (lowinput=0) and (overload=0) and (overtemprature=1) then
                        while count1<5
                            gosub overtempraturemode
                            count1=count1+1
                            wend
                        outputpin =1
                        count1=0
    
                    case %101 ;if (lowinput=1) and (overload=1) and (overtemprature=0) then
                        while count1<5
                            gosub overtempraturemode
                            count1=count1+1
                            wend
                        outputpin =1
                        count1=0
                    end select
    
            goto Start
    
    
    overloadmode:
            High green
            low red
            Pause 500
    
            Low green
            high red
            Pause 500
            return
    
    lowinputmode:
            High green
            low red
            Pause 500
            
            Low green
            high red
            Pause 500
            return
    
    overtempraturemode:
            
            High green
            high red
            Pause 500
            
            Low green
            low red
            Pause 500
            
            return
    
            end
    Last edited by mister_e; - 16th December 2007 at 21:10.
    Steve

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

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    . . . .

    The compiler use between 20 & 22 bytes of RAM itself.. so... no real space for more variables
    Hello Mister_E
    Could you please explain? This statement appears to me to mean PIC BASIC PRO is an intrepreted code, if not why would the compiler require any of the PIC's ram?
    Thank You
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Default

    Yeah but the library/compiler need to reserve some variable to work to not interfer with your code... euh.. that's my understanding

    support for 12 bit core is limited, and the real explanation can be found at the bottom of the folowiing page
    http://www.melabs.com/support/12-bit.htm

    so why 20-22... i don't know, seems hungry to me.. but, you have to deal with it.

    We already heard something like that for 10F and bring some weird/nasty/dangerous/clever alternate solutions, some who remind...
    http://www.picbasic.co.uk/forum/showthread.php?t=4789&

    HTH
    Last edited by mister_e; - 16th December 2007 at 23:41.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    After converting all the IF statements like I suggested above, it did fit in RAM,
    and it compiled to 313 WORDS.

    mister_e,
    Yours fit in RAM too, and compiled to 295 WORDS. (unexpected for Select Case)

    You know what that means RIGHT?
    Yup, this ain't over yet!

    172 WORDS
    Code:
    @ DEVICE WDT_OFF
    DEFINE NO_CLRWDT 1 ' Don't kick the Dog 
    
    lowinput       VAR GPIO.0
    overtemprature VAR GPIO.1
    overload       VAR GPIO.2
    outputpin      VAR GPIO.3
    green          VAR GPIO.4
    red            VAR GPIO.5
    FlashCount     var byte
    FlashPattern   var byte
    
    TRISIO = %000111
    
    Start:
        If (lowinput=0) then
            IF (overload=0) then             ; lowinput, overload, overtemprature
                if (overtemprature=0) then                      ; 000
                    outputpin = 0
                    FlashCount = 1 
                    FlashPattern = %0001  ; ModeOK
                    GOSUB FlashLEDs
                else                                            ; 001
                    FlashCount = 5
                    FlashPattern = %0011  ; overtempraturemode
                    gosub FlashLEDs
                    outputpin = 1
                endif
            else                                                ; 010
                if (overtemprature=0) then           
                    FlashCount = 2
                    FlashPattern = %1001  ; overloadmode
                    gosub FlashLEDs
                    outputpin =1
                    
                    FlashCount = 7
                    gosub FlashLEDs
                    outputpin =0
                else                                            ; 011
                    ; --- Action undefined ---
                endif
            endif
        else
            if (overload=0) then                     
                if (overtemprature=0) then                      ; 100
                    FlashCount = 5
                    FlashPattern = %1001  ; lowinputmode
                    gosub FlashLEDs
                    outputpin =1
                else                                            ; 101
                    ; --- Action undefined ---
                endif
            else                                                ; 110
                if (overtemprature=0) then           
                    FlashCount = 5
                    FlashPattern = %0011  ; overtempraturemode
                    gosub FlashLEDs
                    outputpin =1
                else                                            ; 111
                    ; --- Action undefined ---
                endif
            endif
        endif
    GOTO Start
    
    FlashLEDs:
        REPEAT
             green = FlashPattern.0
             red   = FlashPattern.1
             Pause 500
    
             green = FlashPattern.2
             red   = FlashPattern.3
             Pause 500
             FlashCount = FlashCount - 1
        UNTIL (FlashCount = 0)
    return
    However, omid_juve,

    There are 3 states that are not accounted for

    lowinput=0 overload=1 overtemprature=1
    lowinput=1 overload=0 overtemprature=0
    lowinput=1 overload=1 overtemprature=1

    It may be intentional. Maybe they aren't needed. But normally, unchecked states will cause havoc in your program.

    If we knew what was supposed to happen in those states, I think mister_e ..., uh I mean, I could probably reduce it further.
    DT

  8. #8
    Join Date
    Dec 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    it a program for 24v to 12v converter that has 3 input 1.over temperature 2.low input 3.overload and we have 3 output that 2 of them is just indicator and one (outputpin)
    is the output for controlling the output voltage according to the situation of inputs.
    and just the modes that you saw in the program can occur .
    thanks for all of your help. my problem is solved .

Similar Threads

  1. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 9th December 2008, 00:40
  2. Optimizing DIV
    By skimask in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 22nd September 2008, 05:58
  3. pbp245 compliation error
    By Woodzy in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 25th July 2006, 06:59
  4. 16F88 Compile error
    By Toley00 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 2nd November 2005, 01:22
  5. Compiler/Assembler Error
    By LT_Pic in forum General
    Replies: 7
    Last Post: - 21st July 2005, 10: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