Shop OBEX P1 Docs P2 Docs Learn Events
Error : overwrite same program counter location — Parallax Forums

Error : overwrite same program counter location

loojadeloojade Posts: 30
edited 2008-02-27 16:47 in General Discussion
Hallo everybody

I nebie with SXB and I don't know assembly... I write a program and it seems correct, but when I try to run it some errors appear.
The main problem is that the errors are in assembly code (geneterd by SX KEY I think).

This is my SXB code :

[code]

'
' Program Description
'
'
' GRIPOne

Comments

  • BeanBean Posts: 8,129
    edited 2008-02-21 13:29
    You cannot declare SUBs before the INTERRUPT command.
    Do this:

    ' -------------------------------------------------------------------------
    INTERRUPT 50_000
      GOTO ISR_Start
    ' -------------------------------------------------------------------------
    
     
    ' -------------------------------------------------------------------------
    ' Subroutine Declarations
    ' -------------------------------------------------------------------------
    
    CHECK_SPINNING  SUB     0                       ' 
    MEM_OUT         SUB     3                       ' write value to memory
    MEM_IN          SUB     2                       ' read byte from memory
    
    ' -------------------------------------------------------------------------
    
    ISR_Start:
    
    Ch1:
    
    

    You have some problems in your code though. For example from within the interrupt routine you are using "GOTO Check_Spinning", but that is a subroutine. If you really just want to call the Check_Spinning subroutine, just use "Check_Spinning" without the goto.

    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • loojadeloojade Posts: 30
    edited 2008-02-21 14:48
    Thanks Bean,

    You are very kind and fast to reply...
    I'll try like you show me.
    I change the position of SUB declaration because If I try to put it after the INTERRUPT code, it was impossible call the SUB.
    But like this should be ok.

    Thanks again

    Loojade
  • loojadeloojade Posts: 30
    edited 2008-02-25 21:44
    I change a bit the the code but compiling the same eror appeare...
    "overwriting same program location"
    and to the next row: "address exceeds memory limit"

    this is the SXB code:

    [code]

    '
    ' Program Description
    '
    '
    ' GRIPOne
  • JonnyMacJonnyMac Posts: 9,216
    edited 2008-02-25 22:46
    You have very large interrupt structure -- you might consider trimming that down. Another strategy, often used by forum guru PJV, is to simply let the ISR mark a flag that the foreground waits for; once the flag has been detect the foreground program can go forward with a large chuck of code (so long as it's not so large that the flag gets reset before the code is done).
  • pjvpjv Posts: 1,903
    edited 2008-02-26 05:34
    Hi Jonny;

    Actually, things can be simply improved if the flag is replaced by a counter (as in my more recent examples), and the foreground simply tests it for a non-zero value, then proceeds with the foreground code (as it did with the flag), and decrements the counter by one. If, on completing the foreground task, the counter still is not zero, perhaps because it took longer than one interrupt tick, the foreground program is again immediately launched with another round, repeating all this until the couner is empty.

    In this manner, no ticks are lost, regardless (almost) of the size of the foreground program. At worst a bit of jitter is introduced.


    Interrupt······· ·inc········· Intcounter··················· ;indicate another interrupt has occurred
    ···················· mov······ ·w, #IntValue··············· ·;return to main or scheduler
    ···················· retiw


    Scheduler······ test·········IntCounter··················· ;test for non-zero
    ····················snz
    ··················· jmp········ Scheduler···················· ·;no tick is detected
    ··················· dec·········IntCounter···················· ;subtract one interrupt event
    ··················· scheduler code··························· ·;scheduler and application code as per "flag" examples
    ··················· .
    ··················· .
    ··················· scheduler code
    ··················· jmp······· Scheduler······················ ·;wait for another interrupt


    Cheers,

    Peter (pjv)


    Post Edited (pjv) : 2/26/2008 5:41:52 AM GMT
  • JonnyMacJonnyMac Posts: 9,216
    edited 2008-02-26 15:09
    That's a cool idea, Peter, thanks for sharing.
  • loojadeloojade Posts: 30
    edited 2008-02-27 16:47
    Actually I'm not sure to understud...

    But I change a lot the program. JonnyMac spoken about lot of code in interrupt so I change the code. Now I use the asichro interrupt to fix the counter
    and the main program to INC the counter:

    
    ...
    ISR_Start:
      WKPND_B = winner                            ' get winner
        byte_interrupt = winner
    Ch1:                                                ' check channel
        IF byte_interrupt <> %00000001 THEN Ch2             ' if not, try next
        last_fr_l = counter_fr_l                        'quando l'ingresso cambia di stato salvo il valore del contatore  e azzero il contatore
        last_fr_h = counter_fr_h
        counter_fr_l = 0
        counter_fr_h = 0
        GOTO ISR_Exit
    
    Ch2:
        IF byte_interrupt <> %00000010 THEN Ch3             ' if not, try next
        last_rr_l = counter_rr_l                        'quando l'ingresso cambia di stato salvo il valore del contatore  e azzero il contatore
        last_rr_h = counter_rr_h
        counter_rr_l = 0
        counter_rr_h = 0
        GOTO ISR_Exit
    
    Ch3:
      IF byte_interrupt <> %00000100 THEN ISR_Exit
        IF controllo = 1 THEN
            IF cicli < taglio THEN
                IF cicli = 0 THEN
                    t_control = 1
                ELSE
                    t_control = 0
                ENDIF
                INC cicli
                IF cicli = taglio THEN
                    cicli = 0
                ENDIF
            ENDIF
        ENDIF
      GOTO ISR_Exit
    
    ISR_Exit:
      WKEN_B = %11111000                            ' prepare for new ISR
    
      RETURNINT
    ...
    
    



    [code]

    ...
    Start:
    WKPND_B = %00000000 ' clear pending
    WKED_B = %11111111 ' falling edge detect
    WKEN_B = %11111000 ' use bits 0..2 for inputs

    TRIS_B = %00011111 ' imposto gli ingressi e le uscite della porta B
    TRIS_C = %00000000 ' imposto gli ingressi e le uscite della porta C

    INPUT SDA ' float I2C bus pins
    INPUT SCL


    counter_fr_l = 255
    counter_fr_h = 255
    counter_rr_l = 255
    counter_rr_h = 255
    last_fr_l = 255
    last_fr_h = 255
    last_rr_l = 255
    last_rr_h = 255
    controllo = 0
    byte_interrupt = 0
    addr = 0
    byte1 = 0

    Main:

    IF button_1 = 1 THEN 'il pulsante di scelta
Sign In or Register to comment.