Pages: [1]   Go Down
Author Topic: Can anyone suggest the difference between these two programs  (Read 756 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#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..
« Last Edit: October 18, 2011, 02:04:53 pm by vipersnh » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 286
Posts: 25666
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't yet see the differences, but I can see what is the same - neither is posted in a code box.
Logged

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

Finland
Offline Offline
Sr. Member
****
Karma: 1
Posts: 270
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 286
Posts: 25666
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Perhaps the "tx register empty" signal wakes the processor shortly after it is put to sleep.
Logged

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

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

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

Pages: [1]   Go Up
Jump to: