Multiple External Interupts


Closed Thread
Results 1 to 5 of 5
  1. #1
    w7ami's Avatar
    w7ami Guest

    Cool Multiple External Interupts

    Help!

    I want to use multiple external interupts and perform different functions depending upon which interupt was triggered. From reading the green book and the product manual I can't see how to do this. Can someone give me a push in the right direction.

    I am using a PIC18F4620.

    Terry

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by w7ami View Post
    Help! I want to use multiple external interupts and perform different functions depending upon which interupt was triggered. From reading the green book and the product manual I can't see how to do this. Can someone give me a push in the right direction. I am using a PIC18F4620.
    Terry
    If you use the 'On Interrupt' function, when you get into the 'On Interrupt' loop, you have to check the individual interrupt flags that you've enabled.
    In the case of using TMR0-overflow interrupt...
    1) You set up the TMR to run at whatever rate you want (timer prescaler, timer source, etc)
    2) Enable global interrupts
    3) enable the timer interrupt
    4) When the overflow interrupt fires (i.e. tmr0 counted from 255 and rolled over to 0), 'On Interrupt' fires...
    5) The code inside the 'On Interrupt' looks at the TMR0-OverFlow Interrupt flag. If it's set (or reset depending on which interrupt you're using), that particular interrupt caused the interrupt.
    6) Then (most likely) you have to reset the particular interrupt flag that you checked
    7) Execute your interrupt code accordingly
    8) RESUME your normal code

    What, in particular, were you lookingfor? Just playing around?
    I use 'On Interrupt' a lot, only because I believe I understand it well enough to overcome it's limitations.
    There are a couple of much faster, more flexible interrupt routines on this forum. They deal somewhat with assembly, macros, etc. They aren't that hard to use. I believe they are the way to go if you're looking for something time critical.

  3. #3
    w7ami's Avatar
    w7ami Guest


    Did you find this post helpful? Yes | No

    Smile Multiple External Interupts

    Thanks Skimask,

    I think I'm good now. I just needed to enable INTCON1 and INTCON2. Somehow I missed them. I have some test code up and working now.

    What I doing is not super time critical so I am doing everything I can to stay away from assembly. The only assembly I can do is with a soldering iron, screw driver, wrench....

    Thanks also for the hints on TMR0 I'll be needing that soon.

    Terry

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by w7ami View Post
    Thanks Skimask,
    I think I'm good now. I just needed to enable INTCON1 and INTCON2. Somehow I missed them. I have some test code up and working now.
    What I doing is not super time critical so I am doing everything I can to stay away from assembly. The only assembly I can do is with a soldering iron, screw driver, wrench....
    Thanks also for the hints on TMR0 I'll be needing that soon.
    Terry
    In the case of TMR0...registers to note:

    INTCON.7 = 1 'enable ALL interrupts
    INTCON.6 = 1 'enable ALL peripheral interrupts
    INTCON.5 = 1 'enable TMR0 OVERFLOW interrupt
    INTCON.2 = 1 'TMR0 OVERFLOWed, so it interrupted, must be cleared manually after your program has recognized the interrupt (INTCON.2 = 0)
    INTCON2.2 = 1 'sets TMR0 to high priority, not really needed, but useful to note
    T0CON...all bits for controlling TMR0 (see the datasheet)

  5. #5
    w7ami's Avatar
    w7ami Guest


    Did you find this post helpful? Yes | No

    Default Multiple External Interupts

    Just in case someone wants to see how to do multiple hardware interupts, here is my quick and dirty program.

    ;************************************************* *******
    ; PIC18F4620
    DEFINE OSC 40
    ; Setup Ports
    TRISB = %11111111 ; Port B all inputs
    TRISD = %00000000 ; Port D all outputs
    DTR var INTCON.0 ; alias to intcon
    DSR var INTCON2.0 ; alias to intcon1
    ACC var INTCON3.0 ; alias to intcon2
    INTCON = %10010000 ; Enable External Interupt INT0

    INTCON2 = %10110000 ; INTCON2.7 = All pull up are disabled
    ; INTCON2.6 = INT0 trigger on falling edge
    ; INTCON2.5 = INT1 trigger on rising edge
    ; INTCON2.4 = INT2 trigger on rising edge
    ; INTCON2.3 = Not used
    ; INTCON2.2 = TMR0 low priority
    ; INTCON2.1 = Not used
    ; INTCON2.0 = Port change priority
    INTCON3 = %01011000 ; INTCON3.7 = INT2 Low priority
    ; INTCON3.6 = INT1 Hi priority
    ; INTCON3.5 = Not used
    ; INTCON3.4 = INT2 external enabled
    ; INTCON3.3 = INT1 external enabled
    ; INTCON3.2 = Not used
    ; INTCON3.1 = INT2 Flag (Read Only)
    ; INTCON3.0 = INT1 Flag (Read Only)

    On Interrupt Goto INTERUPTS ; Define interrupt handler
    ;************************************************* ********
    Loop:
    PORTD.0 = 0 ; Turn all LEDs on
    PORTD.1 = 0
    PORTD.2 = 0
    PORTD.3 = 0
    Goto loop ; Do it forever
    ;************************************************* ********
    ; Interrupt handler
    Disable ; No interrupts past this point
    INTERUPTS:
    if INTCON.1 = 1 then
    PORTD.0 = 1 ; Turn LED1 OFF
    Pause 500 ; Wait .5 seconds
    INTCON.1 = 0 ; Clear interrupt flag
    endif
    if INTCON3.0 = 1 then
    PORTD.1 = 1 ; Turn LED2 OFF
    Pause 500 ; Wait .5 seconds
    INTCON3.0 = 0 ; Clear interrupt flag
    endif
    if INTCON3.1 = 1 then
    PORTD.2 = 1 ; Turn LED2 OFF
    Pause 500 ; Wait .5 seconds
    INTCON3.1 = 0 ; Clear the interupt flag
    Endif
    RESUME ; Return to main program
    ENABLE
    ;************************************************* ********
    END

    Terry

Similar Threads

  1. Multiple PICS from Same Crystal?
    By WOZZY-2010 in forum General
    Replies: 2
    Last Post: - 6th February 2010, 15:18
  2. Replies: 1
    Last Post: - 28th January 2010, 22:15
  3. Help! My 'interupt', erhm ...only interupts the one time?!!!
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd November 2009, 12:49
  4. Multiple PIC programming
    By Nicholas in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 7th May 2007, 23:47
  5. Using Multiple EEPROMs
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th March 2005, 07:37

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