From 4ef1f4b8e656c1e7b8b98f455517879a56c6a9a2 Mon Sep 17 00:00:00 2001 From: maniacbug Date: Tue, 10 May 2011 21:34:51 -0700 Subject: [PATCH] Removed power_all/enable/disable, useless. Added a multiples of the wakeup. --- examples/pingpair_sleepy/pingpair_sleepy.pde | 21 ++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/examples/pingpair_sleepy/pingpair_sleepy.pde b/examples/pingpair_sleepy/pingpair_sleepy.pde index a3a31bf..2abffc9 100644 --- a/examples/pingpair_sleepy/pingpair_sleepy.pde +++ b/examples/pingpair_sleepy/pingpair_sleepy.pde @@ -70,6 +70,9 @@ typedef enum { wdt_16ms = 0, wdt_32ms, wdt_64ms, wdt_128ms, wdt_250ms, wdt_500ms void setup_watchdog(uint8_t prescalar); void do_sleep(void); +const short sleep_cycles_per_transmission = 4; +volatile short sleep_cycles_remaining = sleep_cycles_per_transmission; + // // Normal operation // @@ -106,7 +109,7 @@ void setup(void) // Only the ping out role sleeps. Wake up every 4s to send a ping if ( role == role_ping_out ) - setup_watchdog(wdt_4s); + setup_watchdog(wdt_1s); // // Setup and configure rf radio @@ -192,13 +195,19 @@ void loop(void) // Shut down the system // + // Experiment with some delay here to see if it has an effect + delay(500); + // Power down the radio. Note that the radio will get powered back up // on the next write() call. radio.powerDown(); // Sleep the MCU. The watchdog timer will awaken in a short while, and // continue execution here. - do_sleep(); + while( sleep_cycles_remaining ) + do_sleep(); + + sleep_cycles_remaining = sleep_cycles_per_transmission; } // @@ -242,10 +251,9 @@ void loop(void) // Sleep helpers // -// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms +// 0=16ms, 1=32ms,2=64ms,3=125ms,4=250ms,5=500ms // 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec - void setup_watchdog(uint8_t prescalar) { prescalar = min(9,prescalar); @@ -258,8 +266,8 @@ void setup_watchdog(uint8_t prescalar) WDTCSR = _BV(WDCE) | wdtcsr | _BV(WDIE); } -// Even though it does nothing, it's necessary to have a WDT ISR ISR(WDT_vect) { + --sleep_cycles_remaining; } void do_sleep(void) @@ -267,12 +275,9 @@ void do_sleep(void) set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here sleep_enable(); - power_all_disable(); sleep_mode(); // System sleeps here sleep_disable(); // System continues execution here when watchdog timed out - power_all_enable(); } - // vim:ai:cin:sts=2 sw=2 ft=cpp