Interrupt Yes or No - Difference


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302

    Default Interrupt Yes or No - Difference

    I have two codes which both of them works.
    But i don't understand which is the difference with Interrupt and without Interrupt.
    The operation both of them is the same

    The first with Interrupt is :
    Code:
    '  On Interrupt - Interrupts in BASIC
    '  Turn LED on-off.  Interrupt on PORTB.0 (INTE) turns LED1 on
    '  Program waits 1 seconds and turns LED1 back off.
    
    
        ' 16F88
    
        led  var PORTA.2
        led1  var PORTA.3
        
        CMCON = 7
        ANSEL = 0
    
        On Interrupt goto myint    ' Define interrupt handler
        
        OPTION_REG = %00111111
        INTCON = %10010000         ' Enable INTE interrupt
    
    loop:
    
        High LED
        Pause 100
        Low LED
        Pause 100
        Goto loop        ' Do it forever
    
        ' Interrupt handler
        
        Disable          ' No interrupts past this point
        
    myint:
    
        High LED1        'If we get here, turn LED1 on
        Pause 1000       ' Wait 1 seconds
        Low LED1         ' If we get here, turn LED1 off
        INTCON.1=0       ' Clear interrupt flag
        Resume           ' Return to main program
        Enable
    The second without Interrupt is :
    Code:
        ' 16F88
    
        led  var PORTA.2
        led1  var PORTA.3
        
        CMCON = 7
        ANSEL = 0
        TRISB=%11111111
        
    loop:
    
        if PORTB.0=0 THEN GOSUB myint 
        High LED
        Pause 100
        Low LED
        Pause 100
        Goto loop        'Do it forever
        
    myint:
    
        High LED1        'If we get here, turn LED1 on
        Pause 1000       'Wait 1 seconds
        Low LED1         'If we get here, turn LED1 off
     
        RETURN

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default

    Hi,
    In this particular case the difference is that in the example using interrupts the latency is max ~100mS and in the example not using interrupts the latency can be up to 200mS.

    In the first example PBP check if there is an interrupt pending between each PBP statement. Basicly:
    Code:
    Loop:
     Interrupt?
    High LED
     Interrupt?
    Pause 100
      Interrupt?
    Low LED
     Interrupt?
    Pause 100
     Interrupt?
    Goto Loop
    The second example checks the switch at the begining of each iteration thru the loop and since you have two Pause 100 in there it takes at least 200mS between each check. Depending on when you push the button the time it takes for program to respond will be between 0 and ~200mS.

    /Henrik Olsson.

Similar Threads

  1. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  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. NEWBIE: Some basic questions using interrupts
    By JackPollack in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2006, 02:59
  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