Loading...
Pages: [1]   Go Down
Author Topic: RISING and FALLING interrupt on same pin?  (Read 185 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 41
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
Edison Member
*
Karma: 43
Posts: 2480
"We're a proud service of the Lost Electricity Reclamation Agency"
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

Get the infamous "One Million Ohms" board at tINDIE.com: http://tinyurl.com/BuyMohms

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 20
Posts: 1626
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
Melbourne, Australia
Offline Offline
Shannon Member
*****
Karma: 218
Posts: 13896
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


Netherlands
Offline Offline
Tesla Member
***
Karma: 87
Posts: 9360
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 -

Pages: [1]   Go Up
Print
 
Jump to: