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.

msp430f2013, modified example code for SD conversion

TI provide a code sample to read channel 6, the internal temperature sensor.

I've modified the code so you can see the actual temperature. My additions are marked by the comment // DH

 

#include  <msp430x20x3.h>

#define ADCDeltaOn 31                       // ~0.5 Deg C delta
static unsigned int LastADCVal;         // holds ADC temperature result

void main(void)
{
  BCSCTL2 |= DIVS_3;                        // SMCLK/8
  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 + SD16DF;   // DH
  _BIS_SR(LPM0_bits + GIE);                 // Enter LPM0 with interrupt
}

float temp; // DH
#pragma vector=SD16_VECTOR
__interrupt void SD16ISR(void)
{
  if (SD16MEM0 <= LastADCVal + ADCDeltaOn)
    P1OUT &= ~0x01;                         // LED off
  else
    P1OUT |= 0x01;                          // LED on
  LastADCVal = SD16MEM0;                    // Store value
  temp = (LastADCVal / 65535.0F) * 1200.0F; // DH convert to mV
  temp /= 1.32F;   // DH convert to K - see datasheet SD16_A
  temp -= 273.15F; // DH convert to C
}

// Watchdog Timer interrupt service routine
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void)
{
  SD16CCTL0 |= SD16SC;                      // Start SD16 conversion
}

  • Thanks for sharing this.

    I only hope that people will use the search function and find this rather than asking for such a solution in new threads.

    However, using integer fixed-point arithmetic instead of floating point operations wor the claculations would be a big increase in speed/efficiency and decrease program size.

**Attention** This is a public forum