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: TEMPERATURE SENSOR DELAYING PROBLEM

Part Number: MSP430L092
Other Parts Discussed in Thread: MSP430WARE

I used MSP430L092 example code for measuring temperature sensor value but It seems that there is a delay for operation. For example; I set a condition that if DegC is greater than 30, P1.4 port that is tied LED is high. After 42 seconds, my LEDis high. I don't understand this delay. Respectively, If I set greater than 20 this sensor result, it is high later 30 seconds. I put below example code that I rearranged.

/* --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--*/
/* Description: ADC Temperature Sample */
/****************************A_POOL ADC Conversion *******************************/
/* */
/* */
/* +----L092---+ */
/* |*1 14 | */
/* | 2 13 | */
/* | 3 12 | */
/* | 4 11 | */
/* | 5 10 | */
/* | 6 9 | */
/* | 7 8 | */
/* +-----------+ */
/* */
/* D.Dang/ D.Archbold/ D.Szmulewicz /F. Chen */
/* Texas Instruments Inc. */
/* Built with IAR Version 5.51.1 and CCS Verison 5.3.00090 */
/*********************************************************************************/

#include <msp430.h>

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
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
P1DIR |= (BIT4+BIT5+BIT6);

while(1)
{

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>20){
P1OUT|=BIT4;
}

else{
P1OUT&=~BIT4;

}

__no_operation(); // SET 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 calculate Temperature


}

Please, Can someone give me an advice prevent this delay?

Thanks in advance

  • Hello,

    It seems you are not setting up your clock from default values. By default, the DCO will go to 1MHz and MCLK has a divide by 8. This would mean you are running at 125kHz and sampling at the same speed (since you choose MCLK to be ADC Clock). This is the reason why you see such a delay.
  • This code is an example for MSP430L092 microcontroller. I just added up the code for LED.

    I uses this below code for clock. I intend to combine temperature sensor code part with my different code that contains below code in while(1) loop.

    I have tried them with together but it does not work.

    What do I need to solve this problem?


    TA0CCTL0 = CCIE; // TA0CCR0 interrupt enabled

    TA0CCR0 = 10; // Set value for TA0CCR0

    TA0CTL = TASSEL_2 + MC_1 + TACLR; // SMCLK, up mode



    __bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt: CPU, MCLK are disabled

    // ACLK is active, SMCLK is active, and HFOSC is on

    TA0CTL = MC_0+TACLR;

    Please give me more details about solution.
  • Hello,

    Timing wise, you are not changing MCLK so this application will run slow, thus your delay. In the above code, you will go into LPM0 until your Timer interrupt is raised. Then within your Timer ISR, you need to exit LPM0 in order to continue your code.
  • Thanks for quick reply. Your solution is changing clock division, isn't it? I tried "CLKDIV0" (A-POOL Prescaler Control Bit: 0*/). It doesn't work.

    In my code, If I set up if(DegC>40), P1.4 pin is going to be high later 50 seconds. I think that this example code is not working correctly. My sensor value is increasing second by second. I observed that When time is up I mean that after 50 seconds, my led is blinking 2 times and then it turns on constantly.

    Is there another example code to measure built-in temperature sensor value for msp430l092?

    I couldn't measure it exactly.

  • Hello,

    The clock division I spoke of is not within the APOOL nodule, but the clock system. The clock system in its default state, configure the DCO to 1MHz, the divides that down to 125kHz for MCLK and SMCLK. If you want your application to run faster, please see the examples located within MSP430 for changing your clock system to 1MHz or higher.

    As far as temp sensor examples, we only have one example of this and it is msp430x09x_apool_adc_06.c located within MSP430Ware
  • In clock system, I tried to add up below code from example msp430x09x_ta_07 for setting up clock but there is no change. I still suffer from this delay problem. I consider that DegC is increasing second by second so it always increases .

    CCSCTL7 = 0; // Clear HF & LF OSC fault
    SFRIFG1 = 0; // Clear OFIFG flags

    CCSCTL4 = SELS_0 + SELM_0; // Select HFCLK/DCO as the source for SMCLK and MCLK
    CCSCTL5 = DIVS_0 + DIVM_0; // Set the Dividers for SMCLK to 1
    CCSCTL0_H |= 0xFF; // Lock CCS
    /* Lock by writing to upper byte */

    I put my whole code. Please help me. I couldn't understand your solution. I just want to blink my LED when DegC is greater than 20 *C but I didn't overcome this problem.


    /*
    * --/COPYRIGHT--*/
    /* Description: ADC Temperature Sample */
    /****************************A_POOL ADC Conversion *******************************/
    /* */
    /* */
    /* +----L092---+ */
    /* |*1 14 | */
    /* | 2 13 | */
    /* | 3 12 | */
    /* | 4 11 | */
    /* | 5 10 | */
    /* | 6 9 | */
    /* | 7 8 | */
    /* +-----------+ */
    /* */
    /* D.Dang/ D.Archbold/ D.Szmulewicz /F. Chen */
    /* Texas Instruments Inc. */
    /* Built with IAR Version 5.51.1 and CCS Verison 5.3.00090 */
    /*********************************************************************************/

    #include <msp430.h>

    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
    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
    P1DIR |= (BIT4+BIT5+BIT6);


    /***************************/
    /* Setup CCS */
    /* SMCLK = HFCLK/1 ~1MHz */
    /***************************/
    CCSCTL0 = CCSKEY; // Unlock CCS
    while (SFRIFG1 & OFIFG) // Oscillator Flag(s)?
    {
    CCSCTL7 = 0; // Clear HF & LF OSC fault
    SFRIFG1 = 0; // Clear OFIFG flags
    }
    CCSCTL4 = SELS_0 + SELM_0; // Select HFCLK/DCO as the source for SMCLK and MCLK
    CCSCTL5 = DIVS_0 + DIVM_0; // Set the Dividers for SMCLK to 1
    CCSCTL0_H |= 0xFF; // Lock CCS
    /* Lock by writing to upper byte */
    while(1)
    {

    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>20){
    P1OUT|=BIT4;
    }

    else{
    P1OUT&=~BIT4;

    }

    __no_operation(); // SET 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 calculate Temperature


    }
  • I added up the code ( APOMR=CLKDIV_0; ) for clock division APOMR is A-POOL Operation Mode Register but I couldn't solve this problem. Please, can you correct my mistakes?
  • Hello,

    As stated before, the issue is not the clocking of the ADC, but of the clock of your whole system. You need to increase the clock speed of Mclk in order to run through your application at a faster rate. You can then run the ADC of off the SMCLK at a lower rate that matches your needed ADC sampling specifications.

**Attention** This is a public forum