Interruptus Frustratus


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    ....Continued from above.

    Code:
    '---[TMR1 Gate - interrupt handler]--------------------------------------------------
    disable   
    CheckCount:
            T1CON.0 = 0   'stop timer1
            timercount[index] = TMR1L + TMR1H << 8   'stuff the contents of the timer register into a word    
            TMR1L = 0     'reset counter to 0...
            TMR1H = 0     'upper 1/2 too
    
            If delay < 1001 then    'delay user access to the buttons until the count "average" has stabilized.
                delay = delay +1        
            endif    
        
            If timercount[index] > timerave[index] +70 then  'Help provide a speedy recovery for released buttons
                timerave[index] = timercount[index]
            endif
                 
            if (timercount[index] - timerave[index]) < AvgCount Then Close
            timerave[index] = timerave[index] - (timerave[index]/AvgCount)    'average the count so you have a reference to compare....
            timerave[index] = timerave[index] + (timercount[index]/AvgCount)  '...with timercount
            Goto checkscore
        
            Close:
                timerave[index] = timerave[index] - (timerave[index]/(AvgCount/16))   
                timerave[index] = timerave[index] + (timercount[index]/(AvgCount/16))    
        
            Checkscore:       'Determine if a button is pressed (count is less than average)        
                If timerave[index] - (timerave[index] /50) > timercount[index] and (delay > 1000) then 
                   gosub ServiceHardw 'Signal that a button is pressed. 
                endif
            
            If index < 5 then     'Increment to the next touch sensor input
               index = index +1
            else
                index = 0
            Endif
            CPSCON1 = index
         
            TMR0 = 0       'reset timer 0              
            T1CON.0 = 1  'restart timer1
     
    @ INT_RETURN
    enable
    
    
    '----------SUBROUTINES--------------------------------
    'Subroutine for Button 1-----------------------------
    Butt1:
            Digit4 = 1
            gosub sortdigits
            Pause 500
            digit4 = 0
            gosub sortdigits
    Return
    
    
    'Subroutine for Button 2-----------------------------
    Butt2:
            Digit4 = 2
            gosub sortdigits
            Pause 500
            digit4 = 0
            gosub sortdigits
    Return
    
    
    'Subroutine for Button 3-----------------------------
    Butt3:
            Digit4 = 3
            gosub sortdigits
            Pause 500
            digit4 = 0
            gosub sortdigits
    Return
    
    
    'Subroutine for Button 4-----------------------------
    Butt4:
            Digit4 = 4
            gosub sortdigits
            Pause 500
            digit4 = 0
            gosub sortdigits
    
    Return
    
    
    'Subroutine for Button 5-----------------------------
    Butt5:
            Digit4 = 5
            gosub sortdigits
            Pause 500
            digit4 = 0
            gosub sortdigits
    Return
    
    
    'Subroutine for Button 6-----------------------------
    Butt6:
            Digit4 = 6
            gosub sortdigits
            Pause 500
            digit4 = 0
            gosub sortdigits
    Return
    
    
    'Subroutine to display numbers on 7-segment display-----------
    display:
              shiftout S_in, LEDCLK, 1, [LEDData]
    return
    
    
    'Subroutine to map numbers to the correct LED segments------
    getpattern:  
           lookup numeral,[$EE,$28,$CD,$6D,$2B,$67,$E7,$2C,$EF,$6F], LEDData 'MSBFirst / Right side up digits
    return
    
    
    'Subroutine to read time from RTC--------------------              
    gettime:  
            RST = 1         ' Ready for transfer
            ' Read all 8 RTC registers in burst mode
            Shiftout IO, SCLK, LSBFIRST, [$bf]      
            Shiftin IO, SCLK, LSBPRE, [rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, rtccontrol]
            RST = 0         ' Reset RTC 
            mathtemp =(rtcsec>>4)*10+(rtcsec & $0F)  'convert BCD seconds into Decimal seconds 
            digit1 = mathtemp dig 0   'digit 1 = ones of seconds
            digit2 = mathtemp dig 1   'digit 2 = tens of seconds     
            mathtemp =(rtcmin>>4)*10+(rtcmin & $0F)  'convert BCD minutes into Decimal minutess 
            digit3 = mathtemp dig 0   'digit 3 = ones of minutes
    '        digit4 = mathtemp dig 1
            gosub sortdigits              
    Return
    
    
    'Subroutine to sort out the buttons-------------------
    ServiceHardw:
            branchl index, [Butt1,Butt2,Butt3,Butt4,Butt5,Butt6]
    return
    
    
    ' Subroutine to write time to RTC------------------------        
    settime: 
            RST = 1         ' Ready for transfer
            Shiftout IO, SCLK, LSBFIRST, [$8e, 0]  ' Enable write
            RST = 0         ' Reset RTC
            RST = 1         ' Ready for transfer
                ' Write all 8 RTC registers in burst mode
            Shiftout IO, SCLK, LSBFIRST, [$be, rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, 0]
            rst = 0        
    Return 
    
    
    'Subroutine to lookup numbers and put them in the correct LED digit-----------
    sortdigits:  
            numeral = digit4   
            gosub getpattern
            swap LEDData.0, LEDdata.4   'Swap "DP" and "G" segments on upsidedown digits
            gosub display    
            numeral = digit3
            gosub getpattern
            LEDData.4 = 1       'Turn on lower DP in colon
            gosub display    
            numeral = digit2
            gosub getpattern
            swap LEDData.0, LEDdata.4   'Swap "DP" and "G" segments on upsidedown digits
            LEDData.0 = 1      'Turn on upper DP in colon
            gosub display    
            numeral = digit1
            gosub getpattern
            gosub display
           High Latch
           pause 1
           low Latch
    return
    
          
    'Main loop - Gets the time and displays it----------------------------------        
    main:   
            gosub gettime
            gosub sortdigits
            pause 100              
            Goto main   ' repeat until nauseated...
    
    End

    Thanks!

    Steve

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


    Did you find this post helpful? Yes | No

    Talking

    Hi,

    I didn't know DT interrupts were using Enable and Disable Commands ...

    Alain

    Coïtus interruptus frustrans est ...
    ************************************************** ***********************
    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 " !!!
    *****************************************

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Code:
    INTCON.5 = 1; // enable TMR0 interrupt
    There's no handler for the TMR0 interrupt.

    So the flag for that interrupt never gets cleared.
    It then continuously enters/exits the interrupt processor, never to see the light of day again.

    Added: And Alain is correct. disable/enable has no effect on DT_INTS.
    <br>
    Last edited by Darrel Taylor; - 8th April 2009 at 08:43. Reason: Added:
    DT

  4. #4
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    970


    Did you find this post helpful? Yes | No

    Default

    Steve

    Code:
         
    Checkscore:       'Determine if a button is pressed (count is less than average)        
                If timerave[index] - (timerave[index] /50) > timercount[index] and (delay > 1000) then 
                   gosub ServiceHardw 'Signal that a button is pressed. 
                endif
    Your call to gosub ServiceHardw is the culprit. It nests other subroutines. This is what may be consuming the time. I can recommend you replace the call to gosub ServiceHardw with a bit variable getting set. You then check the bit variable in your mainline code to decide if you need to serviceHardw. It will definitely yield results.

    Code:
         Checkscore:       'Determine if a button is pressed (count is less than average)        
                If timerave[index] - (timerave[index] /50) > timercount[index] and (delay > 1000) then 
                   ServiceHw=1
                endif
    In your main, put this
    Code:
    ServiceHw var  bit        ' declarations section
    
                If ServiceHw then gosub ServiceHw

    Jerson

  5. #5
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Alain, Darrel, Jerson, thanks very much! You guys are great!

    Sooo... if "Disable" & "Enable" don't work with DT_INT, what keeps interrupts from occurring during the interrupt handler? I assume that DT_INT must "protect" it's own handler?

    Is there a way for me to disable the interrupts during certain subroutines?
    When I get the rest of this put together there will be several places where I need to kill the interrupts to perform time sensitive tasks. Is that possible using DT_INT ?
    Do I simply turn the interrupts on and off with the GIE bit when I want to? (INTCON.7 = 0) ?

    Darrel, thanks for catching the TMR0 interrupt with no handler. I don't know why I keep doing that. I had to change the Timer resource from TMR2 to TMR0 and I enabled it's interrupt unnecessarily. Thanks! Turning TMR0 interrupt off helped but didn't completely cure the problem.

    Jerson, please print yourself a pretty gold star and pin it to your shirt for the day!
    The call to gosub "ServiceHardw" was indeed the big culprit. I assume that I just had so much stuff inside my interrupt handler that I ran out of time to do anything else before the next interrupt ?
    I set a bit to tell when a button is pressed and check it in my main code as you suggested, and it works MUCH better now!

    There's clearly a few bugs still to work out before I start adding the rest of my code back in, but it's looking pretty hopeful now.

    Thanks again to all of you. What a great resource!


    Steve

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Enable/Disable are for PBP ON INTERRUPT GOTO

    For DT-INTS you have
    @ INT_ENABLE IntSource
    and
    @ INT_DISABLE IntSource

    You could disable all interrupt by clearing INTCON GIE too. Used with care this could work.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Enable/Disable are for PBP ON INTERRUPT GOTO

    For DT-INTS you have
    @ INT_ENABLE IntSource
    and
    @ INT_DISABLE IntSource

    You could disable all interrupt by clearing INTCON GIE too. Used with care this could work.
    AHA! Thanks Steve!

    When using @ INT_DISABLE to protect a subroutine, does it also protect nested gosubs, or do I need to disable interrupts in each nested subroutine to protect them all from interrupt?

    Thanks!

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    It protect what's in between DISABLE and ENABLE, so yes if your Gosub are in between them, they will be "protected" as well.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  9. #9
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    It protect what's in between DISABLE and ENABLE, so yes if your Gosub are in between them, they will be "protected" as well.
    Excellent. Thanks!




    Steve

  10. #10
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    970


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Byte_Butcher View Post
    Alain, Darrel, Jerson, thanks very much! You guys are great!
    ...snip...
    Jerson, please print yourself a pretty gold star and pin it to your shirt for the day!
    ...snip...
    Thanks again to all of you. What a great resource!
    Steve
    Wow, I am thrilled for that. Thank you. I'm sure many more will learn from your problem as they browse this resource. I myself have used this website to learn from DT, Steve (bow) many times before I began to return the favour. It's my hope that you will be able to soon. :thumbs up:

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