Turning on & off multiple interrupts


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2005
    Location
    Virginia
    Posts
    65

    Question Turning on & off multiple interrupts

    Hi all! I'm attempting to use two interrupts - one is on at all times and the other is on only during specific routines. When I first turn on my program and hit a switch, it seems the second interrupt occurs though it should be off. This might be a hardware problem, but I wanted to inquire about turning an interrupt on and off. Here's an example of what I *think* I'm supposed to do:


    'PIC18F2525

    On Interrupt goto Reset

    intcon = %10010000 ' Enable global interrupts and interrupt on RB0

    Main:

    'Do something here'

    'If switch is pushed go to Switched_Pushed

    goto Main ' If switch is not pushed, repeat Main routine

    Switched_Pushed:

    intcon3 = %00001000 ' Enable interrupt on RB1
    intcon2.5 = 0 ' Act on falling edge
    'Do stuff here, if RB1 goes low, goto Reset

    'Do more stuff, if RB1 goes low, goto Reset

    goto Main

    Disable
    Reset:

    'Do something here

    Resume Over_Here
    Enable

    Over_Here:

    intcon3 = %00000000 ' Turn off interrupt on RB1

    goto Main



    I notice the PBP manual says you can use On Interrupt more than once. Do I need to add an "On Interrupt goto Reset" before the intcon3 in the Switched_Pushed routine or am I missing something else? Any advice is appreciated.

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


    Did you find this post helpful? Yes | No

    Default

    Hi elec_mech,

    Changing the Edge Select bit while the interrupts are enabled can cause a False interrupt to be generated.

    Turn off the Global Interrupt Enable (INTCON.7) before doing this...

    intcon2.5 = 0 ' Act on falling edge

    Then clear the INT1IF Flag (INTCON3.0) before enableing GIE again.

    HTH,
       Darrel

  3. #3
    Join Date
    Apr 2005
    Location
    Virginia
    Posts
    65


    Did you find this post helpful? Yes | No

    Question Can't enable INT1

    Dave,

    Thanks for the info. Unfortunately, I've discovered I'm stuck at step one here. I can't get the INT1 to work. I know the PIC is going low when I push the switch on RB1 to go low, but the PIC seems to ignore it. Any ideas what I'm missing? Here's the sample code I'm working with:


    ************************************************** *****
    trisb = %00000111
    portb = %00000000

    B2 var byte
    i var word
    time var word

    time = 250


    On Interrupt goto Reset

    intcon = %10010000 ' Enable GIE and INT0


    Main:

    for i = 1 to 100
    portb.3 = 1
    pause time
    portb.3 = 0
    pause time
    button portb.2, 0, 255, 0, B2, 1, Switch
    next

    goto Main

    Switch:

    'On Interrupt goto Reset ' Tried this, no luck
    intcon3.3 = 1 ' Enable interrupt on RB1


    for i = 1 to 20
    portb.4 = 1
    pause 250
    portb.4 = 0
    pause 250
    next
    intcon3.3 = 0 '%00000000 ' Disable INT1
    goto Main



    Disable
    Reset:

    portb = %00000000
    intcon.1 = 0 ' Clear INT0 flag
    intcon3.0 = 0 ' Clear INT1 flag
    Resume Over_Here
    Enable



    Over_Here:
    intcon3 = %00000000 ' Turn off INT1 interrupt
    button portb.2, 0, 255, 0, B2, 1, Main
    pause 10


    goto Over_Here
    ************************************************** ******

    INT0 works great.

    I've tried adding another On Interrupt (as shown above) linked to the same
    handler. I've also tried turning on the INT1 right after the INT0, then turning it off in the Main Routine then back on during the Switch Routine (then off before returning to the Main Routine. I feel I'm missing something fundamental. I'm going to try just turning on INT1 while INT0 is off, but I suspect I'll have the same problem. Any suggestions? Gracias!

  4. #4
    Join Date
    Apr 2005
    Location
    Virginia
    Posts
    65


    Did you find this post helpful? Yes | No

    Red face Solved

    Okay, I'm an idiot. It turned out to be a hardware problem. Dave, thanks again for the info, everything now seems to work well, at least the demo program.

Similar Threads

  1. Problem with multiple interrupts
    By aratti in forum General
    Replies: 7
    Last Post: - 2nd June 2009, 08:18
  2. General Question About Multiple Interrupts
    By grzeh666 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 31st August 2008, 17:09
  3. help: TMR0 interrupts disabling PORTAchange interrupts???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th August 2008, 15:10
  4. Handeling multiple Interrupts
    By BobSpencerr in forum General
    Replies: 15
    Last Post: - 1st March 2007, 01:12
  5. Multiple HW Interrupts
    By Radiance in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th August 2003, 22:35

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