Jump to content
43oh

Low power mode using WDT


Recommended Posts

Could someone throw out some example code of how I could for instance, run some code, go into LPM3 or 4 for 60 seconds, then run the code again?

 

So:

 

 

 

Loop:

Do something

Sleep for 60 sec

 

 

Couldn't the watch dog timer be used to accomplish this?  I have looked at some examples, I am just having a hard time seeing how to make it all work in the Energia IDE.  

 

Here is the sample code I have been looking at...I get what is going on here, but what I want is to get rid of the parts setting LED on or off, and turn it into a function so that I can call it, it will sleep, then the ISR will wake it up and clear the sleep mode...re-run the code, go back to sleep, etc.

 

Any help would be greatly appreciated.

 

 

Link to post
Share on other sites
 
LPM4 can only be woke up by pin interrupts.
 
for LPM3
 
taken directly from the ti example pack
 
msp430x20x3_wdt_02.c
 

 

#include <msp430x20x3.h>




void main(void)
{
  WDTCTL = WDT_ADLY_250;                    // WDT 250ms, ACLK, interval timer
  IE1 |= WDTIE;                             // Enable WDT interrupt
  P1DIR |= 0x01;                            // Set P1.0 to output direction


  _BIS_SR(LPM3_bits + GIE);                 // Enter LPM3 w/interrupt
}


// Watchdog Timer interrupt service routine
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void)
{
  P1OUT ^= 0x01;                            // Toggle P1.0 using exclusive-OR
}

 

u can play w/ the WDTCTL to alter the duration. i.e. divider, etc.

Link to post
Share on other sites

That post is the one that I keep going back to.  What I can't figure out, is how to use attachInterrupt, with the WDT instead of a button press, or pin Interrupt.  I see the two pieces, I just can't seem to figure out how to put them both together in Energia.  

 

 

So here is TI's example:

 

 

#include <msp430g2452.h>
 
void main(void)
{
  BCSCTL1 |= DIVA_1;                        // ACLK/2
  BCSCTL3 |= LFXT1S_2;                      // ACLK = VLO
  WDTCTL = WDT_ADLY_1000;                   // Interval timer
  IE1 |= WDTIE;                             // Enable WDT interrupt
  P1DIR = 0xFF;                             // All P1.x outputs
  P1OUT = 0;                                // All P1.x reset
  P2DIR = 0xFF;                             // All P2.x outputs
  P2OUT = 0;                                // All P2.x reset
 
  while(1)
  {
    int i;
    P1OUT |= 0x01;                          // Set P1.0 LED on
    for (i = 10000; i>0; i--);              // Delay
    P1OUT &= ~0x01;                         // Reset P1.0 LED off
    _BIS_SR(LPM3_bits + GIE);               // Enter LPM3
  }
}
 
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer (void)
{
  _BIC_SR_IRQ(LPM3_bits);                   // Clear LPM3 bits from 0(SR)
}
 
 
 
What I would like to do is use this for data collection.  Start in sleep, wake up after 10 minutes, log data to flash mem, go back to sleep, wake up 10 minutes later, etc.  
 
I will keep plugging away....anybody has any other ideas let me know.
 
Link to post
Share on other sites
  • 3 weeks later...

 

 

Rick,

 

    I just wanted to say thank you.  I became so frustrated trying to figure out the LPM's on these devices that I went back to ATTiny chips.  I made a few of the things I wanted, and even got them down under 60 microamps during sleep...but...I REALLLY wanted to see that 1micro in LPM3.  I finally revisited your code from the post above...and like a ton of bricks..it hit me, and I finally got it.  I set about modifying it for a test and ended up with a working parking sensor (for my wife, for the garage)...it wakes up when the light comes on (using an LDR in a voltage divider to trigger an interrupt), uses an ultrasonic sensor and three LED's to let her know if she is not far enough in the garage...just right..or too far in the garage.  Then after 2 minutes, it goes into LPM3 again, waiting for the lights in the garage to come on again.

 

   Now I think I am finally ready to tackle the watchdog to wake me up from interrupt. 

 

   Thanks again man!

 

   Jerod

Link to post
Share on other sites

The WDT can only be set to a limited set of intervals (depending on your clock divider and source). If you want to have more freedom on the interval, you can set the interval lower and then count a certain number of those intervals.

 

As an example, set the WDT to 250ms (1/4th of a second), then count 240 of those. 240 quarter seconds equals 60 seconds. Then set this counter to zero again and call another loop, which you could call "LoopMinute" or something like that.

Link to post
Share on other sites

Watchdog not 'freely' avaliable ?  

=>  already set and  used by Energia core (interval mode + 16MHz/512 +  interrupts) for milli(), delay(), micros()......functions.

settings seen in :    /hardware/msp430/cores/msp430/ wiring.c   file.

Link to post
Share on other sites
  • 1 year later...

Rick,

 

    I just wanted to say thank you.  I became so frustrated trying to figure out the LPM's on these devices that I went back to ATTiny chips.  I made a few of the things I wanted, and even got them down under 60 microamps during sleep...but...I REALLLY wanted to see that 1micro in LPM3.  I finally revisited your code from the post above...and like a ton of bricks..it hit me, and I finally got it.  I set about modifying it for a test and ended up with a working parking sensor (for my wife, for the garage)...it wakes up when the light comes on (using an LDR in a voltage divider to trigger an interrupt), uses an ultrasonic sensor and three LED's to let her know if she is not far enough in the garage...just right..or too far in the garage.  Then after 2 minutes, it goes into LPM3 again, waiting for the lights in the garage to come on again.

 

   Now I think I am finally ready to tackle the watchdog to wake me up from interrupt. 

 

   Thanks again man!

 

   Jerod

 Hi Jerod,

 

I am trying to build something similar to your parking sensor. Any possibility of sharing your code and schematic.

 

Thanks,

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...