Go Down

Topic: RISING and FALLING interrupt on same pin? (Read 859 times) previous topic - next topic

ArduinoTom

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

Jack Christensen

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.
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

DuaneB

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


Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

Nick Gammon


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.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

robtillaart


Code: [Select]


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()
{
}
Rob Tillaart

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

Go Up