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.

CCS/MSP430FR6989: ADC12 read analog input from LM35

Part Number: MSP430FR6989
Other Parts Discussed in Thread: LM35,

Tool/software: Code Composer Studio


Hello all,

I am trying to set up ADC12 to read data from a temperature sensor LM35. I have an interrupt that will gather the data and then i do my conversion once I get the info but it seems like it is not leaving the ISR once it is triggered.

I've looked everywhere and even compared my code to the example TI puts out for each MSP430 controller. I am new to programming these controllers beyond turning on the LEDs.

Below is my code. Any help would be appreciated.

#include <msp430fr6989.h>
#include <msp430.h>
#include <stdio.h>
//void Initialize_LCD();
//void display_num_lcd();
void ADC_SETUP();
#define redLED BIT0 // Red at P1.0

//Temperature sensor

 unsigned int temp;
volatile int IntDegF;
volatile int IntDegC;


/**
 * main.c
 */
int main(void)
{
    //---------------------------------------
    volatile unsigned int n;
    int x = 0;
    WDTCTL = WDTPW + WDTHOLD;              // stop watchdog timer

    PM5CTL0 &= ~LOCKLPM5;
    //=======================================
    P1DIR |= redLED; // Pins as output
    P1OUT &= ~redLED; // Red off
    
    P1SEL1 |= BIT3; // Select P1.3 for analog input
    P1SEL0 |= BIT3;




    ADC_SETUP();  // ADC set-up call function call



    ADC12CTL0 |= ADC12ENC;


    while(x==0)
    {

    ADC12CTL0 |= ADC12SC | ADC12ENC;                  //Start conversion software-trigger?
    _bis_SR_register(CPUOFF + GIE);        //Enables Low powered mode 0 and enables global interrupts after returning
    __no_operation();
                                           //From interrupt routine
                                           //CPUOFF = Low powered mode
                                           //GIE = General Interrupt Enable interrupts
    x++;
    }

    //conversion


    IntDegF =  temp * 1200 / 4095;
    IntDegF = IntDegF/10;                //IntDegF = (ADC_value * 1200 mV)/4095 * 1/10
                                         //Reference voltage is 1.2 or 1200 mV
                                         //2^12 - 1 = 4095 (ADC is 12 bits)
                                         //Gain or slope of LM35 is 10 mV / C
                                         //Rearrange the numbers and you get: 1200 mV / 10 mV per C = 1200

      P1OUT ^= redLED;

       



    return 0;


}

