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.

ADC temperature sensor

Other Parts Discussed in Thread: MSP430G2553

Hi,

     I am currently working with MSP430G2553's internal Temperature Sensor. The sample code for ADC has the below given configuration.

ADC10CTL1 = INCH_10 + ADC10DIV_3; 
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE;

The formula used to calculate temperature in Celsius and Fahrenheit is given as

// oF = ((A10/1024)*1500mV)-923mV)*1/1.97mV = A10*761/1024 - 468

temp = ADC10MEM;
IntDegF = ((temp - 630) * 761) / 1024;

// oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278
temp = ADC10MEM;
IntDegC = ((temp - 673) * 423) / 1024;

Can anybody help me out with the above formula explanation for the given ADC configuration...

Thanks in advance....

  • Rohini,

    please specify your question a little bit more - I don't know what you are asking for. Don't you understand the formula in general or what is the problem? Doesn't it work as expected?

    Dennis
  • I got the expected output. But I didn't understand the formula. How can it be derived or is it the general formula for calculating the temperature sensor value from ADC output.

    // oF = ((A10/1024)*1500mV)-923mV)*1/1.97mV = A10*761/1024 - 468

    temp = ADC10MEM;
    IntDegF = ((temp - 630) * 761) / 1024;

    // oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278
    temp = ADC10MEM;
    IntDegC = ((temp - 673) * 423) / 1024;

    what is the need for 1500mv, 923mv,1.97mv, in DegF calculation,
    and 986mv, 1.97mv,3.55mv in DegC calculation.
  • >what is the need for 1500mv, 923mv,1.97mv, in DegF calculation,
    >and 986mv, 1.97mv,3.55mv in DegC calculation.

    Considering you know how DAC works, then all you shall learn is chapter "23.2.7 Using the Integrated Temperature Sensor" of msp430g2553 user guide (SLAU144). First thing you would want to do - see the temperature transfer function graph (Figure 23-10). Then perhaps everything about those seemingly strange calculations becomes clear.
  • Indeed, this calculation is a little bit weird, but it saves processing steps.

    For °C:

    The 1500mV is the ADC's reference voltage, the 986mV is the offset of the temperature sensor and the 3.55mV is the gain per °C of the sensor.

    Look at the user's guide, page 550:

    The long way for calculating the temperature is the following one...

    The voltage of the sensor is the measured ADC value multiplied by the reference voltage and divided by your maximum resolution:

    V_sensor = (ADC_value * 1500mV) / 1023

    Now the sensor has an offset of 986mV, so you can subtract this value from the measured voltage, giving you the signal voltage:

    V_signal = V_sensor - 986

    Now you know that the sensor has 3.55mV/°C gain, so dividing the signal voltage by this gain will give you the temperature:

    T = V_signal / 3.55

    The complete formula would be

    T = (((ADC_value * 1500mV) / 1023) - 986) / 3.55

    This is quite complex and it would deal with floating point numbers - you don't want that on such a small processor for such a simple task. You could multiply all the values to get rid of the decimals, but you can also "pre-calculate" some numbers - that means:

    You can first subtract the ADC value for the offset. This can easily be calculated by

    N_offset = (986 * 1023) / 1500 = 672

    This value can be subtracted directly from each ADC sample, giving you the resulting counts for the signal

    N_signal = ADC_value - 672

    The N_signal must now be converted into signal voltage again to divide it by the gain of 3.55mV/°C - V_signal first:

    V_signal = (N_signal * V_ref) / 1023 = (N_signal * 1500) / 1023

    Now to get the temperature you have to divide this value by 3.55:

    T = V_signal / 3.55 = (N_signal * 1500) / 1023) / 3.55 = (N_signal * 1500) / 1023) * (1 / 3.55)

    If you rearrange the formula, you can also write:

    T = N_signal * 1500 * (1 / 1023) * (1 / 3.55)

    T = N_signal * [1500 * (1 / 3.55)] * (1 / 1023)

    T = N_signal * 423 * (1 / 1023)

    T = (N_signal * 423) / 1023

    And since we know that N_signal = ADC_value - 672 we can write:

    T = ((ADC_value - 672) * 423) / 1023

    That's it. But I agree that it is not very easy to see at first sight

    Dennis

  • When calculating with 1024 instead of 1023, you can improve this calculation further by writing

    T = ((ADC_value - 672) * 423) >> 10

    since a bit shift is a very fast operation. And 1023 or 1024 does not make a huge difference. But when optimizations of the compiler are enabled, a division by 1024 should automatically be replaced by this bit shift.


    Dennis

**Attention** This is a public forum