MSP430 LaunchPad Low Power Mode

From Texas Instruments Wiki
Jump to: navigation, search

by Aldo Briano

 

In this example, after a period of 8 seconds without any activity, the mcu will go to low power mode. To show that it is in low power mode, the LED will turn off to save power. The MCU can be awoken using the push button’s interrupt which will turn on the LED.  

 


Related Projects


Quick Start

  • Create a new Project
  • Download Code
  • Enjoy!

Development

Code

//******************************************************************************
// MSP430G2xx Demo - WDT, Low Power Mode, Interval Overflow ISR, DCO SMCLK
//
// Description: Go to LowPowerMode using software timed by the WDT ISR. The LED
// will turn off when sleeping, Port 1 interrupt will awake the mcu and turn on
// LED. The mcu will sleep at approximately 250 * 32ms based on default 
// DCO/SMCLK clock source used in this example for the WDT.
// ACLK = n/a, MCLK = SMCLK = default
//
// MSP430G2xxx
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// | P1.0|-->LED
//
// Aldo Briano
// Texas Instruments Inc.
// July 2010
//******************************************************************************
#include <msp430g2231.h>

unsigned int wdtCounter = 0;
void main(void)
{
WDTCTL = WDT_MDLY_32; // Set Watchdog Timer interval to ~32ms
IE1 |= WDTIE; // Enable WDT interrupt
P1DIR |= BIT0; // Set P1.0 to output direction
P1OUT |= BIT0; // Turn on LED at 1.0
P1IE |= BIT3; // enable P1.3 interrupt
__enable_interrupt();

for(;;)
{

}
}

// Watchdog Timer interrupt service routine
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void)
{
if(wdtCounter == 249)
{
P1OUT = 0x00; // P1.0 turn off
wdtCounter = 0;
_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/interrupt 
}
else 
{
wdtCounter++;
}

}
// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
wdtCounter = 0; // reset watchdog timer counter
P1OUT |= 0x01; // turn LED on 
P1IFG = 0x0;
_BIC_SR(LPM3_EXIT); // wake up from low power mode

}


Theoretical Background

 The Watchdog Timer is typically used to trigger a system reset after a certain amount of time. In most examples, you will see that this timer is stopped during the first line of code. The Watchdog Timer counts down from a specified value and either resets or interrupts when overflow is reached. A way to use this timer is to periodically service it by resetting its counter so that the system “knows” that everything is all right and there is no reset required. In this case, this module is configured as an interval timer to generate interrupts at selected time intervals.

Low power mode is a feature for which the MSP430 is designed for. It is useful because it shuts down certain areas of the CPU in order to save power. Since most embedded systems need to be energy efficient, low power modes of operation are employed. The MSP430 features five modes of operation, yet the most popular 3 are the following (the others can be found in the datasheet):

              1. Active mode (AM), I ≈ 300 uA
                                     a. All clocks are active


               2. Low-power mode 0 (LPM0), I ≈ 85uA
                                     a. CPU is disabled
                                     b. ACLK and SMCLK remain active, MCLK is disabled


               3. Low-power mode 3 (LPM3), I ≈ 1uA
                                     a. CPU is disabled
                                     b. MCLK and SMCLK disabled
                                     c. ACLK remains active
                                     d. DCO’s dc-generator is disabled

The interesting thing about these modes of operation is that interrupts can wake up the device from any low power mode, process, and decide whether to restore the low power or active mode.

Programming

The watchdog timer is set to interval mode by setting its register to WDTCTL = WDT_MDLY_32.  This setting is defined in the msp430g2231.h include file.  It sets the watchdog to interrupt every ≈32ms when clocking from a 1Mhz SMCLK.  An interrupt counter is set up so that the device goes to low power after ≈ 8 seconds ( 32ms * 250 = 8 s).  The watchdog interrupt counter is cleared every time P1 interrupts, as well as wakes up if the device is currently in low power mode. 


Key things to remember:

  • Enable WDT interrupt
  • Enable P1 and global interrupts
  • Clear P1 interrupt flag before exiting
  • When setting LPM3, the GIE must also be set to allow interrupts

 

Future Ideas

  • Use an external clock for the watchdog timer

References

  1. MSP430x2xx Family User Guide
  2. [http://www.ti.com/lit/gpn/msp430g2231 MSP430G2x31 Datasheet