This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430L092: How can I combine temperature sensor code and reading analog value code?

Part Number: MSP430L092

I have tried to combine two different example code. I intend to measure my sensor value so I used ADC example code (msp430x09x_apool_adc_07.c ). It works fine. After reading my sensor value, I wanted to measure built-in temperature sensor value.  Although I used example code ( msp430x09x_apool_adc_06.c  APOOL_ADC, Sampled Temperature and Convert to oC), it couldn't measure temperature sensor value. I considered that clear the ADC register APINT = 0x00; // Clear ADC-DAC-REG after measuring my sensor value but there is no change. I got result for temperature sensor that is DegC=3 or 5. First, I want to measure my sensor value and then built-in temperature sensor value respectively.

I don't want to measure my sensor value and built-in temperature sensor value at the same time.

I have tried to debug with IAR Embedded Workbench via MSP-FET FLASH EMULATION TOOL and MSP-TS430L092 Target Board.

I put my code below.


#include <msp430.h>

int ChannelA2;

int Result;
volatile short int DegC;

int main(void)
{

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

// Begin Configuration of the A-POOL registers
APCTL = 0; // Clear APCTL register
APCNF = CMPON+DBON+CONVON+EOCBU+APREFON+CLKSEL_MCLK; // Configure A-POOL elements, Select MCLK as A-POOL Clock Source
APINT = 0x00; // Clear ADC-DAC-REG
APVDIV=A2DIV_1;

APIE |= EOCIE; // Enable Interrupt for End of Conversion
APTRIM = REFTSEL;
APVDIV = TMPSEN; // Enable Temperature Sensor

P1DIR|=BIT4;

while(1)
{


APIE = EOCIE; // Enable Interrupt for End of Conversion
APINT = 0x00; // Clear ADC-DAC-REG
APCTL = OSEL+CBSTP+RUNSTOP+APNSEL_2+APPSEL_5; // Set Channels and Start Conversion
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupts enabled
ChannelA2 = APINT; // Get Result for A2

if(ChannelA2 >85){

APCTL = OSEL+ODEN+OSWP+APPSEL_4+APNSEL_5; // Set Channels and Start Conversion--+ODEN+
APINT = 0x00; // Clear ADC-DAC-REG
APIFG = 0;
APCTL |= CBSTP+SBSTP+RUNSTOP;
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupts enabled

Result = APINT;
DegC =(((Result-179)*125)/58) + 30; // Refer to datasheet for accuracy and offset specs

if(DegC>18 && DegC<30){
P1OUT|=BIT4;
}


}

else{

}



__no_operation(); // Place breakpoint here
}

}

//A_POOL Interrupt Service Routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=APOOL_VECTOR
__interrupt void A_POOL(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(APOOL_VECTOR))) A_POOL (void)
#else
#error Compiler not supported!
#endif
{

APIFG = 0; // Clear Interrupt Flag
__bic_SR_register_on_exit(LPM0_bits); // Exit Active to Sample next Channel

}

Please help me to fix mistakes

  • I have received your question I will go through the code and get back to you.
  • Did running example code 6 for ADC temperature sensor work correctly and yielded the right results?
  • short int MeasureTemp()
    {
        int Result;
        short int DegC;
    
        APCTL = 0;                                                     // Clear APCTL register
        APIE |= EOCIE;                                                 // Enable Interrupt for End of Conversion
        APTRIM = REFTSEL;
        APVDIV = TMPSEN;                                               // Enable Temperature Sensor
        APCNF = CMPON+DBON+CONVON+APREFON+CLKSEL_MCLK;                 // Configure A-POOL elements, Select MCLK as A-POOL Clock Source
    
        APCTL = OSEL+ODEN+OSWP+APPSEL_4+APNSEL_5;                                // Set Channels and Start Conversion--+ODEN+
        APINT = 0x00;                                                  // Clear ADC-DAC-REG
        APIFG = 0;
        APCTL |= CBSTP+SBSTP+RUNSTOP;
        __bis_SR_register(LPM0_bits + GIE);                           // Enter LPM0 w/ interrupts enabled
    
        Result = APINT;
        DegC =(((Result-179)*125)/58) + 30;                                   // Refer to datasheet for accuracy and offset specs
    
        __no_operation();                                             // SET BREAKPOINT HERE
    
        return DegC;
    }
    
    int MeasureVoltage()
    {
        int  ChannelA0;
    
        APCTL = 0;                                            // Clear APCTL register
        APCNF = CMPON+DBON+CONVON+EOCBU+APREFON+CLKSEL_MCLK;  // Configure A-POOL elements, Select MCLK as A-POOL Clock Source
        APINT = 0x00;                                         // Clear ADC-DAC-REG
    
        APIE  = EOCIE;                                        // Enable Interrupt for End of Conversion    
        APINT = 0x00;                                         // Clear ADC-DAC-REG
          APCTL = OSEL+CBSTP+RUNSTOP+APNSEL_0+APPSEL_5;       // Set Channels and Start Conversion
        __bis_SR_register(LPM0_bits + GIE);                   // Enter LPM0 w/ interrupts enabled
        ChannelA0 = APINT;                                    // Get Result for A0
    
        return ChannelA0;
    }
    
    

    Use these functions and call them in main.

  • Did you try the code above?

**Attention** This is a public forum