Interrupt only works in main loop, not in subroutines???


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2006
    Posts
    7

    Arrow Interrupt only works in main loop, not in subroutines???

    Hello,
    I am facing to the strange problem. I have the following program:

    'interrupt for timer
    OPTION_REG = $d5
    INTCON = $a0 'enable TMR0 interrupts and global interrupt
    PIE1 = 0
    On Interrupt Goto intManagement

    enable
    while 1
    if (PIR1.5==1) then
    HSERIN 50, main, [wait ("GET /"), STR COMMAND\96\$2F]
    GOSUB waitFiveSec
    HSEROUT["Hello"]
    endif
    WEND
    end


    disable
    intManagement:
    if (INTCON.2 == 1) then
    ticks = ticks + 1 ' Count pieces of seconds
    If ticks < 61 Then tiexit
    toggle ACTIVITY_LED
    ticks = 0 'One second elasped
    second = second + 1
    If second >= 60 Then
    second = 0
    minute = minute + 1
    If minute >= 60 Then
    minute = 0
    hour = hour + 1
    if (hour >= 24) then
    hour = 0
    day = day + 1
    if (day >= 7) then
    day = 0
    endif
    endif
    ENDIF
    endif
    endif
    tiexit:
    INTCON.2 = 0
    INTCON.7 = 1
    resume

    enable
    waitFiveSec:
    for i = 0 to 5000
    pause 1
    next i
    return


    The interrupt is working, my activity led is blinking. But if I will send to serial port this "GET /",
    then the LED will stop blink for these 3 seconds. For me it seems, that if the main program will jump to sub, then, it waits for its end and then it calls the interrupt. It looks like, that the interrupt doesn't work in sub programs. Am I right?

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


    Did you find this post helpful? Yes | No

    Default

    You might be getting a stack overflow due to missing resume at the end of intManagement routine when it finally does exit there . . .
    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.

  3. #3
    Join Date
    Aug 2006
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    You might be getting a stack overflow due to missing resume at the end of intManagement routine when it finally does exit there . . .
    I have resume at the end of intManagement

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    That is one of the problems with ON INTERRUPT. Not sub routines but ON INTERRUPT waiting for certain commands to finish.

    From the manual
    When an interrupt occurs, it is flagged. As soon as the current PICBASIC PRO™ statement=s execution is complete, the program jumps to the BASIC interrupt handler at Label. Once the interrupt handler is complete, a RESUME statement sends the program back to where it was when the interrupt occurred, picking up where it left off.
    PBP will not enter the BASIC interrupt handler until it has finished executing the current statement. If the statement is a PAUSE or SERIN, it could be quite a while before the interrupt is acknowledged. The program must be designed with this latency in mind. If it is unacceptable and the interrupts must be handled more quickly, an assembly language interrupt routine must be used.
    So you will want to use ASM interrupts or DT's instant interrupts. DT basically makes ASM interrupts easy.

    http://www.picbasic.co.uk/forum/showthread.php?t=3251
    Last edited by mackrackit; - 30th November 2010 at 14:14.
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts