Pages: [1]   Go Down
Author Topic: RISING and FALLING interrupt on same pin?  (Read 661 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can I use a single pin to tigger a RISING interrupt service routine, as well as a separate FALLING interrupt service routine?
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3941
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Use a pin change interrupt, or INT0 and INT1 can both be configured to interrupt on any logical change. Looks like it will be up to the code to determine rising or falling, but that should be straightforward. Read the pin first thing in the ISR, if it's low, then falling, if high then rising. So one ISR rather than two, but the same functionality can be accomplished I think.
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 22
Posts: 1675
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thats badically it, the external interrupts int0 and int1 which are on digital pins 2 and 3 can be set to interrupt on rising, falling or change which is the one you want.

For the other interrupts its a little more difficult, but there is a library that helps. here is a quick overview of the library 'pinchaneint'

http://rcarduino.blogspot.com/2012/03/need-more-interrupts-to-read-more.html

Duane B

rcarduino.blogspot.com


Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can I use a single pin to tigger a RISING interrupt service routine, as well as a separate FALLING interrupt service routine?

The pin change interrupt isn't going to help any more than doing a CHANGE interrupt would. In any case, there is only one ISR.

Conceivably you could switch from RISING to FALLING inside the ISR, but why bother? By the time you have done that, you may as well have found out (by reading the pin) which one it is.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13477
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Code:

void setup()
{
  pinMode(pin, OUTPUT);
  attachInterrupt(0, isr, CHANGE);
}

void loop()
{
  digitalWrite(pin, state);
}

void isr()
{
  if (digitalRead(2) == HIGH) doRising();  // you can use direct port read to be faster - http://www.arduino.cc/en/Reference/PortManipulation -
  else doFalling();
}

doRising()
{
}

doFalling()
{
}
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: