Interrupt problem.


Closed Thread
Results 1 to 15 of 15
  1. #1
    Peter Oors's Avatar
    Peter Oors Guest

    Default Interrupt problem.

    Hello,

    It's the first time I try to use ON INTERRUPT.
    If I compile my program (PBP2.45a), I get an error.
    Error test.mac 46: [235] Opcode Expected Instead of '1'
    If I disable ON INTERRUPT with a " ' " , compiling is ok.

    What's wrong?

    @ DEVICE PIC16F819, INTRC_OSC_NOCLKOUT, MCLR_OFF
    OPTION_REG = %10000000 ' Turn off pull-up resistors
    DEFINE ONINT_USED 1
    OSCCON=$60 ' osc. controller, 70=8MHz, 60=4MHz
    adcon1=7 ' comperator off
    TRISA=%00011111
    TRISB=%11110000
    led VAR PORTB.0

    ON INTERRUPT GoTo myint ' Define interrupt handler
    INTCON = %10001000 ' Enable RBIE interrupt
    loop:
    led=1 ' Turn LED on
    GoTo loop ' Do it forever
    myint:
    Disable ' No interrupts past this point
    led=0 ' If we get here, turn LED off
    Pause 500 ' Wait .5 seconds
    INTCON.0 = 0 ' Clear interrupt flag
    Resume
    Enable

    Stop

    Thanks for the help,
    Peter
    Last edited by Peter Oors; - 20th September 2004 at 05:51.

  2. #2
    kima's Avatar
    kima Guest


    Did you find this post helpful? Yes | No

    Default

    myint:
    Disable ' No interrupts past this point


    is this work:

    DISABLE ‘ Disable interrupts in handler
    myint:

    Resume ‘ Return to main program
    Enable ‘ Enable interrupts after handler

  3. #3
    Peter Oors's Avatar
    Peter Oors Guest


    Did you find this post helpful? Yes | No

    Default

    Hello Kima,

    I tried what you wrote.
    It still gives the same error.
    What else could it be?

    Peter

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    (1) Ensure that the 'myint' in the ON INTERRUPT statement is the same spelling as the Label in the Interrupt Service Routine.

    (2) Ensure that the myint label in the ISR has a COLON and not a SEMI-COLON following it.

    (3) Ensure that the myint label in the ISR is against the left-hand margin of your source code, and is not prefixed by a Space or Tab or other character (this forum by default strips out formatting characters so we can't see if this is the case).

    (4) Delete out both occurances of myint and retype them in.

    See PM.TXT in your PBP directory.

  5. #5
    Peter Oors's Avatar
    Peter Oors Guest


    Did you find this post helpful? Yes | No

    Default

    Hello,

    After deleting DEFINE ONINT_USED 1, compiling wasn't a problem anymore.
    I have to test it in real.
    Thanks for the help so far.

    Peter

  6. #6
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    Peter, to my knowlege there is no command "DEFINE ONINT_USED 1, at least in the PBP 2.45 manual listings.

    Dave Purola,

  7. #7
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    On versions of the PicBasic Pro Compiler earlier than 2.33, Define ONINT_USED 1 was necessary when using the MeLabs boot-loader to keep library code from being inserted in the first 4 locations.

    Define LOADER_USED 1 is used for newer versions. You'll receive the error message Opcode Expected Instead of '1' when using the older define with a newer version of PBP.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  8. #8
    Peter Oors's Avatar
    Peter Oors Guest


    Did you find this post helpful? Yes | No

    Default

    Bruce, it's true.
    The first version of PBP for me was earlier than 2.33.
    At the top of my programs I always put the PIC-chip pinning and the "standard" initalisation of that chip.
    For a new program I copy that top of the program and thus also "old" commands......
    That happend before with the command 'ansel' for the 12F675.
    Thanks everybody for the reactions.

  9. #9
    Peter Oors's Avatar
    Peter Oors Guest


    Did you find this post helpful? Yes | No

    Default

    Hello,
    Next program works fine.
    I found that you are not allowed to place any command after
    resume and enable !!
    So, place this always at the end of the program.
    Is this a bug in PBP?

    @ DEVICE PIC16F819, INTRC_OSC_NOCLKOUT, WDT_OFF, MCLR_OFF
    OPTION_REG=0 ' Enable PORTB pullups RB4,5 EN 6, %00000000
    DEFINE LOADER_USED 1 ' Boot loader is being used
    OSCCON=$60 ' osc. controller, 70=8MHz, 60=4MHz

    init:
    Output PORTA.7 ' Output LED
    option_reg = %0
    ON INTERRUPT GoTo int_routine ' Define interrupt handler
    INTCON = $88 ' GIE=1, enable INTE interrupt
    main:
    PORTA.7=0 ' LED off
    GoTo main
    End
    int_routine:
    Disable
    PORTA.7=1 ' LED on
    Pause 300
    intcon.0=0
    Resume
    Enable
    ' No commands allowed after here!!

    Peter

  10. #10
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    It is best to pretend that your Interrupt Service Routine is like a subroutine, and the RESUME statement is the RETURN that exits you back out from that routine. Naturally, unless you explictly place code AFTER a RETURN statement, and somehow then jump to it, it'll never be executed will it? Likewise with your ISR.

    Also, you have one fatal error in your program, remove that END statement and place it at the very end of your code NOT in the middle. The END statement is there to tell the compiler that there is no more code, so technically your ISR shouldn't even compile in. This too is perhaps why further code is ignored.

  11. #11
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Peter,

    It's not a bug in PBP.

    RESUME inserts RETFIE (return from interrupt) after your interrupt handler is finished.

    If you insert code after the RETFIE (RESUME), there's no way for it to ever execute since program flow is returned to where it was before the interrupt.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  12. #12
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I don't understand the logic behind having END mid-stream in code like this, but the END command won't prevent any code following it from being compiled. It generates code to enter a continuous loop executing the SLEEP command.

    If you don't include a GOTO before END, and program execution lands on the END statement, then you're trapped in a continuous loop similar to the one shown below.

    @@0000 sleep
    clrf PCLATH
    goto @@0000

    This (shown below) should work as-is since program execution should never land on END, but I still don't see the logic in placing it mid-stream like this!

    GoTo main
    End
    int_routine:
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  13. #13
    aruran's Avatar
    aruran Guest


    Did you find this post helpful? Yes | No

    Default Interrupt handling

    I have developed a PBP code to be used on an embedded sms sender...

    My requirement is when my PIC (SMS) is interrupted by a centralized controlling PIC it should execute

    the necessary routines and send sms via a T10 phone.... As far as sending sms is concerned the code

    works ok...But the interrupt mechanism is not working properly.

    I have some subroutines to attend while inside the ISR..I simulated the code and found that upto the

    first GOSUB command it works properly and then it reacts as though a new interrupt has occured and it

    executes ISR from the begining...

    Please be kind enough to help me

    I have herewith attached my code

    thanks
    aruran

  14. #14
    aruran's Avatar
    aruran Guest


    Did you find this post helpful? Yes | No

    Default Source code.....

    INCLUDE "modedefs.bas"

    DEFINE OSC 10 '10MHz crystal

    ' Set receive register to receiver enabled
    DEFINE HSER_RCSTA 90h
    ' Set transmit register to transmitter enabled
    DEFINE HSER_TXSTA 20h
    ' Set baud rate
    DEFINE HSER_BAUD 9600
    ' Set SPBRG directly (normally set by HSER_BAUD)
    DEFINE HSER_SPBRG 15

    Clear

    customer var byte
    string var byte [32]'Text Data
    pdu VAR BYTE [8] 'pdu data
    tmp VAR BYTE [8] 'temporary array
    b1 VAR BYTE [4]
    x var byte [2]
    finalpdu var byte [54]
    recvnum var byte [12]
    telnum var byte [12]
    string1 var byte [8]
    ch var byte

    OPTION_REG = 0
    TRISB = $0F

    on Interrupt Goto myint ' Define interrupt handler
    INTCON = $90 ' Enable INTE interrupt

    loop:
    Goto loop ' Infinite Loop


    '''''''''''''' Interrupt handler'''''''''''''''''''''''


    myint:

    Disable ' No interrupts past this point

    for x=0 to 9
    LookUp X,["0011000B81"],b1
    finalpdu(x)=b1
    next x

    ; Taking in Recepient Number

    telnum[1]=9
    telnum[0]=4
    telnum[3]=7
    telnum[2]=7
    telnum[5]=6
    telnum[4]=0
    telnum[7]=6
    telnum[6]=9
    telnum[9]=3
    telnum[8]=1
    telnum[11]=7
    telnum[10]=$F

    For X=0 TO 11
    LookUp telnum(x),["0123456789"],b1
    recvnum(x)=b1
    Next X
    recvnum(10)="F"

    for x=10 to 21
    finalpdu(x)=recvnum[x-10]
    next x

    for x=22 to 29
    LookUp (X-22),["0000AA20"],b1
    finalpdu(x)=b1
    next x

    ;;;;;;;;;;;;;;;;;;;;;;Message;;;;;;;;;;;;;;;;;;;;; ;

    ;Taking in Customer

    ;;;;;;;;;;; Should be deleted ;;;;;;;;;;;;;;;;;;;;;

    for x=0 to 16
    lookup x,["aaaaaaaaaaaaaaaaa"],b1
    customer(x)=b1
    next x

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;

    for x=0 to 16
    lookup2 x,[customer],b1
    string(x)=b1
    next x

    ;Taking in String2
    For X=0 TO 14
    LookUp2 X,[",Reported Fault"],b1
    string(x+17)=b1
    Next X

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;

    ;HSerout [str string\32,13,10]
    HSerout ["AT+CMGF=0",13,10] 'Set to PDU Mode
    HSerout ["AT+CMGS=42",13,10] 'Set to PDU length
    hserout [str finalpdu\30]

    for x=0 to 7
    string1(x)=string(x)
    next x
    Gosub txt2pdu

    for x=0 to 7
    string1(x)=string(x+8)
    next x
    ;GoSub txt2pdu

    for x=0 to 7
    string1(x)=string(x+16)
    next x
    GoSub txt2pdu

    for x=0 to 7
    string1(x)=string(x+24)
    next x
    GoSub txt2pdu
    HSerout [26]

    INTCON.1 = 0 ' Clear interrupt flag
    Resume ' Return to main program
    Enable

    ;-----CONVERSION ROUTINES-------
    ;---TXT2PDU--(sms encoding)-----


    TXT2PDU:
    for x=1 to 7
    tmp(x) = string1(x) << (8-x)
    next x
    ch(0)=string1(0)
    pdu(0)=tmp(1) + ch(0)

    for x=1 to 6
    ch(x)=string1(x) >> x
    pdu(x)=tmp(x+1) + ch(x)
    next x

    for x=0 to 6
    hserout [hex2 pdu(x)]
    next x

    RETURN

  15. #15
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    ENABLE causes PBP to continue inserting interrupt test code. If you jump out
    of the ISR routine with GOSUB TXT2PDU, and this sub routine has interrupt
    test code in it, then it's going to jump directly back to your ISR sub-routine.

    Example. In your ISR interrupt routine you have ENABLE at the end which is
    causing PBP to insert interrupt test code in your lower sub-routine TXT2PDU.

    Once you land on the first GOSUB TXT2PDU statement, you land right on
    code inside your TXT2PDU routine that's re-directing you right back to the
    beginning of ISR.

    ' == last part of ISR routine ==
    INTCON.1 = 0 ' Clear interrupt flag
    Resume ' Return to main program "with RETFIE"
    ' Enable '<=== CONTINUES PLACING INTERRUPT TEST CODE AFTER HERE

    Remove the ENABLE from the last line of routine ISR (like shown above), and
    drop it at the bottom of your TXT2PDU sub-routine like this;

    TXT2PDU:
    for x=1 to 7
    tmp(x) = string1(x) << (8-x)
    next x
    ch(0)=string1(0)
    pdu(0)=tmp(1) + ch(0)

    for x=1 to 6
    ch(x)=string1(x) >> x
    pdu(x)=tmp(x+1) + ch(x)
    next x

    for x=0 to 6
    hserout [hex2 pdu(x)]
    next x

    RETURN ' return from each GOSUB
    Enable ' Re-enable auto inserrtion of interrupt checking code beyond here
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. problem using GOSUB under interrupt
    By fobya71 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 5th March 2010, 19:52
  2. Problem with Interrupt on PIC18F4620 PORTB
    By rookie in forum Off Topic
    Replies: 1
    Last Post: - 22nd March 2007, 01:34
  3. Interrupt Problem
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th November 2005, 20:58
  4. Interrupt stack overflow problem with Resume {label}
    By Yuantu Huang in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 3rd May 2005, 01:17
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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