Pages: [1]   Go Down
Author Topic: mega168 no interrupt when RISING CHANGES FALLING  (Read 459 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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...
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Faraday Member
**
Karma: 61
Posts: 2891
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

Offline Offline
Edison Member
*
Karma: 64
Posts: 2489
The last thing you did is where you should start looking.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This may be of some use:
http://www.gammon.com.au/forum/?id=11497
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley-neutral
so it should work with rising right?
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley-neutral
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.
Logged

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.

Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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.

Pages: [1]   Go Up
Jump to: