Using an interrupt for an input


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Using an interrupt for an input

    Hi Christopher,
    Not sure I understand the first question. DT-Ints doesn't use any of the timers by it self so they are free for you to use which way you see fit.

    The 18F4550 has three external interrupt pins (not counting IOC) and these are PortB.0-PortB.2. Only these three pins can trip an interrupt. So if what you're really trying to do is to trip an interrupt on PortB.5 it will never work. (Actually PortB.5 has the IOC features so it CAN work but it doesn't appear like that's what you're doing).

    Without seeing the rest of your code, with the interrupt declarations ets it looks to me like you're triggering an interrupt on INT0 (PortB.0). When it fires it checks PortB.5 and if it's logoc low you're jumping to RECEIVING_DATA. Using a GOTO to jump out of an interrupt service routine is generally a VERY bad idea because the program execution will then not reach the @ INT_RETURN which is a very bad thing indeed.

    One more thing. IF you're doing this in an effort to receive RS232 data using SERIN or SERIN2 it won't work. I won't elaborate more on that in case that's not what you're doing.

    /Henrik.

  2. #2
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: Using an interrupt for an input

    Hi Henrik,

    I have a mainloop that is executing analog measurements and other "stuff." When the interrupt pin goes low, I want to stop doing whatever my mainloop is checking (non-critical stuff) and goto the receive section for the CAN network. It can be a gosub but I don't know if this would cause the same problem you are describing with the goto. It seems like such a simple concept (if this then that) but I've tried using interrupts before and haven't had any luck. DT's interrupt code made it simple and painless and I was hoping to use that to check hardware or software inputs.

    Putting it more simply, when the interrupt pin goes low, I want the 18F4550 to handle the CAN data and if there's no CAN data then stay in the mainloop.

    I'm not even sure I need an interrupt because the CAN data is so quick that the weak link seems to be the LCD screen. In other words, the LCD screen seems to take a little longer than the CAN data so as soon as one write cycle is finished there's a ton of CAN data to handle so I don't think the 18F4550 is ever waiting for data. But I wanted to try it to see if there's a difference.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Using an interrupt for an input

    Hi,
    Interrupts are hardware events, you can't just use any pin you like. You must use a pin which is capable of generating an interrupt. On the 18F4550 these are PortB.0 (INT0), PortB.1 (INT1) and PortB.2 (INT2).

    (PortB.4-7 are also capable of generating interrupts (interrupt on change) but they are trickier to use than the "normal" INT pins).

    In the INTCON2 register you'll find bits which controlls if the interrupt should be triggered off a rising or falling edge, set that up to your needs. You then declare your interrupt as shown in every example of DT-Ints
    Code:
    INTCON2.6 = 0   'Interrupt on falling edge of INT0
    INTCON2.5 = 1   'Interrupt on rising edge of INT1
    
    ' Here two interrupts are declared. One for INT0 (PortB.0) and one for INT1 (PortB.1). 
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    INT0_INT,  _RcvCAN,   PBP,  yes
            INT_Handler    INT1_INT,  _DoSomething, PBP, yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    Main:
      Pause 100
      Toggle LED
    Goto Main
    
    RcvCAN:
    ' Put your code here or GOSUB it but make SURE you have a RETURN at the end of the routine so you come back here, otherwise you'll crash.
    @ INT_RETURN
    
    DoSomethingElse:
    Toggle AnotherLED
    @ INT_RETURN
    Well, something like that.

    /Henrik.

Similar Threads

  1. Interrupt on change for IR input - is it a good way to go
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 30th July 2012, 11:05
  2. PIC Interrupt and PORTA input
    By Jerade in forum mel PIC BASIC
    Replies: 5
    Last Post: - 29th November 2009, 18:24
  3. Using interrupt as an input
    By kduck63 in forum General
    Replies: 1
    Last Post: - 22nd June 2009, 18:14
  4. Interrupt driven Buffered Serial Input
    By johnmiller in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 13th May 2007, 02:42
  5. realise second RX-interrupt input
    By mischl in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th February 2006, 04:42

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