External interrupts

External interrupts

Postby Baby Bertha » Tue Feb 28, 2012 5:46 pm

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.
Baby Bertha
Newbie
Newbie
 
Posts: 4
Joined: Tue Feb 28, 2012 4:07 am

Re: External interrupts

Postby Michael » Wed Feb 29, 2012 8:41 am

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
Michael
Administrator
Administrator
 
Posts: 577
Joined: Sat May 29, 2010 8:24 am

Re: External interrupts

Postby Baby Bertha » Fri Mar 02, 2012 1:00 am

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!
Baby Bertha
Newbie
Newbie
 
Posts: 4
Joined: Tue Feb 28, 2012 4:07 am

Re: External interrupts

Postby Michael » Fri Mar 02, 2012 9:39 am

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.
Michael
Administrator
Administrator
 
Posts: 577
Joined: Sat May 29, 2010 8:24 am

Re: External interrupts

Postby Praterma2 » Tue Jan 29, 2013 12:24 pm

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
Praterma2
Newbie
Newbie
 
Posts: 1
Joined: Tue Jan 29, 2013 12:18 pm

Re: External interrupts

Postby Michael » Wed Jan 30, 2013 8:40 am

Praterma2 , I'm glad that this was helpful.
Michael
Administrator
Administrator
 
Posts: 577
Joined: Sat May 29, 2010 8:24 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest