The picture shows the temperature in a display and in front the Thermistor. I'm using my new SPI-based display for this one, but it can obviously be used on SugarAddict's or other, or a character display such as this one (with code) on my blog.
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. Should also be pretty easy to make a MSP430-controlled heater by connecting this to a relay or transistor that handles the current. Maybe even adding a PID-controller.
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);










