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.

MSP430G2553: Internal temperature sensor

Part Number: MSP430G2553

Hi all,

I've found an example for the internal temperature sensor and it works just fine. the problem starts when I'm trying to use this code along side with other ADCs channel. meaning, I have to other channels that being used and all of the different in the settings is the ADC10SHT_3 of ADC10CTL0. in the other channels I use ADC10SHT_2. When Sampling and conversion is enabled in the other channels, the numbers of the temperature measurement is NOT OK and there's no changing at the output of the ADC under different temperatures. I did gave the ADC 30us and more to be accurate but still not good.

I believe that  something is different with the internal temperature, I just don't know what.

pls help.

10X a lot

  • Hi Yehuda,

    Can you please provide a minimal set of code that reproduces the issue with a description of the changes you're making in the comments?

    Best regards,
    Caleb Overbay
  • Yes, of course.

    Function 1: 

    long VBAT_SAMPLE()
    {
    long voltage = 0;
    const int num_of_samp = 3;
    int i;
    long actual_voltage;
    /*now that we have two function with ADC we need to change the channel at the entry of each function.*/

    ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;// + REF2_5V;

    ADC10CTL1 = INCH_0; // input A0
    ADC10AE0 |= 0x01; // PA.0 ADC option select
    for(i = 0; i< num_of_samp; i++)
    {
    ADC10CTL0 |= ENC | ADC10SC; // Sampling and conversion start
    delay(1);
    voltage += ADC10MEM;
    }
    voltage = voltage/num_of_samp;
    actual_voltage = 4000 - (int)(((890-voltage)/2)*10)+130; //890 is the value for 4.0V and we get a drop of about 22 every 100mV. the return of this function is in mV.

    int j;
    if(!(P1IN & CAP_INT.BIT))
    {
    if((actual_voltage<VOLTAGE_THRESHOLD) && (actual_voltage > 2000))
    {
    UNSET_HEATER();
    for(j=0;j<LED_NUM;j++)
    ControlLED(LEDS[j],ON); // turn on all LEDs
    Buzzer(500); //activate the buzzer for 4000 milliseconds
    for(j=0;j<LED_NUM;j++)
    ControlLED(LEDS[j],OFF); // turn off all LEDs
    LOW_VOLTAGE_FLAG = TRUE; //Set this flag to one so the system will know that the voltage has dropped.

    Mc = Mc + Mt/10;
    Mt = 0;

    STATUS = STATUS_LPM3; //go to LPM3 to save power and also for start counting VD timer.
    }
    else
    {
    //LOW_VOLTAGE_FLAG = FALSE;
    }
    }
    return actual_voltage;
    ADC10CTL0 &= ~ENC;
    ADC10CTL0 &= ~ADC10SC;
    }

    Function 2:

    int SAMPLE_LIGHT_SENSOR() // sample the light sensor and return the sampled value. The calculated value is a numerical value representative of the amount of light sensed but is unitless
    {
    long sample = 0;
    static long z = 0;
    int i;
    int sample_avg_num = 10;
    int us;
    //static long CAL_V15;
    ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;
    ADC10CTL1 = INCH_5; // input A1
    ADC10AE0 |= 0x20; // PA.5 ADC option select
    for(i=0;i<sample_avg_num;i++)
    {
    ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
    us=22; //wait for _____ so the sample will be accurate
    while (us)
    {
    __delay_cycles(1); //990 for 1MHz
    us--;
    }
    sample += ADC10MEM;
    z = ADC10MEM;
    }
    sample = sample/sample_avg_num;
    sample = (sample*(((long)(*CAL_15V)*100)/32768))/100; // dividing by 2^15 as defined in the datasheet for using the calibration values of the ADC

    #ifndef DEBUG
    return sample;
    #else
    return vr_debug;//260;
    #endif
    ADC10CTL0 &= ~ENC;
    ADC10CTL0 &= ~ADC10SC;
    }

    Function 3: (with internal temperature sensor)

    int Temperature_measuring()
    {
    //WDTCTL = WDTPW | WDTHOLD; // Stop WDT
    long temp;
    int num_of_sample = 5;
    int i;
    int us=300; //wait for _____ so the sample will be accurate

    ADC10CTL1 = INCH_10 | ADC10DIV_3; // Temp Sensor ADC10CLK/4
    ADC10CTL0 = SREF_1 | ADC10SHT_2 | REFON | ADC10ON | ADC10IE;
    ADC10CTL0 |= ENC | ADC10SC; // Sampling and conversion start
    for(i = 0; i < num_of_sample; i++)
    {
    us=300;
    while (us)
    {
    __delay_cycles(1); //990 for 1MHz
    us--;
    }
    temp = temp + ADC10MEM;
    }
    temp = temp/num_of_sample;
    //IntDegC1= (long)(*CAL_TEMP_15V_30C);
    //IntDegC2= (long)(*CAL_TEMP_15V_85C);
    //IntDegC4 = (temp - IntDegC1)*(55/(IntDegC2 - IntDegC1))+30;
    ADC10CTL0 &= ~ENC;
    ADC10CTL0 &= ~ADC10SC;
    return (temp);
    }

    The problem occurs only if the “ADC10CTL0 |= ENC + ADC10SC” is used in function 1 and 2. If I put this line under comment in functions 1 and two, the output of the temperature function is OK.

  • Solved it. it was the order of writing to the registers.

**Attention** This is a public forum