//Tell the compiler that the next
//Function is an ISR
//Code taken from examples

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12_ISR (void)
#else
#error Compiler not supported!
#endif
{
    switch(__even_in_range(ADC12IV, ADC12IV_ADC12RDYIFG))
    {
        case ADC12IV_NONE:        break;    // Vector  0:  No interrupt
        case ADC12IV_ADC12OVIFG:  break;    // Vector  2:  ADC12MEMx Overflow
        case ADC12IV_ADC12TOVIFG: break;    // Vector  4:  Conversion time overflow
        case ADC12IV_ADC12HIIFG:  break;    // Vector  6:  ADC12BHI
        case ADC12IV_ADC12LOIFG:  break;    // Vector  8:  ADC12BLO
        case ADC12IV_ADC12INIFG:  break;    // Vector 10:  ADC12BIN
        case ADC12IV_ADC12IFG0:             // Vector 12:  ADC12MEM0 Interrupt
             temp = ADC12MEM0;
                // Exit from LPM0 and continue executing main
                __bic_SR_register_on_exit(LPM4_bits);
            break;
        case ADC12IV_ADC12IFG1:   break;    // Vector 14:  ADC12MEM1
        case ADC12IV_ADC12IFG2:   break;    // Vector 16:  ADC12MEM2
        case ADC12IV_ADC12IFG3:   break;    // Vector 18:  ADC12MEM3
        case ADC12IV_ADC12IFG4:   break;    // Vector 20:  ADC12MEM4
        case ADC12IV_ADC12IFG5:   break;    // Vector 22:  ADC12MEM5
        case ADC12IV_ADC12IFG6:   break;    // Vector 24:  ADC12MEM6
        case ADC12IV_ADC12IFG7:   break;    // Vector 26:  ADC12MEM7
        case ADC12IV_ADC12IFG8:   break;    // Vector 28:  ADC12MEM8
        case ADC12IV_ADC12IFG9:   break;    // Vector 30:  ADC12MEM9
        case ADC12IV_ADC12IFG10:  break;    // Vector 32:  ADC12MEM10
        case ADC12IV_ADC12IFG11:  break;    // Vector 34:  ADC12MEM11
        case ADC12IV_ADC12IFG12:  break;    // Vector 36:  ADC12MEM12
        case ADC12IV_ADC12IFG13:  break;    // Vector 38:  ADC12MEM13
        case ADC12IV_ADC12IFG14:  break;    // Vector 40:  ADC12MEM14
        case ADC12IV_ADC12IFG15:  break;    // Vector 42:  ADC12MEM15
        case ADC12IV_ADC12IFG16:  break;    // Vector 44:  ADC12MEM16
        case ADC12IV_ADC12IFG17:  break;    // Vector 46:  ADC12MEM17
        case ADC12IV_ADC12IFG18:  break;    // Vector 48:  ADC12MEM18
        case ADC12IV_ADC12IFG19:  break;    // Vector 50:  ADC12MEM19
        case ADC12IV_ADC12IFG20:  break;    // Vector 52:  ADC12MEM20
        case ADC12IV_ADC12IFG21:  break;    // Vector 54:  ADC12MEM21
        case ADC12IV_ADC12IFG22:  break;    // Vector 56:  ADC12MEM22
        case ADC12IV_ADC12IFG23:  break;    // Vector 58:  ADC12MEM23
        case ADC12IV_ADC12IFG24:  break;    // Vector 60:  ADC12MEM24
        case ADC12IV_ADC12IFG25:  break;    // Vector 62:  ADC12MEM25
        case ADC12IV_ADC12IFG26:  break;    // Vector 64:  ADC12MEM26
        case ADC12IV_ADC12IFG27:  break;    // Vector 66:  ADC12MEM27
        case ADC12IV_ADC12IFG28:  break;    // Vector 68:  ADC12MEM28
        case ADC12IV_ADC12IFG29:  break;    // Vector 70:  ADC12MEM29
        case ADC12IV_ADC12IFG30:  break;    // Vector 72:  ADC12MEM30
        case ADC12IV_ADC12IFG31:  break;    // Vector 74:  ADC12MEM31
        case ADC12IV_ADC12RDYIFG: break;    // Vector 76:  ADC12RDY
        default: break;
    }

}


//**********************************************************

