Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: attachInterrupt() teensy 3.1 multiple ISR per interrupt

  1. #1
    Senior Member
    Join Date
    Jan 2014
    Location
    London, UK
    Posts
    109

    attachInterrupt() teensy 3.1 multiple ISR per interrupt

    Unfortunately I'm away from my Teensy 3.1 so I can't test this, but the documentation isn't clear so I'm going to ask to put my mind at rest.

    The AVR can assign one ISR to a pin and one can select a trigger mode, Falling, Rising, Change etc...

    With the ARM's more complex interrupt controller, is is possible to attach a separate ISR for each of the interrupt trigger modes of a single pin?

    So one ISR for a rising state and another ISR for a falling state on a single pin?

    Many thanks.

  2. #2
    Senior Member
    Join Date
    Sep 2013
    Location
    Hamburg, Germany
    Posts
    894
    The pins can be configured to generate an interrupt request on either edge, i.e. rising and falling (PORTx_PCRn.IRQC, chapter 11.14.1). There is only one interrupt flag per port (!), so your ISR has to examine PORTx_ISFR (chapter 11.14.4) to see if an interrupt occured for your pin. If your signal doesn't change too quickly, you can read the pin level and then call the approriate subroutine (pin is low: there was a falling edge; pin is high: there was a rising edge). If only one pin per port generates interrupt requests, you don't have to check if it came from the right pin.

    AFAIK (I'm a Cortex-M4 noob, btw) there is no method to get individual interrupts for each interrupt condition on one pin. If you have spare pins, you can feed your signal into two of them and configure one pin to generate an interrupt when a rising edge occurs, and one pin to generate an interrupt when a falling edge occurs.

    So: what timing requirements do you have and what do you want to achieve? Maybe there's a totally different way to achieve what you want.

    Regards

    Christoph

  3. #3
    Senior Member
    Join Date
    Jan 2014
    Location
    London, UK
    Posts
    109
    Hi Christoph,

    Many thanks for your reply. There is no problem only being able to attach a single ISR to a pin, I simply attachIntrrupt to the pin triggered by a state change and then do a check in the ISR for the state of the pin and direct the program flow after that.

    My question was to see if this could be handled by the hardware, perhaps saving a few CPU cycles

  4. #4
    Senior Member
    Join Date
    Sep 2013
    Location
    Hamburg, Germany
    Posts
    894
    Do you really need to save CPU cycles? If so, why? Don't try to optimize when there's no need.

  5. #5
    Senior Member
    Join Date
    Jan 2014
    Location
    London, UK
    Posts
    109
    Quote Originally Posted by christoph View Post
    Do you really need to save CPU cycles? If so, why? Don't try to optimize when there's no need.
    I like to leave the ISR as quickly as possible, so a few cycles saved here and there are always a good idea
    My programming history is writing games/demos on the Amiga, so optimization is everything

  6. #6
    Junior Member
    Join Date
    Jan 2014
    Location
    Huntsville Alabama
    Posts
    14
    Hi,

    Where can I find a reference for ALL interrupt related functions that are available. The teensyduino interrupt.h file is empty, PJRC website has a page on using interrupts but it's not up to date for teensy 3.1, which I'm using, and no interrupts mentioned on the library compatibility page.

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •