9 times out of 10, my program awakes fine (IOC interrupt related), but....


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: 9 times out of 10, my program awakes fine (IOC interrupt related), but....

    Hank, while I am no old hand, may I remind you there are things we can do- but shouldn't. Like bungee jump or sir jump. I guess this also includes gosubs. Btw, for he benefit of those reading, it's not limited to gosubing from DT_int, it's any interrupt.

    Thanks for sharing Hank, we all learn from others mishaps.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  2. #2
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: 9 times out of 10, my program awakes fine (IOC interrupt related), but....

    Thanks bert :-)

    Ok, I've removed all the gosubs from the interrupt routine, but I'm still getting erratic results...I kinda know what's not causing my PIC to go to sleep , but the workaround is ugly.

    I think I'm hitting diffs with nested gosubs. Imagine this scenario (this is just high evel *not* my actual code - just to get my problem across)...

    Code:
    loop1:
    if pattern = 2 then goto loop2
    IF sleep_flag = 1 THEN GOTO SLEEP_ROUTINE
    pause 10
    gosub decrease duty
    gosub select_LED1
    pause 10
    gosub increase_duty
    goto loop1:
    '
    loop2:
    if pattern = 1 then goto loop1
    IF sleep_flag = 1 THEN GOTO SLEEP_ROUTINE
    pause 10
    gosub decrease duty
    gosub select_LED2
    pause 10
    gosub increase_duty
    goto loop2
    '
    SLEEP_ROUTINE:
    debug "PIC off to sleep",13,10
    pause 200
    @sleep
    
    ' program continues here afteran IOC interrupt....
    pause 100
    debug "PIC awake",13,10
    
    IOC_Int:
    @ INT_DISABLE  IOC_INT
    
    if sleep_flag = 1 then ' if we wake from asleep, this flag will be set still need to clear it & retun to the main program
    sleep_flag = 0
    goto INTERRUPT_END
    endif
    
    LOOP3:
            IF SW1 = 0 THEN 
            COUNT3 = COUNT3+1
            IF COUNT3 >300 THEN      'if Sw1 held for 300mS then set sleep_flag
            SLEEP_FLAG =1 
            goto INTERRUPT_END
            ENDIF
            pause 1 
            GOTO LOOP3
            ENDIF
    
    if pattern <2 then    pattern=pattern+1  'cycle between pattern1 & pattern 2
    else
    pattern=1
    endif
    
    INTERRUPT_END:
    COUNT3 =0  
    while sw1=0
    wend
    PAUSE 180 
    IOCAF = 0         'CLEAR THE INTERRUPT FLAG
    @ INT_ENABLE  IOC_INT
    '**************
    @ INT_RETURN
    It seems the interrupt routine (or program!) doesn't like the highlighted Gosubs in the loop1 & loop2 - if I remove the gosubs & instead locate the actual code contents of the gosubs in each loop - then everything is dandy (i.e. the PIC always goes to sleep & awakes fine) , but if I have gosubs in those two main loops - it looks like the interrupt routine (or some other aspect of my program) doesn't return to the main two loops & then trap the sleep_flag being hit! (the problem here is that by not using gosubs I run out of program space *very* quickly!)

    What am I missing here?
    Last edited by HankMcSpank; - 10th October 2011 at 01:44.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    Did you find this post helpful? Yes | No

    Default Re: 9 times out of 10, my program awakes fine (IOC interrupt related), but....

    Hi,
    First, I don't understand why you shouldn't (can't) be able to use GOSUB inside or outside of a DT-INTS ISR as long as you RETURN (as you should with ANY GOSUB), anyone care to elaborate on the reason you say you should never do that? Yes, the stack is limited, so you need to makes sure it doesn't overflow if you happen to get an interrupt when you're already into x nested GOSUBS but as far as I can see it should work.

    Hank, I'm not syaing I have a solution for you but is seems to me that your program can "fall thru" into the ISR by itself. It wakes up, DT-Ints trips and jumps to the ISR, the ISR runs and the then it returns to where it woke up, which is right before the ISR so the ISR runs again. It hits the @INT_RETURN (by the way, there seems to be a missing underscore in your code?) and it returns to "somewhere". I think you need a Goto Loop1 or whatever right after the DEBUG satement - but I just had a quick look at it so I may be missing something.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: 9 times out of 10, my program awakes fine (IOC interrupt related), but....

    Golden rule for interrupts.
    Once in get out as quick as possible.
    My guess is GOSUB a time or two will violate the golden rule.

    Yes, seeing the whole code could help
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: 9 times out of 10, my program awakes fine (IOC interrupt related), but....

    Quote Originally Posted by mackrackit View Post
    Golden rule for interrupts.
    Once in get out as quick as possible.
    My guess is GOSUB a time or two will violate the golden rule.

    Yes, seeing the whole code could help
    I no longer have Gosubs in my interrupt - I removed them.

    The problem seems to be the Gosub in the main body of code - when I leave them in, the IOC interrupt routine or my program hangs once in every 8-10 switch presses.
    (not sure which yet...when it hangs, the last debug line I see is that from inside in the interrupt routine!)

    I'm presently trimming my bloaty program right down (most of it is just visual 'white noise' lol!)...once i've slimmed it down but can still replicate the problem I'm experiencing, then I'll post up the code....at least then you'll have a chance of picking through it!

    Henrik - re the missing underscore - that was just a rough high level example of my approach - not my code (& it was *very* late UK time!)
    Last edited by HankMcSpank; - 10th October 2011 at 09:38.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    Did you find this post helpful? Yes | No

    Default Re: 9 times out of 10, my program awakes fine (IOC interrupt related), but....

    Hank,
    Yes, that would be nice, please post the with which you are actually having problems... ;-)
    But if it's like the code you DID post I still think though that there's a missing Goto Main or Goto Loop1 or whatever as per my previous post.

    And, regarding the GOSUBs, there's really nothing preventing you from having a PAUSE 10000 in the ISR, it'll work. That "golden rule" is there to allow any software timings etc in the main loop to stay as accurate as possible. I still don't understand why using a GOSUB in the ISR would cause problem but that discussion is moot since that, for sure, is no longer the cause of the problem in this case.

    /Henrik.

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default Re: 9 times out of 10, my program awakes fine (IOC interrupt related), but....

    Hi, Hank

    as far as I can understand what you try to do ... ( ) I do not see any GIE bit cancelling before entering sleep ... nor the traditionnal "@NOP" placed right after the " @Sleep " ...

    Regards

    Alain
    Last edited by Acetronics2; - 10th October 2011 at 18:14.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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