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.

i am not getting the temperature vale.

/*
* -------------------------------------------
* MSP432 DriverLib - v3_21_00_05
* -------------------------------------------
*
* --COPYRIGHT--,BSD,BSD
* Copyright (c) 2016, 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.
* --/COPYRIGHT--*/
/*******************************************************************************
* MSP432 ADC14 - Single Channel Repeat Temperature Sensor
*
* Description: This example shows the use of the internal temperature sensor.
* A simple continuous ADC sample/conversion is set up with a software trigger.
* The sample time is set to TBD as speced by the User's Guide. All calculations
* take place in the ISR which take advantage of the Stacking Mode of the FPU.
* The temperature is calculated in both Celsius and Fahrenheit.
*
* MSP432P401
* ------------------
* /|\| |
* | | |
* --|RST P5.5 |
* | |
* | |
* | |
*
* Author: Timothy Logan
******************************************************************************/
/* DriverLib Includes */
#include "LibG2_main.h"
volatile float tempC;
volatile float tempF;
int64_t status;
uint32_t cal30, cal85;
int main(void)
{
/* Halting WDT */
WDT_A_holdTimer();

/* Enabling the FPU with stacking enabled (for use within ISR) */
FPU_enableModule();
FPU_enableLazyStacking();

/* Initializing ADC (MCLK/1/1) with temperature sensor routed */
ADC14_enableModule();
ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1,
ADC_TEMPSENSEMAP);

/* Configuring ADC Memory (ADC_MEM0 A22 (Temperature Sensor) in repeat
* mode).
*/
ADC14_configureSingleSampleMode(ADC_MEM0, true);
ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS,
ADC_INPUT_A22, false);

/* Configuring the sample/hold time for TBD */
ADC14_setSampleHoldTime(ADC_PULSE_WIDTH_192,ADC_PULSE_WIDTH_192);

/* Enabling sample timer in auto iteration mode and interrupts*/
ADC14_enableSampleTimer(ADC_AUTOMATIC_ITERATION);
ADC14_enableInterrupt(ADC_INT0);

/* Setting reference voltage to 2.5 and enabling temperature sensor */
REF_A_setReferenceVoltage(REF_A_VREF2_5V);
REF_A_enableReferenceVoltage();
REF_A_enableTempSensor();

/* Enabling Interrupts */
Interrupt_enableInterrupt(INT_ADC14);
Interrupt_enableMaster();

/* Triggering the start of the sample */
ADC14_enableConversion();
ADC14_toggleConversionTrigger();

/* Going to sleep */
while (1)
{
/*status = ADC14_getEnabledInterruptStatus();
ADC14_clearInterruptFlag(status);

if(status & ADC_INT0)
{
cal30 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF,
SYSCTL_30_DEGREES_C);
cal85 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF,
SYSCTL_85_DEGREES_C);

tempC = (float) (((uint32_t) ADC14_getResult(ADC_MEM0) - cal30) * (85 - 30))
/ (cal85 - cal30) + 30.0f;

tempF = tempC * 9.0f / 5.0f + 32.0f;
}*/
}
}

/* This interrupt happens every time a conversion has completed. Since the FPU
* is enabled in stacking mode, we are able to use the FPU safely to perform
* efficient floating point arithmetic.*/
void ADC14_IRQHandler(void)
{
uint64_t status;
uint32_t cal30, cal85;
uint16_t temp;
status = ADC14_getEnabledInterruptStatus();
ADC14_clearInterruptFlag(status);

if(status & ADC_INT0)
{
cal30 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF,
SYSCTL_30_DEGREES_C);
cal85 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF,
SYSCTL_85_DEGREES_C);


temp=ADC14_getResult(ADC_MEM0);

tempC = (float) (((uint32_t) ADC14_getResult(ADC_MEM0) - cal30) * (85 - 30))
/ (cal85 - cal30) + 30.0f;

