Go Down

Topic: Can anyone suggest the difference between these two programs (Read 897 times) previous topic - next topic

vipersnh

Oct 18, 2011, 07:44 pm Last Edit: Oct 18, 2011, 09:04 pm by vipersnh Reason: 1
Code: [Select]
#include<avr/sleep.h>

ISR(TIMER1_OVF_vect)
{
 static boolean state=false;
  Serial.println("Woke from sleep mode");
 if(state)
 {
   state=false;
   digitalWrite(13,LOW);
 }
 else
 {
   state=true;
   digitalWrite(13,HIGH);
 }
 TIFR1=0x00;
}

void setup()
{
 pinMode(13,OUTPUT);
 TCCR1A=0x00;
 TCCR1B=0x05;
 TIFR1=0x00;
 TIMSK1=0x01;
 Serial.begin(9600);
 MCUCR|=0xF0;
}

void loop()
{
 Serial.println("Going to sleep mode");
 sleep_cpu();
}



and



#include<avr/sleep.h>

ISR(TIMER1_OVF_vect)
{
 static boolean state=false;
 //Serial.println("Woke from sleep mode");
 if(state)
 {
   state=false;
   digitalWrite(13,LOW);
 }
 else
 {
   state=true;
   digitalWrite(13,HIGH);
 }
 TIFR1=0x00;
}

void setup()
{
 pinMode(13,OUTPUT);
 TCCR1A=0x00;
 TCCR1B=0x05;
 TIFR1=0x00;
 TIMSK1=0x01;
//  Serial.begin(9600);
 MCUCR|=0xF0;
}

void loop()
{
//  Serial.println("Going to sleep mode");
 sleep_cpu();
}



actually the first program doesnt work in sleep mode, it always prints the data "going to sleep mode" and prints "woke from sleep mode" after every 4 seconds..
I'm finding it hard to figure out why its not working when i use serial port communications..

AWOL

I can't yet see the differences, but I can see what is the same - neither is posted in a code box.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

pekkaa

The second one has  Serial.println("Going to sleep mode"); commented out.

Btw, there are programs, like the diff command in Linux and Unixes, which show the differences between two files.

vipersnh

Guys i know the character wise difference between them..
I want to know why commented out program goes to sleep mode, and why uncommented one doesnt go to sleep mode.

AWOL

Perhaps the "tx register empty" signal wakes the processor shortly after it is put to sleep.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PaulS

Serial data sending in an ISR is not a good idea. It takes too long.

In the second code, you still have a call to Serial.print() although Serial.begin() is commented out. Why?

vipersnh


Serial data sending in an ISR is not a good idea. It takes too long.

In the second code, you still have a call to Serial.print() although Serial.begin() is commented out. Why?

Sorry for that..
programming mistake.

vipersnh

Thanks for all the replies...
Though i couldnt figure out how to use the above with serial port enabled and working..:(
I am able to use WDT timer for this purpose...:) :)

Go Up