External interrupts

Store Forums Digit Shield General Discussion External interrupts

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #513
    Baby Bertha
    Member

    I just discovered a problem with the digit shield – it uses digital pins 2 and 3, which are the only external interrupt inputs on a standard Arduino. That means I need to hack the digit shield hardware and software to use other pins to free up the external interrupts. Since the shield could use any pins for its serial lines, could I suggest that a future revision does that? Using external interrupts is surely going to be pretty common for projects that use the digit shield – for example, I’m making a precision speedometer, and an optical sensor causes an interrupt. The calculated speed is displayed on the digit shield. The pin conflict is turning a simple project into a considerably more complex one.

    #1077
    Michael
    Keymaster

    In fact, any Arduino pin can be used to sense external interrupts. It’s true that pins 2,3 are mapped to very fast external interrupts implemented by the ATmega328. But all other pins can also be used to trigger an interrupt routine when the pin state changes. These are called “pin change interrupts” versus “external interrupts”. The only difference is that they are triggered equally on rising and falling edges, so you need to check the state of the pin to determine which state change occurred.

    In short, you can sense external voltage change events on any pin and dispatch immediately to an interrupt handler. See http://arduino.cc/playground/Code/Interrupts

    A convenient library for dealing with pin change interrupts is here:
    http://code.google.com/p/arduino-pinchangeint/

    The choice of using pins 2-5 for the Digit Shield was very intentional with the above tradeoffs in mind. The routing and layout of the board was very challenging (for me, at least), as I wanted to achieve a particular form factor for the shield. I really needed to use pins near the right side of the board so I could route the signals. As you can see by the board layout, this was a very tricky layout, but I still managed to do it without using any vias!
    http://nootropicdesign.com/digitshield/design.html

    #1072
    Baby Bertha
    Member

    Well, that’s fine if you can use the pinChange interrupt, but not if you require the use of the external interrupt 🙂 I modified my shield, it was no problem, and the code was trivial to change because you nicely defined the pin numbers in one place.

    I’m not sure what’s so bad about vias – after all, all of the component holes are through-plated, so it’s not as if you’re avoiding the need for that plating when the boards are made. Looking at the layout, you could just shuffle all the pins along two places though, without needing any vias (you might need to move the header sockets over slightly to make enough room). Just a suggestion anyway – mine’s working how I need it. Thanks for a nice product!

    #1064
    Michael
    Keymaster

    Ok, glad you have it working. I’m still not clear on why you couldn’t use a pin change interrupt on an input pin. If your goal is to sense the input voltage change caused by an external event, that’s what pin change interrupts can be used for. It’s not as straightforward from a code standpoint, but the library makes it easy.

    Your right about vias — there’s nothing wrong with them at all, I just take it on as a challenge to design my boards without them. It’s just a routing challenge for me.

    #1579
    Praterma2
    Member

    Hello All,
    I just want to say “thank you!” for this discussion! I was stuck with two different devices wanting pins 2,3,4,5. This thread yielded enough insight that even a simple chemist such as myself can muck through the work of Arduinos and physical computing.
    thanks,
    matt
    ;D

    #1580
    Michael
    Keymaster

    Praterma2 , I’m glad that this was helpful.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.