tempF = tempC * 9.0f / 5.0f + 32.0f;
}

}

  • The formulas incorrectly initialize the ADC_MEM0 result and cal[30,85] variables as unsigned integers instead of signed, therefore since cal30 is greater than the ADC_MEM0 the subtraction results in an overflow instead of a negative number. To fix the issue, use int32_t in place of uint32_t. ADC_VREFPOS_INTBUF_VREFNEG_VSS should also be used in place of ADC_VREFPOS_AVCC_VREFNEG_VSS, I will submit these bugs to the DriverLib software team so that they can be fixed in later revisions.

    Edit: The bug has already been discovered internally and will be fixed.

    Regards,
    Ryan

  • Ryan,

    i replaced my code as mentioned in your mail but i am getting -56 c at the room temperature.

    /*
    * -------------------------------------------
    * MSP432 DriverLib - v3_21_00_05
    * -------------------------------------------
    *
    * --COPYRIGHT--,BSD,BSD
    * Copyright (c) 2016, 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.
    * --/COPYRIGHT--*/
    /*******************************************************************************
    * MSP432 ADC14 - Single Channel Repeat Temperature Sensor
    *
    * Description: This example shows the use of the internal temperature sensor.
    * A simple continuous ADC sample/conversion is set up with a software trigger.
    * The sample time is set to TBD as speced by the User's Guide. All calculations
    * take place in the ISR which take advantage of the Stacking Mode of the FPU.
    * The temperature is calculated in both Celsius and Fahrenheit.
    *
    * MSP432P401
    * ------------------
    * /|\| |
    * | | |
    * --|RST P5.5 |
    * | |
    * | |
    * | |
    *
    * Author: Timothy Logan
    ******************************************************************************/
    /* DriverLib Includes */
    #include "LibG2_main.h"
    volatile float tempC;
    volatile float tempF;
    int64_t status;
    //uint32_t cal30, cal85;
    //#define cal30 *((unsigned int *)0x002010DC) // Temperature Sensor Calibration-30 C
    // See device datasheet for TLV table memory mapping
    //#define cal85 *((unsigned int *)0x002010E0) // Temperature Sensor Calibration
    int main(void)
    {
    /* Halting WDT */
    WDT_A_holdTimer();

    /* Enabling the FPU with stacking enabled (for use within ISR) */
    FPU_enableModule();
    FPU_enableLazyStacking();

    /* Initializing ADC (MCLK/1/1) with temperature sensor routed */
    ADC14_enableModule();
    ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1,
    ADC_TEMPSENSEMAP);

    /* Configuring ADC Memory (ADC_MEM0 A22 (Temperature Sensor) in repeat
    * mode).
    */
    ADC14_configureSingleSampleMode(ADC_MEM0, true);
    ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_INTBUF_VREFNEG_VSS,
    ADC_INPUT_A22, false);

    /* Configuring the sample/hold time for TBD */
    ADC14_setSampleHoldTime(ADC_PULSE_WIDTH_192,ADC_PULSE_WIDTH_192);

    /* Enabling sample timer in auto iteration mode and interrupts*/
    ADC14_enableSampleTimer(ADC_AUTOMATIC_ITERATION);
    ADC14_enableInterrupt(ADC_INT0);

    /* Setting reference voltage to 2.5 and enabling temperature sensor */
    REF_A_setReferenceVoltage(REF_A_VREF2_5V);
    REF_A_enableReferenceVoltage();
    REF_A_enableTempSensor();

    /* Enabling Interrupts */
    Interrupt_enableInterrupt(INT_ADC14);
    Interrupt_enableMaster();

    /* Triggering the start of the sample */
    ADC14_enableConversion();
    ADC14_toggleConversionTrigger();

    /* Going to sleep */
    while (1)
    {
    /*status = ADC14_getEnabledInterruptStatus();
    ADC14_clearInterruptFlag(status);

    if(status & ADC_INT0)
    {
    cal30 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF,
    SYSCTL_30_DEGREES_C);
    cal85 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF,
    SYSCTL_85_DEGREES_C);

    tempC = (float) (((uint32_t) ADC14_getResult(ADC_MEM0) - cal30) * (85 - 30))
    / (cal85 - cal30) + 30.0f;

    tempF = tempC * 9.0f / 5.0f + 32.0f;
    }*/
    }
    }

    /* This interrupt happens every time a conversion has completed. Since the FPU
    * is enabled in stacking mode, we are able to use the FPU safely to perform
    * efficient floating point arithmetic.*/
    void ADC14_IRQHandler(void)
    {
    uint64_t status;
    //uint32_t cal30, cal85;
    int32_t cal30, cal85;
    uint16_t temp;
    status = ADC14_getEnabledInterruptStatus();
    ADC14_clearInterruptFlag(status);

    if(status & ADC_INT0)
    {
    cal30 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF,
    SYSCTL_30_DEGREES_C);
    cal85 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF,
    SYSCTL_85_DEGREES_C);

    temp=ADC14_getResult(ADC_MEM0);

    tempC = ((temp - cal30) * (85 - 30))/(cal85 - cal30) + 30.0;

    tempF = tempC* 9.0 / 5.0 + 32.0;
    }

    regards,

    praveen

     

  • void ADC14_IRQHandler(void)
    {
    uint64_t status;
    int32_t cal30, cal85;
    uint16_t temp;
    status = ADC14_getEnabledInterruptStatus();
    ADC14_clearInterruptFlag(status);

    if(status & ADC_INT0)
    {
    cal30 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF,
    SYSCTL_30_DEGREES_C);
    cal85 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF,
    SYSCTL_85_DEGREES_C);


    temp=ADC14_getResult(ADC_MEM0);

    tempC = (float) (((int32_t) ADC14_getResult(ADC_MEM0) - cal30) * (85 - 30))
    / (cal85 - cal30) + 30.0f;

    tempF = tempC * 9.0f / 5.0f + 32.0f;
    }

    }
  • At room temperature the value i get is 88.8 .

    /*
    * -------------------------------------------
    * MSP432 DriverLib - v3_21_00_05
    * -------------------------------------------
    *
    * --COPYRIGHT--,BSD,BSD
    * Copyright (c) 2016, 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.
    * --/COPYRIGHT--*/
    /*******************************************************************************
    * MSP432 ADC14 - Single Channel Repeat Temperature Sensor
    *
    * Description: This example shows the use of the internal temperature sensor.
    * A simple continuous ADC sample/conversion is set up with a software trigger.
    * The sample time is set to TBD as speced by the User's Guide. All calculations
    * take place in the ISR which take advantage of the Stacking Mode of the FPU.
    * The temperature is calculated in both Celsius and Fahrenheit.
    *
    * MSP432P401
    * ------------------
    * /|\| |
    * | | |
    * --|RST P5.5 |
    * | |
    * | |
    * | |
    *
    * Author: Timothy Logan
    ******************************************************************************/
    /* DriverLib Includes */
    #include "LibG2_main.h"
    volatile float tempC;
    volatile float tempF;
    int64_t status;
    //uint32_t cal30, cal85;
    //#define cal30 *((unsigned int *)0x002010DC) // Temperature Sensor Calibration-30 C
    // See device datasheet for TLV table memory mapping
    //#define cal85 *((unsigned int *)0x002010E0) // Temperature Sensor Calibration
    volatile int32_t temp;
    int main(void)
    {
    /* Halting WDT */
    WDT_A_holdTimer();

    /* Enabling the FPU with stacking enabled (for use within ISR) */
    FPU_enableModule();
    FPU_enableLazyStacking();

    /* Initializing ADC (MCLK/1/1) with temperature sensor routed */
    ADC14_enableModule();
    ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1,
    ADC_TEMPSENSEMAP);

    /* Configuring ADC Memory (ADC_MEM0 A22 (Temperature Sensor) in repeat
    * mode).
    */
    ADC14_configureSingleSampleMode(ADC_MEM0, true);
    ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_INTBUF_VREFNEG_VSS ,
    ADC_INPUT_A22, false);

    /* Configuring the sample/hold time for TBD */
    ADC14_setSampleHoldTime(ADC_PULSE_WIDTH_192,ADC_PULSE_WIDTH_192);

    /* Enabling sample timer in auto iteration mode and interrupts*/
    ADC14_enableSampleTimer(ADC_AUTOMATIC_ITERATION);
    ADC14_enableInterrupt(ADC_INT0);

    /* Setting reference voltage to 2.5 and enabling temperature sensor */
    REF_A_setReferenceVoltage(REF_A_VREF2_5V);
    REF_A_enableReferenceVoltage();
    REF_A_enableTempSensor();

    /* Enabling Interrupts */
    Interrupt_enableInterrupt(INT_ADC14);
    Interrupt_enableMaster();

    /* Triggering the start of the sample */
    ADC14_enableConversion();
    ADC14_toggleConversionTrigger();

    /* Going to sleep */
    while (1)
    {
    /*status = ADC14_getEnabledInterruptStatus();
    ADC14_clearInterruptFlag(status);

    if(status & ADC_INT0)
    {
    cal30 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF,
    SYSCTL_30_DEGREES_C);
    cal85 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF,
    SYSCTL_85_DEGREES_C);

    tempC = (float) (((uint32_t) ADC14_getResult(ADC_MEM0) - cal30) * (85 - 30))
    / (cal85 - cal30) + 30.0f;

    tempF = tempC * 9.0f / 5.0f + 32.0f;
    }*/
    }
    }

    /* This interrupt happens every time a conversion has completed. Since the FPU
    * is enabled in stacking mode, we are able to use the FPU safely to perform
    * efficient floating point arithmetic.*/
    void ADC14_IRQHandler(void)
    {
    uint64_t status;
    //uint32_t cal30, cal85;
    int32_t cal30, cal85;

    status = ADC14_getEnabledInterruptStatus();
    ADC14_clearInterruptFlag(status);

    if(status & ADC_INT0)
    {
    cal30 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF,
    SYSCTL_30_DEGREES_C);
    cal85 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF,
    SYSCTL_85_DEGREES_C);

    temp=ADC14_getResult(ADC_MEM0);

    //tempC = ((temp - cal30) * (85 - 30))/(cal85 - cal30) + 30.0f;
    //tempC= tempC+80;
    tempC = (float) (((int32_t) ADC14_getResult(ADC_MEM0) - cal30) * (85 - 30))
    /(cal85 - cal30) + 30.0f;
    tempF = tempC * 9.0f / 5.0f + 32.0f;
    }

    }

    regards 

    praveen

  • Glad to hear it, don't forget that the internal temperature sensor is measuring die temperature as compared to ambient and will therefore display temperatures of a few degrees warmer.

    Regards,
    Ryan

**Attention** This is a public forum