void ADC_SETUP(void)
{
    ADC12CTL0 &= ~ADC12ENC;                   // Disable ADC12
    ADC12CTL1 = ADC12VRSEL_1 +  ADC12INCH_3;              //Use SMCLK
    ADC12CTL1 |= ADC12SHP;
    ADC12CTL0 = ADC12SHT0_2 + ADC12ON;   //16 clock ticks sample and hold time, ADC on
    ADC12CTL2 |= ADC12RES_2;              // 12-bit conversion results
    //ADC12IER0 |= ADC12IE0 ;              //Interrupt enable register: 1 turns it on (P1.3?)
    ADC12IER0 = 0x001;
}

 

















  • Hi Juan,

    Why did you say that it is not leaving the ISR once it is triggered?

    I went through your code shortly but fond you were not create your code follow the example code TI. That said you didn't configure your ADC correctly, for example ADC channel by ADC12MCTL0.

    Please find the http://dev.ti.com/tirex/explore/node?devices=MSP430FR6989&node=ANBvOMxHUtbPUF.-qCyV6A__IOGqZri__LATEST example code for your reference.

  • I don't why my post came out like that. Haha, sorry new here.

    I thought i set ADC12 correctly from reading the manual. I'll take a look at your reference and see what I get. 

  • Okay, I saw the mistake. I corrected it. I reference the example code you linked. 

    I changed ADC12INCH_30 to ADC12Inch_3 since I am using Pin 1.3, this is A3 on pin 1.3. My guess is that this is channel 3 since I am not sure what channel to select.

    I also implemented the reference voltage code to 1.2 V. I thought the equation I had previously had taken care of it based on tutorials I read or saw online, not sure about this.

    Now I get an output from the sensor but it is not correct. Not sure where if my equation is correct or I still need to use the temperature sensor correction code from the example.

    Below is my revised code. Thanks for the help.

    #include <msp430fr6989.h>
    #include <msp430.h>
    #include <stdio.h>
    
    void ADC_SETUP();
    
    
    #define redLED BIT0 // Red at P1.0
    
    //Temperature sensor
    
     unsigned int temp;
    volatile unsigned int IntDegF;
    volatile unsigned int IntDegC;
    
    
    /**
     * main.c
     */
    int main(void)
    {
        //---------------------------------------
        volatile unsigned int n;
        int x = 0;
        WDTCTL = WDTPW + WDTHOLD;              // stop watchdog timer
    
        while(REFCTL0 & REFGENBUSY);              // If ref generator busy, WAIT
        REFCTL0 |= REFVSEL_0 + REFON;             // Enable internal 1.2V reference
    
        PM5CTL0 &= ~LOCKLPM5;
        //=======================================
        P1DIR |= redLED; // Pins as output
        P1OUT &= ~redLED; // Red off
    
        P1SEL1 |= BIT3; // Select P1.3 for analog input
        P1SEL0 |= BIT3;
    
    
    
    
        ADC_SETUP();  // ADC set-up call function call
        Initialize_LCD();
    
        while(!(REFCTL0 & REFGENRDY));            // Wait for reference generator
                                                    // to settle
        ADC12CTL0 |= ADC12ENC;
    
        //This can be put into a function
        while(x==0)
        {
    
        ADC12CTL0 |= ADC12SC;                  //Start conversion software-trigger
        _bis_SR_register(LPM0_bits + GIE);        //Enables Low powered mode 0 and enables global interrupts after returning
        __no_operation();
                                               //From interrupt routine
                                               //CPUOFF = Low powered mode
                                               //GIE = General Interrupt Enable interrupts
    
         IntDegF =  (temp * 1200)/4095;
         
        x++;
        }
                       //IntDegF = (ADC_value * 1200 mV)/4095 * 1/10
                      //Reference voltage is 1.2 or 1200 mV
                     //2^12 - 1 = 4095 (ADC is 12 bits)
                     //Gain or slope of LM35 is 10 mV / C
                    //Rearrange the numbers and you get: 1200 mV / 10 mV per C = 1200
    
            P1OUT ^= redLED;
    
        return 0;
    
    
    }
    
    //Tell the compiler that the next
    //Function is an ISR
    //Code taken from examples
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = ADC12_VECTOR
    __interrupt void ADC12_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
        switch(__even_in_range(ADC12IV, ADC12IV_ADC12RDYIFG))
        {
            case ADC12IV_NONE:        break;    // Vector  0:  No interrupt
            case ADC12IV_ADC12OVIFG:  break;    // Vector  2:  ADC12MEMx Overflow
            case ADC12IV_ADC12TOVIFG: break;    // Vector  4:  Conversion time overflow
            case ADC12IV_ADC12HIIFG:  break;    // Vector  6:  ADC12BHI
            case ADC12IV_ADC12LOIFG:  break;    // Vector  8:  ADC12BLO
            case ADC12IV_ADC12INIFG:  break;    // Vector 10:  ADC12BIN
            case ADC12IV_ADC12IFG0:             // Vector 12:  ADC12MEM0 Interrupt
                 temp = ADC12MEM0;
                    // Exit from LPM0 and continue executing main
                    __bic_SR_register_on_exit(LPM4_bits);
                break;
            case ADC12IV_ADC12IFG1:   break;    // Vector 14:  ADC12MEM1
            case ADC12IV_ADC12IFG2:   break;    // Vector 16:  ADC12MEM2
            case ADC12IV_ADC12IFG3:   break;    // Vector 18:  ADC12MEM3
            case ADC12IV_ADC12IFG4:   break;    // Vector 20:  ADC12MEM4
            case ADC12IV_ADC12IFG5:   break;    // Vector 22:  ADC12MEM5
            case ADC12IV_ADC12IFG6:   break;    // Vector 24:  ADC12MEM6
            case ADC12IV_ADC12IFG7:   break;    // Vector 26:  ADC12MEM7
            case ADC12IV_ADC12IFG8:   break;    // Vector 28:  ADC12MEM8
            case ADC12IV_ADC12IFG9:   break;    // Vector 30:  ADC12MEM9
            case ADC12IV_ADC12IFG10:  break;    // Vector 32:  ADC12MEM10
            case ADC12IV_ADC12IFG11:  break;    // Vector 34:  ADC12MEM11
            case ADC12IV_ADC12IFG12:  break;    // Vector 36:  ADC12MEM12
            case ADC12IV_ADC12IFG13:  break;    // Vector 38:  ADC12MEM13
            case ADC12IV_ADC12IFG14:  break;    // Vector 40:  ADC12MEM14
            case ADC12IV_ADC12IFG15:  break;    // Vector 42:  ADC12MEM15
            case ADC12IV_ADC12IFG16:  break;    // Vector 44:  ADC12MEM16
            case ADC12IV_ADC12IFG17:  break;    // Vector 46:  ADC12MEM17
            case ADC12IV_ADC12IFG18:  break;    // Vector 48:  ADC12MEM18
            case ADC12IV_ADC12IFG19:  break;    // Vector 50:  ADC12MEM19
            case ADC12IV_ADC12IFG20:  break;    // Vector 52:  ADC12MEM20
            case ADC12IV_ADC12IFG21:  break;    // Vector 54:  ADC12MEM21
            case ADC12IV_ADC12IFG22:  break;    // Vector 56:  ADC12MEM22
            case ADC12IV_ADC12IFG23:  break;    // Vector 58:  ADC12MEM23
            case ADC12IV_ADC12IFG24:  break;    // Vector 60:  ADC12MEM24
            case ADC12IV_ADC12IFG25:  break;    // Vector 62:  ADC12MEM25
            case ADC12IV_ADC12IFG26:  break;    // Vector 64:  ADC12MEM26
            case ADC12IV_ADC12IFG27:  break;    // Vector 66:  ADC12MEM27
            case ADC12IV_ADC12IFG28:  break;    // Vector 68:  ADC12MEM28
            case ADC12IV_ADC12IFG29:  break;    // Vector 70:  ADC12MEM29
            case ADC12IV_ADC12IFG30:  break;    // Vector 72:  ADC12MEM30
            case ADC12IV_ADC12IFG31:  break;    // Vector 74:  ADC12MEM31
            case ADC12IV_ADC12RDYIFG: break;    // Vector 76:  ADC12RDY
            default: break;
        }
    
    }
    
    
    //**********************************************************
    
    void ADC_SETUP(void)
    {
        ADC12CTL0 &= ~ADC12ENC;                   // Disable ADC12
        ADC12MCTL0 = ADC12VRSEL_1 + ADC12INCH_3;              //Use SMCLK
        ADC12CTL1 |= ADC12SHP;
        ADC12CTL0 = ADC12SHT0_2 + ADC12ON;   //16 clock ticks sample and hold time, ADC on
    
        //ADC12IER0 |= ADC12IE0 ;              //Interrupt enable register: 1 turns it on (P1.3?)
        ADC12IER0 = 0x001;
    }

  • Hi,

    could you share the more details about "I get an output from the sensor but it is not correct"?

    BTW, I find you were existing LPM4 instead of LPM0 in your  ADC12_ISR, even though you entered LPM0 in your main loop. 

  • I have the results displayed on the onboard LCD and the temperature keeps jumping around (Like 10 degrees from each other sometimes). It is not a stable number as I expected. Maybe it is the formula I have calculating IntDegC. 

    From the example you linked, do I need to add CALADC12_12V_30C as well? I was thinking it was only used when the onboard temperature sensor was going to be used. 

    I corrected the LMP0 in the ISR. 

    #include <msp430fr6989.h>
    #include <msp430.h>
    #include <stdio.h>
    
    #define CALADC12_12V_30C  *((unsigned int *)0x1A1A)   // Temperature Sensor Calibration-30 C
    
    void Initialize_LCD();
    void display_num_lcd();
    void ADC_SETUP();
    const unsigned char LCD_Num[10] = {0xFC, 0x60, 0xDB, 0xF3, 0x67, 0xB7, 0xBF, 0xE0, 0xFF, 0xE7 };
    #define greenLED BIT7
    #define redLED BIT0 // Red at P1.0
    
    //Temperature sensor
    
     unsigned int temp;
    volatile unsigned int IntDegF;
    volatile unsigned int IntDegC;
    
    
    /**
     * main.c
     */
    int main(void)
    {
        //---------------------------------------
        volatile unsigned int n;
        int x = 0;
        WDTCTL = WDTPW + WDTHOLD;              // stop watchdog timer
    
        while(REFCTL0 & REFGENBUSY);              // If ref generator busy, WAIT
        REFCTL0 |= REFVSEL_0 + REFON;             // Enable internal 1.2V reference
    
        PM5CTL0 &= ~LOCKLPM5;
        //=======================================
        P1DIR |= redLED; // Pins as output
        P1OUT &= ~redLED; // Red off
        P9DIR |= greenLED; // Pins as output
        P9OUT &= ~greenLED;
    
    
        P1SEL1 |= BIT3; // Select P1.3 for analog input
        P1SEL0 |= BIT3;
    
    
    
    
        ADC_SETUP();  // ADC set-up call function call
        Initialize_LCD();
    
        while(!(REFCTL0 & REFGENRDY));            // Wait for reference generator
                                                    // to settle
        ADC12CTL0 |= ADC12ENC;
    
        //This can be put into a function
        while(x==0)
        {
    
        ADC12CTL0 |= ADC12SC;                  //Start conversion software-trigger
        _bis_SR_register(LPM0_bits + GIE);        //Enables Low powered mode 0 and enables global interrupts after returning
        __no_operation();
                                               //From interrupt routine
                                               //CPUOFF = Low powered mode
                                               //GIE = General Interrupt Enable interrupts
    
         IntDegC = temp * ((1000.f/4096.f)/10.f); //NOT sure if this is correct 
    
         IntDegF = IntDegC * 9.0f / 5.0f + 32.0f;
         //IntDegF = IntDegF/10;
    
         __delay_cycles(1000000);
            P1OUT ^= redLED;
            display_num_lcd(IntDegF);                                //Rearrange the numbers and you get: 1200 mV / 10 mV per C = 1200
            __no_operation();
        //x++;
        }
                       //IntDegF = (ADC_value * 1200 mV)/4095 * 1/10
                                               //Reference voltage is 1.2 or 1200 mV
                                               //2^12 - 1 = 4095 (ADC is 12 bits)
                                               //Gain or slope of LM35 is 10 mV / C
    
    
    
    
        return 0;
    
    
    }
    
    //Tell the compiler that the next
    //Function is an ISR
    //Code taken from examples
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = ADC12_VECTOR
    __interrupt void ADC12_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
        switch(__even_in_range(ADC12IV, ADC12IV_ADC12RDYIFG))
        {
            case ADC12IV_NONE:        break;    // Vector  0:  No interrupt
            case ADC12IV_ADC12OVIFG:  break;    // Vector  2:  ADC12MEMx Overflow
            case ADC12IV_ADC12TOVIFG: break;    // Vector  4:  Conversion time overflow
            case ADC12IV_ADC12HIIFG:  break;    // Vector  6:  ADC12BHI
            case ADC12IV_ADC12LOIFG:  break;    // Vector  8:  ADC12BLO
            case ADC12IV_ADC12INIFG:  break;    // Vector 10:  ADC12BIN
            case ADC12IV_ADC12IFG0:             // Vector 12:  ADC12MEM0 Interrupt
                 temp = ADC12MEM0;
                 P9OUT ^= greenLED;
                    // Exit from LPM0 and continue executing main
                    __bic_SR_register_on_exit(LPM0_bits);
                break;
            case ADC12IV_ADC12IFG1:   break;    // Vector 14:  ADC12MEM1
            case ADC12IV_ADC12IFG2:   break;    // Vector 16:  ADC12MEM2
            case ADC12IV_ADC12IFG3:   break;    // Vector 18:  ADC12MEM3
            case ADC12IV_ADC12IFG4:   break;    // Vector 20:  ADC12MEM4
            case ADC12IV_ADC12IFG5:   break;    // Vector 22:  ADC12MEM5
            case ADC12IV_ADC12IFG6:   break;    // Vector 24:  ADC12MEM6
            case ADC12IV_ADC12IFG7:   break;    // Vector 26:  ADC12MEM7
            case ADC12IV_ADC12IFG8:   break;    // Vector 28:  ADC12MEM8
            case ADC12IV_ADC12IFG9:   break;    // Vector 30:  ADC12MEM9
            case ADC12IV_ADC12IFG10:  break;    // Vector 32:  ADC12MEM10
            case ADC12IV_ADC12IFG11:  break;    // Vector 34:  ADC12MEM11
            case ADC12IV_ADC12IFG12:  break;    // Vector 36:  ADC12MEM12
            case ADC12IV_ADC12IFG13:  break;    // Vector 38:  ADC12MEM13
            case ADC12IV_ADC12IFG14:  break;    // Vector 40:  ADC12MEM14
            case ADC12IV_ADC12IFG15:  break;    // Vector 42:  ADC12MEM15
            case ADC12IV_ADC12IFG16:  break;    // Vector 44:  ADC12MEM16
            case ADC12IV_ADC12IFG17:  break;    // Vector 46:  ADC12MEM17
            case ADC12IV_ADC12IFG18:  break;    // Vector 48:  ADC12MEM18
            case ADC12IV_ADC12IFG19:  break;    // Vector 50:  ADC12MEM19
            case ADC12IV_ADC12IFG20:  break;    // Vector 52:  ADC12MEM20
            case ADC12IV_ADC12IFG21:  break;    // Vector 54:  ADC12MEM21
            case ADC12IV_ADC12IFG22:  break;    // Vector 56:  ADC12MEM22
            case ADC12IV_ADC12IFG23:  break;    // Vector 58:  ADC12MEM23
            case ADC12IV_ADC12IFG24:  break;    // Vector 60:  ADC12MEM24
            case ADC12IV_ADC12IFG25:  break;    // Vector 62:  ADC12MEM25
            case ADC12IV_ADC12IFG26:  break;    // Vector 64:  ADC12MEM26
            case ADC12IV_ADC12IFG27:  break;    // Vector 66:  ADC12MEM27
            case ADC12IV_ADC12IFG28:  break;    // Vector 68:  ADC12MEM28
            case ADC12IV_ADC12IFG29:  break;    // Vector 70:  ADC12MEM29
            case ADC12IV_ADC12IFG30:  break;    // Vector 72:  ADC12MEM30
            case ADC12IV_ADC12IFG31:  break;    // Vector 74:  ADC12MEM31
            case ADC12IV_ADC12RDYIFG: break;    // Vector 76:  ADC12RDY
            default: break;
        }
    
    }
    
    
    //**********************************************************
    
    void ADC_SETUP(void)
    {
        ADC12CTL0 &= ~ADC12ENC;                   // Disable ADC12
        ADC12MCTL0 = ADC12VRSEL_1 + ADC12INCH_3;              //Use SMCLK
        ADC12CTL1 |= ADC12SHP;
        ADC12CTL0 = ADC12SHT0_2 + ADC12ON;   //16 clock ticks sample and hold time, ADC on
    
        //ADC12IER0 |= ADC12IE0 ;              //Interrupt enable register: 1 turns it on (P1.3?)
        ADC12IER0 = 0x001;
    
    
    }

  • Hi,

    The example is just showing you how to configure the ADC. You should implement the formula for the temperature sensor you are using.

  • Hello,

    I got ADC working and all, but the readings are fluctuating +-10 degrees from each other. It is not stable. I am not sure if I have the correct settings for the p1.3 pin. 

    Anyways, the formula I am using is this:

    IntDegC = temp * ((1200.f/4096.f)/10.f)

    IntDegF = (IntDegC * (9.0f / 5.0f)) + 32.0f;

    1200 is the reference voltage I am using (1.2 Volts) and 4096 is the 12 bit ADC.

    10 is coming from the datasheet of the LM35 which is 10 mv/C.

    Thanks for the help,

    J

  • Hi,

    You may need to scope the input voltage of ADC input, which should be the output of your temp sensor, and check if it is stable. If yes, the ADC conversion result should be stable. Otherwise, you should take a look at the LM35 for any issue.

  • I did notice something when I unplugged the output pin from the pin P1.3.

    When I run the code without any input, it still displays a number on the LCD screen. Is that something I should look into as well?

    I'll try to measure the output voltage from the temperature sensor this week and see if it is stable.

    Thank you for your help,

    J

  • Hi Juan,

    When I run the code without any input, it still displays a number on the LCD screen. Is that something I should look into as well?

    you should connect ADC input to a voltage not floating.

    Looking forward to your test result of the output voltage from the temp sensor.

  • Hi,

    you should connect ADC input to a voltage not floating.

     

    What do you mean? I should connect to the analog pin P1.3 with a stable voltage, correct?

    J

  • Hi,

    I did some tests on the temp sensor (I have several sensors, so I switched to make sure I did not measure a bad one). Below are the details of what I did. 

    • Connected 5 V pin from MSP to the input pin of temp sensor
    • Connected GND from temp sensor to GND on MSP
    • Measured the output from the temp sensor with a calibrator and got 2 mV output at room temperature

    What I observed was the voltage output was stable. 

    I'm not sure what is causing the readings to fluctuate but still displaying room temperature readings (70 - 75 degrees F). 

    I've looked over my code many times, and I'm not quite about the ADC initialization, specifically the voltage reference. I think I am selecting 1.2 V ? 

    Not sure. I'll keep debugging. 

    J

     

  • What I mean is that you shouldn't float the P1.3 for ADC input for testing with ADC.

  • Hi,

    What did you mean for "Connected 5 V pin from MSP to the input pin of temp sensor"? MSP430 device has no pin named 5 V.

    The MSP430FR6989 max supply voltage is 3.6V. But the min supply voltage of LM35 is 4V. How you connect the two devices?

  • Hi.

    The MSP430 FR6989 LaunchPad kit has a 5 Volt pin next to the 3.3 Volt pin. ( I measured the input voltage to the sensor and it read 5 volts).

    I also added a capacitor from the output pin of the sensor to the GND of the sensor. The temperature was stable (77 -76 degrees F).

    However, when I brought a hot object next to it, the temperature (F) decreased, vice versa. The capacitor I used is of an unknown value. I will test it with a 0.01 uF since I couldn't obtain a 0.1 uF capacitor from the lab. Will update soon. 

    Thank you,

    J

  • Hi,

    You can scope the input voltage of MSP430 ADC and compare with the conversion result of ADC to check if it convert a correct value.

  • Hello,

    What do you mean by scope input voltage? Like measure what the output of the sensor is and then calculate the ADC?

    Also, I'm not sure if this is related but ADC12MEM0 i get "Error: Cannot load from primitive location" when I pause the debug session.

    J,

  • Hi,

    What do you mean by scope input voltage? Like measure what the output of the sensor is and then calculate the ADC?

    Yes.

    You should directly check the Menu->View->Registers  in CCS for the register value when pause the debugging. If not, please share me more details about how you did. 

  • Hi,

    I get like 773 when I look at the variable temp from MEM0. When 5 volts is not connected to the sensor, I still get readings. I'm not sure what else to do.

    I also ordered more samples from TI since I got initial my sensors from Amazon.

    J,

  • Hi,

    After a long discussion, I would give you some summary about your question.

    1. you should make sure the sensor output voltage, which is ADC input voltage of MSP430, is correct for your test target. This is why I suggest you to measure the output of the sensor.

    2. Why are you using 1.2 reference voltage for ADC. Your input voltage shouldn't be higher than the ADC reference voltage. Or the conversion result will always be the highest value for ADC12MEMx.

    3. As discussed, the sensor you are using is a 5V powered device, which the output voltage should be up to 5V. But the MSP430 can only input voltage up to 3.6V. You should make sure the input voltage of MSP430 ADC input pin won't exceed the max value. Or the device may be damaged.

    4. For MSP430 ADC function, it is simple to compare the input voltage on A03, which you are using, and compare with ADC conversion result. It the conversion result matches the real input voltage, then your ADC part works well.

  • Hello,

    After a long discussion, I would give you some summary about your question.

    1. you should make sure the sensor output voltage, which is ADC input voltage of MSP430, is correct for your test target. This is why I suggest you to measure the output of the sensor.

    I understand now. I will test this out and let you know what happens.

    2. Why are you using 1.2 reference voltage for ADC. Your input voltage shouldn't be higher than the ADC reference voltage. Or the conversion result will always be the highest value for ADC12MEMx.

    Okay, what do you suggest to use? The sample you linked me had it and the available internal reference voltages are 1.2 , 2, and 2.5 Volts.  I'm thinking of adding a resister and drop the voltage? Not sure.

    3. As discussed, the sensor you are using is a 5V powered device, which the output voltage should be up to 5V. But the MSP430 can only input voltage up to 3.6V. You should make sure the input voltage of MSP430 ADC input pin won't exceed the max value. Or the device may be damaged.

    Okay, I'm thinking of adding a resistor from the output of the sensor to the input of A03 to drop the voltage. is this the correct approach? 

    4. For MSP430 ADC function, it is simple to compare the input voltage on A03, which you are using, and compare with ADC conversion result. It the conversion result matches the real input voltage, then your ADC part works well.

    Sounds good. Will try this and let you know the results. 

  • 2. the ADC12 reference voltage could be configured for various of voltage, including but not limited to 1.2 , 2, and 2.5 Volts, which could be find for the register description of  ADC12VRSEL in Table 34-9 of device User's Guide.  A resistance voltage divider to drop the voltage could be work for you. Just make sure the input voltage of ADC not be higher than the ADC reference voltage.

**Attention** This is a public forum