Interrupt cycle time limitation?


Closed Thread
Results 1 to 4 of 4
  1. #1
    jswayze's Avatar
    jswayze Guest

    Default Interrupt cycle time limitation?

    Well, I'm back with a slightly more simple (I hope) problem this time.

    I needed a timer on which to base certain events in my software. I found Melanie's Olympic Timer and used it as the basis for my timer.

    In order to capture a PWM signal with a period of 2ms, my goal was to increment the timer once every 50us to get the resolution I wanted. As it turns out, I can't make this happen.

    In the code example below, I set the interrupt timer to give me a 5.5ms interrupt cycle. (In this case, 65535-5500 = 60035 or $EA83 is the "start" time for the interrupt). Each cycle of the interrupt I toggle an output port, which gives me a square wave with each square width equaling the interrupt cycle length. This I can see and measure on my o-scope.

    Now the interesting part. I can't seem to get non-whole interrupt intervals. In the example below (which should yield a 5.5ms cycle) I get a perfect signal that's 6ms long. A 1100us entry in the program yields a 2ms cycle. An 1800us entry also yields a 2ms cycle.

    Bottom line, I can't hit my 50us cycle because the smallest I can get is 1ms.

    Can anyone explain this? I'm sure it's something simple, but it's driving me crazy.

    Also, if this is some sort of limitation, is it at all possible to achieve my goal of a 50us interrupt cycle?

    Thanks!

    -Jeff


    Code:
    @ DEVICE INTRC_OSC, LVP_OFF, WDT_OFF, MCLR_OFF
    
    define OSC 4
    
    LED7 var PORTB.6
       
        '------------------------------
        ' Main program starts here
        '------------------------------
        
        Gosub ResetTimer
        On Interrupt goto HandleInterrupt
        PIE1.0=1                    ' Enable TMR1 interrupts
        INTCON.6=1                  ' Enable all unmasked Interrupts
        INTCON.7=1                  ' Enable Global Interrupts
    
    
    MAIN:  
            enable
            pause 1
            goto MAIN   'endless loop
            disable
    
    
    ResetTimer:
        T1CON.0=0           ' Stop the clock
        TMR1H=$EA
        TMR1L=$83
        T1CON.0=1           ' Restart the clock
        PIR1.0=0            ' Reset TMR1's interrupt flag (TMR1IF)
        Return
        
    
    HandleInterrupt:
    
        toggle led7
       
        Gosub ResetTimer    ' Set the timer for the next 50us interval
    
        Resume
        
    END

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


    Did you find this post helpful? Yes | No

    Default

    Jeff,

    I think you're right, it is a simple problem.

    With PBP's ON INTERRUPT statement. The interrupt can only be serviced In-between PBP lines. So the "PAUSE 1" will limit the actual service time to an even interval of 1ms.

    Just lose the PAUSE statement, and you should be a lot closer to what you wanted.

    Personaly, I don't like ON INTERRUPT. ASM interrupts are much more accurate.

    HTH,
        Darrel

  3. #3
    jswayze's Avatar
    jswayze Guest


    Did you find this post helpful? Yes | No

    Red face D'oh!

    Wow. Can I have a mulligan on that one?

    Thanks for pointing it out for me... makes me wonder sometimes...

    A sincere thanks,

    Jeff

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


    Did you find this post helpful? Yes | No

    Default

    Ha, no problem.

    First Mulligan buys a round at the clubhouse.

    DT

Similar Threads

  1. Interrupt RPM and Taylors Elapsed time on 18F4620
    By Tobias in forum mel PIC BASIC Pro
    Replies: 70
    Last Post: - 3rd February 2010, 16:12
  2. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  3. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 18:14
  4. Interrupt and Time Out
    By Tissy in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th March 2005, 01:10
  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