Part Number: MSP430F2619
Tool/software: Code Composer Studio
I am currently programming the MSP430F2619 chip with the 64 pin DEV board. When I run a the simple ta1 example code and enter LPM3 I see 1 uA current draw in low power mode which is exactly what I expect. However now I am trying to use the ADC12 with a timer interrupt.I am measuring the on board temp sensor and measuring P6.0 as well. It seems no matter what I turn off after getting the ADC12 measurements I am still drawing 1.3 mA when I enter LPM3. I have set break points everywhere and it appears the code is working correctly but I can't seem to get ~1uA in LPM3 while using the ADC12.
/* --COPYRIGHT--,BSD_EX
* Copyright (c) 2012, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*******************************************************************************
*
* MSP430 CODE EXAMPLE DISCLAIMER
*
* MSP430 code examples are self-contained low-level programs that typically
* demonstrate a single peripheral function or device feature in a highly
* concise manner. For this the code may rely on the device's power-on default
* register values and settings such as the clock configuration and care must
* be taken when combining code from several examples to avoid potential side
* effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
* for an API functional library-approach to peripheral configuration.
*
* --/COPYRIGHT--*/
//*****************************************************************************
// MSP430x26x Demo - ADC12, Sample A10 Temp, Set P1.0 if Temp ++ ~2C
//
// Description: Use ADC12 and the integrated temperature sensor to detect
// temperature gradients. The temperature sensor output voltage is sampled
// ~ every 60ms and compared with the defined delta values using an ISR.
// (ADC12OSC/256)/ determines sample time which needs to be greater than
// 30us for temperature sensor.
// ADC12 is operated in repeat-single channel mode with the sample and
// convert trigger sourced from Timer_A CCR1. The ADC12MEM0_IFG at the end
// of each converstion will trigger an ISR.
// ACLK = n/a, MCLK = SMCLK = default DCO ~ 1.045M, ADC12CLK = ADC12OSC
//
// MSP430F261x/241x
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// |A10 P1.0|-->LED
//
// B. Nisarga
// Texas Instruments Inc.
// September 2007
// Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.42A
//******************************************************************************
#include <msp430.h>
#define ADCDeltaOn 12 // ~2 Deg C delta
//static unsigned int FirstADCVal; // holds 1st ADC result
int in_value1=0, in_value2=0;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog
/////////TIMER//////////////////////////////////
TACCTL1 = OUTMOD_4; // Toggle on EQU1 (TAR = 0)
TACTL = TASSEL_1 + MC_1 + ID_0; // ACLK, divider of 1, up mode
TACCR0 = 65000; // 8192 ACLK periods = 0.25 seconds
TACCTL0 = CCIE; // Enable interrupt on Timer A2
///////////TURN ON CRYSTAL/////////////////////////
BCSCTL1 &= ~XTS;
BCSCTL3 |= XT2S_0 + LFXT1S_0 + XCAP_3;
do
{
IFG1 &= ~OFIFG;
__delay_cycles(100);
}
while(IFG1 & OFIFG);
BCSCTL2 |= SELM_3;
BCSCTL2 |= DIVM_0;
///////ADC/////////////////////////////////
ADC12CTL1 = SHS_0 + SHP + CONSEQ_3; // TA trig., rpt conv.
ADC12MCTL0 = SREF_1 + INCH_0;
ADC12MCTL1 = SREF_1 + INCH_10 + EOS;// Channel A10, Vref+
ADC12IE = 0x01; // Enable ADC12IFG.0
ADC12CTL0 = SHT0_8 + REF2_5V + REFON + ADC12ON + ENC + MSC; // Config ADC12
//HANDLE PINS/////////////////////////
P1DIR = 0xFF;//Initialize ports
P1OUT = 0x00;
P2DIR = 0xFF;//Initialize ports
P2OUT = 0x00;
P3DIR = 0xFF;//Initialize ports
P3OUT = 0x00;
P4DIR = 0xFF;//Initialize ports
P4OUT = 0x00;
P5DIR = 0xFF;//Initialize ports
P5OUT = 0x00;
P6DIR = 0xFF;//Initialize ports
P6OUT = 0x00;
P7DIR = 0xFF;//Initialize ports
P7OUT = 0x00;
P8DIR = 0xFF;//Initialize ports
P8OUT = 0x00;
PAOUT = 0;
PADIR = 0xFFFF;
while (1)
{
ADC12CTL0 &= ~ADC12ON; //ADC OFF
P6DIR = 0xFF;//Initialize ports
P6OUT = 0x00;
ADC12IE = 0x00;
ADC12CTL0 &= ~REF2_5V; //Reference voltage off
__bis_SR_register(LPM3_bits + GIE); // Enter LPM3 w/ interrupt
}
}
// Timer A0 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMERA0_VECTOR))) Timer_A (void)
#else
#error Compiler not supported!
#endif
{
P6SEL |= 0x01; // P6.0-ADC option select
P6SEL |= BIT0; //Connect pin to A0 input
ADC12CTL0 |= ADC12ON; //ADC ON
ADC12IE = 0x01; //ADC12 interrupt enabled
ADC12CTL0 |= REF2_5V; //Reference votlage on
ADC12CTL0 |= ADC12SC; //Software controlled start sample and hold
__bic_SR_register(LPM3_bits + GIE ); ///Exit LPM3, go back to main
}
//////////////////////ADC Interrupt///////////////////////
///////Interrupt happens when sample and hold conversion is done/////////////////
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12ISR (void)
#else
#error Compiler not supported!
#endif
{
in_value1= ADC12MEM0; //P6.0
in_value2= ADC12MEM1; //On board temperature sensor
__bic_SR_register_on_exit(LPM3_bits + GIE); // Exit active CPU ///Exit LPM3, go back to main
}