Interrupt Problem


Closed Thread
Results 1 to 8 of 8
  1. #1
    FrankM's Avatar
    FrankM Guest

    Default Interrupt Problem

    Hello,

    I use TMR1 to generate an interrupt.
    All is working fine.

    But when I call a procedure with GOSUB, e.g. GOSUB Pause1000, then the Interrupt doesn't work.
    In this procedure is no interupt called, but when the program returns, the interrupt is working again.

    So how can I make, that the interrupt works in procedures, too?

    FrankM

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


    Did you find this post helpful? Yes | No

    Default

    I assume you are using PBP's "On Interrupt..." rather than your own Assembler Interrupt.

    In this case the interrupt is not serviced until AFTER the current Basic command has finished executing... this means that if you have a ONE SECOND delay in the form of...

    Pause 1000

    then the interrupt will not occur until AFTER the Pause 1000 has completed. That means at worst-case there could be a 1 Second delay before you jump into your ISR.

    How can you improve on this? Simply break your pause up into smaller segments...

    For ByteCounter=1 to 100
    Pause 10
    Next ByteCounter

    Here the overall timing is still 1 Second, but the interrupt will be serviced after 10mS worst-case instead. You can use Pause 1 instead for an even faster Interrupt Service, however, when you get down to 1mS instructions, and if timing is critical to you, the extra processing for your Counter Code will start having an impact to your timing... example...

    For WordCounter=1 to 1000
    Pause 1
    Next WordCounter

    ...here you may find that you have not got exactly 1 Second, but 1.05 Seconds or thereabouts (the actual figure depends on many factors). Then instead of using Pause 1, use PauseUS instead, and adjust the value to compensate to get as close to your overall ideal 1 Second as possible... eg...

    For WordCounter=1 to 1000
    PauseUS 995
    Next WordCounter

    Melanie

  3. #3
    FrankM's Avatar
    FrankM Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks for your answer, but that's not exactly my problem.

    My Code looks like this:


    Main:

    ON INTERRUPT GOTO MyInt

    GOTO Start

    DISABLE
    MyInt:

    PIR1=0

    'PINS
    IF ReedPin=0 Then I2CTransfer
    IF LadePin=0 THEN IsLoading

    RESUME
    ENABLE


    Start:

    T1CON=%00000101
    INTCON=$C0
    PIE1=%1

    GOSUB SPKUp
    PAUSE 100

    GOTO ShutDown


    SPKUp:
    For SPKVAR1=10 to 60
    FREQ=SPKVAR1*SPKVAR1
    FREQOUT SpkPin, 10, FREQ
    PAUSE 100
    NEXT SPKVAR1
    RETURN


    My Problem is:
    If I call SPKUp, the Interrupt Handler won't work. So it doesn't check the ReedPin oder LadePin.

    And now my question:
    What can I make, that this works?

    I used the PBP's Interrupt handler, because I can no Assembler

    FrankM

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


    Did you find this post helpful? Yes | No

    Default

    What PIC are you using?

  5. #5
    FrankM's Avatar
    FrankM Guest


    Did you find this post helpful? Yes | No

    Default

    Pic 16F876 @ 20Mhz

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


    Did you find this post helpful? Yes | No

    Default

    I disagree with you Frank... your posted code above CANNOT look like your code that doesn't work...

    Your Subroutine MUST be positioned correctly...

    (1) It must be located AFTER an ON INTERRUPT statement and...
    (2) It must be located AFTER an ENABLE statement

    I have tested all four examples below to double-check...

    Example 1. This will Not work...

    Jump to Start
    Subroutine
    ISR (Interrupt Service Routine with Disable/Enable)
    Start:
    On Interrupt Statement
    Enable Statement
    Main Program Loop

    Example 2. This will not work

    Jump to Start
    Subroutine (with Enable)
    ISR (with Disable/Enable)
    Start:
    On Interrupt Statement
    Enable Statement
    Main Program Loop

    Example 3. This WILL work

    Jump to Start
    ISR (with Disable/Enable)
    Start:
    On Intterrupt Statement
    Enable Statement
    Main Program Loop
    Subroutine

    Example 4. This WILL work

    On Interrupt Statement
    Enable Statement
    Jump to Start
    Subroutine
    ISR (with Disable/Enable)
    Start:
    Main Program Loop

    Basically, the physical location of the Subroutine within your code MUST be AFTER the ON Interrupt Statement (which comes first) and after an ENABLE Statement (which comes second). Do not place the subroutine BEFORE an On Interrupt/Enable... it doesn't compile correctly.

    Melanie

    btw... forgot to say... Don't give up Music class... *smiles*

  7. #7
    FrankM's Avatar
    FrankM Guest


    Did you find this post helpful? Yes | No

    Default

    OK, I agree, it was my fault

    The subs are in seperate files, which are included at the beginning of my main file.

    So I'll have to include these files at the end of my main prgramm.

    I'll try it later and see if it works, but I hope that this was the mistake and I think, that this was the mistake.

    thanks

    Frank

  8. #8
    FrankM's Avatar
    FrankM Guest


    Did you find this post helpful? Yes | No

    Default

    Thank you, it works!!!!

    Frank

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 : 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