Thermistor based thermometer for MSP430

I’ve made some MSP430 code for a high-temperature capable thermometer, by adapting the code from Reprap. The code uses the B57560G104F thermistor that can measure temperatures up to 300 Degrees C. As a display I suggest you buy the display I’m showing below (will soon be available to buy) or for example this character-display from Farnell.

The picture shows the temperature in a display and in front the Thermistor. These are really tiny glass beads that can handle high temperatures, but be careful with how you mount it.

The circuit is basically

Vcc — 10K resistor — P1.2 — Thermistor — 0V

It’s also good to place a 1uF capacitor across the thermistor to remove noise.

IAR MSP430 code is below. It can easily be adapted to CCS or MSPGCC.

thermistor.c:

/*
* Inspired by http://reprap.org/wiki/Temperature_Sensor_1_0
* No license info from that page, but some may claim it's GPL.
* Not sure if that is relevant for such a short code snippet.
*/

#include
#include "thermistor.h"

// Thermistor B57560G104F http://uk.farnell.com/epcos/b57560g104f/thermistor-ntc/dp/3878697?Ntt=3878697

// r0: 100000
// t0: 25
// r1: 0
// r2: 10000
// beta: 4036
// max adc: 1023
#define NUMTEMPS 20
int temptable[NUMTEMPS][2] = {
   {1, 664}, // 664.64106912 C
   {54, 210}, // 210.439979582 C
   {107, 171}, // 171.052478604 C
   {160, 149}, // 149.564016786 C
   {213, 134}, // 134.640069513 C
   {266, 123}, // 123.039739982 C
   {319, 113}, // 113.394921511 C
   {372, 104}, // 104.997832544 C
   {425, 97}, // 97.4294169841 C
   {478, 90}, // 90.4137427983 C
   {531, 83}, // 83.7503688927 C
   {584, 77}, // 77.2777873564 C
   {637, 70}, // 70.8496463885 C
   {690, 64}, // 64.314518844 C
   {743, 57}, // 57.4917052426 C
   {796, 50}, // 50.1314173911 C
   {849, 41}, // 41.8303323287 C
   {902, 31}, // 31.8031759831 C
   {955, 18}, // 18.0092465547 C
   {995, 0} // 0.112666936696 C
};

void initThermistor()
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  ADC10CTL1 = INCH_2;             // Conversion code singed format, input A1
  ADC10AE0 |= BIT2;                         // P1.2 ADC option select
  ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; // ADC10ON, interrupt enabled
}

int rawValueThermistor()
{
    ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion start
    __bis_SR_register(CPUOFF + GIE);        // LPM0, ADC10_ISR will force exit
    return ADC10MEM;
}

int readTemp()
{
   int rawtemp = rawValueThermistor();
   int current_celsius = 0;

   int i = 0;
   for (i=1;i < NUMTEMPS;i++)    {       if (temptable[i][0] > rawtemp)
      {
         int realtemp  = temptable[i-1][1] + (rawtemp - temptable[i-1][0]) * (temptable[i][1] - temptable[i-1][1]) / (temptable[i][0] - temptable[i-1][0]);

         if (realtemp > 255)
            realtemp = 255; 

         current_celsius = realtemp;

         break;
      }
   }

   // Overflow: We just clamp to 0 degrees celsius
   if (i == NUMTEMPS)  {
      current_celsius = 1000;
   }

   return current_celsius;
}

#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
  __bic_SR_register_on_exit(CPUOFF);        // Clear CPUOFF bit from 0(SR)
}

thermistor.h

void initThermistor();
int rawValueThermistor(void);
int readTemp(void);

One thought on “Thermistor based thermometer for MSP430”

  1. I actually saw this posted on the 43oh forums> I posted this question there, but I’m not sure if you still frequent that so…

    Your code looks like what I am looking for, but I am trying to adapt this to an Ametherm nt03 50169 thermistor ( http://www.ametherm.com/datasheetspdf/NT03%2050169.pdf ).

    I see on the datasheet for your thermistor where you get the values for r0, t0 and beta but I’m not sure about the r1, r2 and max adc. Also, going on your datasheet, I can’t figure out how you built the look up table. Maybe you could explain it… kinda of Thermistor Look-up Tables for Dummies 🙂

    Thanks…

Leave a Reply

Your email address will not be published. Required fields are marked *