Which interrupt ?


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2012
    Posts
    8

    Default Which interrupt ?

    Hi All,

    I'm using PBP and 16F887 MCU.

    I'm employing PortB pin 2 & 3 for interrupts and it works great. I have two push buttons, one for each pin. What I want to happen is when I push the first button, pin 2, a variable increases by one and when pushing the second button, pin 3, it decrements by one. As stated, the interrupt piece works as expected and I have no issue with writing the code inside the handler, I just don't know how the mechanics work for directing either interrupt to the correct handler. Right now they both share the same handler.

    Lots of information available for designing the interrupt but I can't find anything relating to my problem. Any assistance would be appreciated.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Which interrupt ?

    Just thinking out loud here . . . when the interrupt (IOC) occurs you want to read the port, & save it to a temp variable. in your main loop read the variable & act early on, if your main loop is long and busy then check often. I would not act in the ISR unless critical, just to keep the ISR short & sweet, if it is critical, if micro second response is required then act there.
    example;
    Code:
    switchVar var byte     ' var to store port value
    doSomething var byte ' counter var
    
    main:
    do this . . . bla bla 'your code
    gosub Check
    do more . . .' more yourcode
    
    for doSomething = 0 to 50
    gosub check
    yourcode
    next doSomething
    
    morecode . . . 
    gosub check
    
    goto Main
    
    Check:
    if switchVar = 0 then
    return
    else
    do something with the information in switchVar
    switchVar = 0 ' clear the variable after work done
    endif
    
    return
    You could also read the interrupt flag bit to see if interrupt has come, esp if using PBP on interrupt. Asm interrupts are so fast, they would likely be cleared before you loop ever go there though. I am sure others have better solutions, but this will get you started.
    IN Conclusion:
    ISR
    read the port
    store port value in a var
    exit ISR 'assuming ISR clears IOC Flag
    do something with the information in your program
    Last edited by Archangel; - 7th July 2013 at 20:23.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Feb 2012
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Re: Which interrupt ?

    I like the idea but its weird as to what happens. I push the button which generates the interrupt. I watch the status of the "HoldB" variable which is the first statement in the ISR - and it does change to reflect the change on pin 2 or 3 (what ever is pressed) but then HoldB immediately switches back to reflect POrtB again. I don't get it?

    Example:

    - Push button
    - bit 3 of Port B changes from high to low causing interrupt
    - Goes to ISR
    - HoldB grabs PortB status
    - Pin 2 switches back to high state
    - HoldB automatically changes also (this is the part I don't understand)

    Here is the sample code I used:

    Disable

    MyISR:
    HoldB = PortB ' copy Port B into HoldB

    Pause 100
    CV = CV + 1
    endif
    INTCON.0 = 0

    Resume

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Which interrupt ?

    Are you using ON INTERRUPT GOTO ?
    If so did you DISABLE and Enable interrupts during your ISR ? it sounds as if it is repeatedly interrupting before action is taken. I E Fast interrupt, slow finger . . . You can wait to re-enable the interrupt until after your subprogram does it's job . . .
    Last edited by Archangel; - 7th July 2013 at 23:15.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Feb 2012
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Re: Which interrupt ?

    It's saving PortB in HoldB but after the pin goes back to its high state. In other words, Pin 2 is changing back to it's high state before it goes to ISR - at least it seems that way.


    Disable Interrupt

    MyISR:
    HoldB = PortB
    ' Interrupt service routine
    Pause 100
    CV = CV + 1

    INTCON.0 = 0

    Resume
    Enable Interrupt

Similar Threads

  1. Need help with interrupt
    By mbox in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 24th August 2010, 16:48
  2. RX interrupt
    By Arciure in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 5th March 2010, 17:23
  3. on interrupt help
    By cphillips82 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 25th April 2008, 15:48
  4. always go to interrupt
    By savnik in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 26th March 2007, 03:31
  5. Replies: 0
    Last Post: - 27th August 2004, 07:20

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