MSP430 USB Stick Development Tool Program #1

(If you find this page, you can use this Software. I'd appreciate it if you let me know.)

Back to MSP430 USB Stick Development Tool Page

Blinking Thermometer is a program that can turn the off-the-shelf EZ430 Development stick into something that might almost be considered useful without any modifications.

There are a few constants that might be interesting to play with.

The ADCSlope is 34 meaning that the ADC puts out a count that changes by 34 when the temperature changes by 1 Degree F. I determined this constant based on the value from the TI authors. The TI authors said 31 was approximately 0.5 degrees C. I'm sure if you looked at how the ADC is setup you could derive this value.

The ADCOffset was determined by knowing the temp, setting a breakpoint, and seeing what the value that was returned in LastADCVal. Your device might have a different offset.

RestartDelay determines how many interrupt service calls are performed before starting the whole thing over. Each interrupt service period is about 128 msec's.

//******************************************************************************
//  MSP430F20x3 Demo - SD16, Using the Integrated Temperature Sensor
//
//  Description: Use SD16 and it's integrated temperature sensor to detect
//  temperature.  Blink LED to represent temp.
//
// By B. L. Wiscons May 2007 based on example by
//  M. Buccini / L. Westlund
//  Texas Instruments Inc.
//  October 2005
//  Built with IAR Embedded Workbench Version: 3.42A
//******************************************************************************
#include  <msp430x20x3.h>

#define ADCSlope 34                         // ~1.0 Deg F delta
#define ADCOffset 51574                     // ADC Reading at 0 Deg F
#define RestartDelay 0                      // number of interrupt service's
                                            //   before restarting the whole 
                                            //   thing over
static unsigned int LastADCVal;             // holds ADC temperature result
static unsigned int TempDegF;               // Held (and decremented) temperature result
static unsigned int intcnt;                 // interupt counter

void main(void)
{
  intcnt=0;
  BCSCTL2 |= DIVS_2;                        // SMCLK/4
  WDTCTL = WDT_MDLY_32;                     // WDT Timer interval
  IE1 |= WDTIE;                             // Enable WDT interrupt
  P1DIR |= 0x01;                            // P1.0 to output direction
  SD16CTL = SD16REFON +SD16SSEL_1;          // 1.2V ref, SMCLK
  SD16INCTL0 = SD16INCH_6;                  // A6+/-
  SD16CCTL0 = SD16SNGL + SD16IE ;           // Single conv, interrupt
  _BIS_SR(LPM0_bits + GIE);                 // Enter LPM0 with interrupt
}

#pragma vector=SD16_VECTOR
__interrupt void SD16ISR(void)
{
LastADCVal = SD16MEM0;                    // Store value
}

// Watchdog Timer interrupt service routine
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void)
{
intcnt++;
switch (intcnt)
  {
// case 1-6 blinks out the "Starting" pattern of 3 quick blinks
//  case 1 also kicks off a conversion
  case 1:
    {
    P1OUT |= 0x01;                          // LED on  
    SD16CCTL0 |= SD16SC;                    // Start SD16 conversion
    break;
    }
  case 2:
  case 3:
  case 4:
  case 5:
  case 6:
    {
    P1OUT ^= 0x01;                          // LED toggle  
    break;
    }
// case 7 takes whatever the last temperature reading from the interrupt
//  routine and converts it to an integer representing Degrees F.
//  I determined the two constants by experimentation with some guidance
//  from the TI program
  case 7:
    {
    TempDegF=(LastADCVal-ADCOffset)/ADCSlope;
    if (TempDegF >= 100)
      TempDegF = 99;
    break;
    }
//case 16-67 blinks out the ten's digit of the temp
  case 16:
  case 22:
  case 28:
  case 34:
  case 40:
  case 46:
  case 52:
  case 58:
  case 64:
    {
    if (TempDegF >= 10)
      {P1OUT |= 0x01;                          // LED on  
      TempDegF=TempDegF-10;
      }
    else
      intcnt = 90-12;
    break;
    }
  case 19:
  case 25:
  case 31:
  case 37:
  case 43:
  case 49:
  case 55:
  case 61:
  case 67:
    {
    P1OUT &= ~0x01;                         // LED off
    break;
    }
//before starting to blink out the unit's digit, make an adjustment
// so 0 gives ten blinks.
  case 89:
    {
    if (TempDegF==0)
      TempDegF=10;
    break;
    }
//case 90-147 blinks out the units's digit of the temp
  case 90:
  case 96:
  case 102:
  case 108:
  case 114:
  case 120:
  case 126:
  case 132:
  case 138:
  case 144:
    {
    if (TempDegF >= 1)
      {
      P1OUT |= 0x01;                          // LED on  
      TempDegF=TempDegF-1;
      }
    else intcnt=148;
    break;
    }
  case 93:
  case 99:
  case 105:
  case 111:
  case 117:
  case 123:
  case 129:
  case 135:
  case 141:
  case 147:
    {
    P1OUT &= ~0x01;                         // LED off
    break;
    }
  default:
    if (intcnt>=(160+RestartDelay))
      intcnt=0;                            // start the whole thing over

  }     //end of switch  
}       //end of interrupt routine