Go Down

Topic: mega168 no interrupt when RISING CHANGES FALLING (Read 514 times) previous topic - next topic

victorjung

hi, i made a small programm wich blink a few seconds go to sleep mode the if waked up blink a few second etc...
that s my code:
Code: [Select]

include <avr/sleep.h>
int i=1;
void setup()
{
  pinMode(2, INPUT);
  pinMode(13, OUTPUT);
  digitalWrite(2,LOW); //for pull down
}
void call_back()
{}
void f_make_it_sleep()
{
set_sleep_mode(SLEEP_MODE_PWR_DOWN);//set sleep parameters
sleep_enable();
attachInterrupt(0,call_back,RISING);
sleep_mode();
sleep_disable();
detachInterrupt(0);
}
void loop()
{ i++;
  digitalWrite(13,HIGH);
  delay(200);
   digitalWrite(13,LOW);
  delay(200);
  if(i==15)
  {
   i=0;
   digitalWrite(2,LOW); //for pull down again (to be sure)
   f_make_it_sleep();
  }
 
}

it doesn't work neither for CHANGES or FALLING (after inversing pull down by pull up)
But it does work perfectly with LOW and the pull down in pull up...
It's a minipro mega168 5v 16mhz
i have no more ideas...
all the 4 kind of interrupt work perfectly on my uno...

dc42

The datasheet for the atmega chip family says that only a LOW interrupt or a pin change interrupt can wake it up from power down mode.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

victorjung

thank s for your reply,
isn't RISING a pin change interrupt?

michinyon

if you put it to sleep,   then your program will stop .

Do you have some external way of signalling the interrupt pin ?  Like a wire with a switch,  or something ?

LarryD

This may be of some use:
http://www.gammon.com.au/forum/?id=11497
The way you have it in your schematic isn't the same as how you have it wired up!

victorjung

is it possible that an external interrupt must be a low interrupt and no other interrupt, to wake it up?

dc42


thank s for your reply,
isn't RISING a pin change interrupt?


No, a pin change interrupt is a different animal, which the attachInterrupt function doesn't use. However, you can use a pin change interrupt to do the same thing you would do using a RISING interrupt.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

dc42


is it possible that an external interrupt must be a low interrupt and no other interrupt, to wake it up?


Yes if you are using the INT0 or INT1 interrupt (on the Uno), which is what the attachInterrupt function uses. No if you use a pin change interrupt.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

victorjung

what s exactly a pin change interrupt? i think i don't understand this...
i think i am using int0 with attachinterrupt according to my code  :|
so it should work with rising right?

dc42


what s exactly a pin change interrupt? i think i don't understand this...
i think i am using int0 with attachinterrupt according to my code  :|
so it should work with rising right?


No it won't, see my earlier replies. For more on pin change interrupts, see http://playground.arduino.cc/Main/PinChangeInt.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

victorjung

i finally get it!!!! thanks for your patience :)
so you re saying i should use pin change if i absolutely want a rising interrupt?
I gonna try it
one more time thanks

dc42


so you re saying i should use pin change if i absolutely want a rising interrupt?
Yes, if you want a rising interrupt to wake up the mcu from power down mode.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Go Up