sleep_mode PWR_SAVE
hi
i'm using mstimer2 http://www.arduino.cc/playground/main/mstimer2 launch periodically function.
it works perfectly. uses timer2, i'd use sleep_mode put arduino in pwr_save in order save energy
so code test:
---------
// toggle led on pin 13 each second
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <avr/power.h>
#include <mstimer2.h>
void flash() {
static boolean output = high;
interrupts();
digitalwrite(13, output);
output = !output;
serial.println(1, byte);
serial.println(2, byte);
}
void setup() {
pinmode(13, output);
serial.begin(9600);
mstimer2::set(10000, flash);
mstimer2::start();
sei();
}
void sleepnow() // here put arduino sleep
{
/* time set sleep mode. in atmega8 datasheet
* http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf on page 35
* there list of sleep modes explains clocks and
* wake sources available in sleep modus.
*
* in avr/sleep.h file, call names of these sleep modus found:
*
* 5 different modes are:
* sleep_mode_idle -the least power savings
* sleep_mode_adc
* sleep_mode_pwr_save
* sleep_mode_standby
* sleep_mode_pwr_down -the power savings
*
* now, want power savings possible, we
* choose according
* sleep modus: sleep_mode_pwr_down
*
* timer 2 overflow interrupt able wake atmega in pwr_save
*
*/
set_sleep_mode(sleep_mode_pwr_save); // sleep mode set here
sleep_enable(); // enables sleep bit in mcucr register
// sleep possible. safety pin
sleep_mode(); // here device put sleep!!
// program continues here after waking up
sleep_disable(); // first thing after waking sleep:
// disable sleep...
}
void loop() {
sleepnow();
}
------------------
and gives nonsense output, sends 10 chars \x0 every 20 sec...
this sketch works in sleep_mode_idle, not in sleep_mode_pwr_save
however timer2 works in sleep_pwr_save, should work
any idea welcome !!
ps: i've been debugging piece of code hours several guys on irc, i've tried lot of example
if have idea, please test it, because may have tried
thanks help
i'm gonna crazy this...
i'm using mstimer2 http://www.arduino.cc/playground/main/mstimer2 launch periodically function.
it works perfectly. uses timer2, i'd use sleep_mode put arduino in pwr_save in order save energy
so code test:
---------
// toggle led on pin 13 each second
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <avr/power.h>
#include <mstimer2.h>
void flash() {
static boolean output = high;
interrupts();
digitalwrite(13, output);
output = !output;
serial.println(1, byte);
serial.println(2, byte);
}
void setup() {
pinmode(13, output);
serial.begin(9600);
mstimer2::set(10000, flash);
mstimer2::start();
sei();
}
void sleepnow() // here put arduino sleep
{
/* time set sleep mode. in atmega8 datasheet
* http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf on page 35
* there list of sleep modes explains clocks and
* wake sources available in sleep modus.
*
* in avr/sleep.h file, call names of these sleep modus found:
*
* 5 different modes are:
* sleep_mode_idle -the least power savings
* sleep_mode_adc
* sleep_mode_pwr_save
* sleep_mode_standby
* sleep_mode_pwr_down -the power savings
*
* now, want power savings possible, we
* choose according
* sleep modus: sleep_mode_pwr_down
*
* timer 2 overflow interrupt able wake atmega in pwr_save
*
*/
set_sleep_mode(sleep_mode_pwr_save); // sleep mode set here
sleep_enable(); // enables sleep bit in mcucr register
// sleep possible. safety pin
sleep_mode(); // here device put sleep!!
// program continues here after waking up
sleep_disable(); // first thing after waking sleep:
// disable sleep...
}
void loop() {
sleepnow();
}
------------------
and gives nonsense output, sends 10 chars \x0 every 20 sec...
this sketch works in sleep_mode_idle, not in sleep_mode_pwr_save
however timer2 works in sleep_pwr_save, should work
any idea welcome !!
ps: i've been debugging piece of code hours several guys on irc, i've tried lot of example
if have idea, please test it, because may have tried
thanks help
i'm gonna crazy this...
hi again
after hours (and hours , hours...) of debug chroos on irc.
this man has in end found solution !
just add delay(5) after last print...
in order let buffer empty before running in sleep mode
thanks chroos !!
after hours (and hours , hours...) of debug chroos on irc.
this man has in end found solution !
just add delay(5) after last print...
in order let buffer empty before running in sleep mode
thanks chroos !!
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > sleep_mode PWR_SAVE
arduino
Comments
Post a Comment