The value line series (g series) chips that come with the MSP430 Launchpad are pretty cool and has almost all the required peripherals to work with..The best on is ( for those with the newer version v1.5 or later, that comes with pre-soldered Male headers ) MSP430G2553, It has pretty much everything to get you started. Since, I was a little curious i bought the MSP430 launchpad quite a while back..Mine came with a g2231 and g2211..Of which G2231 is the one that has an ADC. The MSP430 boasts of an internal temperature sensor which is probably new to me who has worked earlier on AVR. So, I went on and tested the ” <Accuracy>”  of the sensor.

For you to proceed you need to have this (user`s guide) and refer the pages 559-564.

post1

So setting the bits in the INCHx to 0b1010 (i.e 10 in decimal) the MSP430 allows us to use its internal temperature sensor.

We have chosen the reference voltage to be 1.5V in order to have an ADC Value that is more or less immune to the Voltage Fluctuations.

The code is as follows:

#include<msp430g2231.h>
void tempInit()
{
	ADC10CTL0=SREF_1 + REFON + ADC10ON + ADC10SHT_3 ; //1.5V ref,Ref on,64 clocks for sample
	ADC10CTL1=INCH_10+ ADC10DIV_3; //temp sensor is at 10 and clock/4
}
int tempOut()
{
	int t=0;
	__delay_cycles(1000);              //wait 4 ref to settle
	ADC10CTL0 |= ENC + ADC10SC;      //enable conversion and start conversion
	while(ADC10CTL1 & BUSY);         //wait..i am converting..pum..pum..
	t=ADC10MEM;                       //store val in t
	ADC10CTL0&=~ENC;                     //disable adc conv
	return(int) ((t * 27069L - 18169625L) >> 16); //convert and pass
}
void main(void)
{   volatile int temp;    //initialise
	WDTCTL = WDTPW + WDTHOLD; //stop..bow..boww
	temp=0;
	tempInit();//initialise adc
	while(1)
	{
		__delay_cycles(500); //wait and set break point
		temp=tempOut();           //read temp
		__delay_cycles(500);  //wait and set breakpoint

	}
}

Code is under this licence .  😀

So, when you flash this code using CCS the breakpoints need to be set(Not compulsory et`all). What breakpoints really do is that it stops the program there and allows you to see the value of the watch expression and then when you press the pause/play button again..it will run until the next breakpoint..Its a pretty cool feature..and many use it to analyse code behavior.

This is how you set a breakpoint in the CCS-Edit window:

post2

Just click on the bar next to the line number bar..(Currently highlighted in blue).

These are the results you get by setting the “Watch Expression” to the Temp variable..

post3

The temperature it reads is 23 Degrees Celsius..while my room temperature measured by a standard thermometer is  20 Degrees. which is a relative error of 15%. So, scientifically that`s not accurate..but i dont think that is what it is designed for..I think it is designed for just to give an “Idea” of what the temperature is about..So we can see if we are getting colder or hotter.

The code is pretty well commented and i find it self-explanatory..But still if you have any query ..I am just a “Comment” away!

You can also find the complete CCS project in this repo on github!

Cheers and Greetings!

Indian Tinker!

18 thoughts on “Tutorial: Using the Internal Temperature Sensor on a MSP430

  1. Thanks! This will be very helpful for me 🙂 It’s actually about 1% error if you’re measuring the temperature in Kelvin! Maybe the chip is a bit warmer because of its power dissipation.

  2. Hi,

    How did you figure out this euqation?
    return(int) ((t * 27069L – 18169625L) >> 16);

    I tried to look into datasheet, but it says different equation.

    Thanks and its a great tutorial.

  3. Hello
    I am trying to light a led if the value for temp() rises above a given value, for example 32,
    where would you place the command to do such thing?

    • I’m sorry if I’m being a big hazzle, but when I remove the breakpoints I can get it to run continuously but it no longer displays the temperature. Is there any way you can send me the slight variation in an email? Sorry I’m new to this and still trying to figure it out.

      • It wont display the temperature in Run time. The code is the same. You can find the stop button on the Eclipse GUI to stop the code at any moment and then watch the variable

  4. Hello Sir,
    Thank you so much – it is really helpful

    I had a question,
    I want to attach an temperature sensor to the 1st pin, and before that I need to set a voltage limit to 3V.
    Can you tell me how do I set voltage limit?

    • Hi,
      Glad you like it.
      MSP430 has two internal voltage thresholds at 1.5V and 2.5V. This will saturate the output of ADC to these levels. So, if Voltage at ADC pin is any greater than 2.5 V it will show the maximum ADC reading.

      There is no 3V reference.

Leave a comment