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.

TI adc12 program

Other Parts Discussed in Thread: MSP430F169

Code:

#include <msp430.h>

#define ADCDeltaOn 12 // ~2 Deg C delta

static unsigned int FirstADCVal; // holds 1st ADC result

int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog
P1OUT = 0x00; // Clear P1
P1DIR = 0x01; // P1.0 as output
ADC12CTL1 = SHS_1 + SHP + CONSEQ_2; // TA trig., rpt conv.
ADC12MCTL0 = SREF_1 + INCH_10; // Channel A10, Vref+
ADC12IE = 0x01; // Enable ADC12IFG.0
ADC12CTL0 = SHT0_8 + REF2_5V + REFON + ADC12ON + ENC; // Config ADC12
TACCTL1 = OUTMOD_4; // Toggle on EQU1 (TAR = 0)
TACTL = TASSEL_2 + MC_2; // SMCLK, cont-mode
while (!(0x01 & ADC12IFG)); // First conversion?
FirstADCVal = ADC12MEM0; // Read out 1st ADC value
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}

#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
if (ADC12MEM0 <= FirstADCVal + ADCDeltaOn)
P1OUT &= ~0x01; // LED off
else P1OUT |= 0x01; // LED on
}

This is a TI example program..and i don't understand what "#define ADCDeltaOn 12 // ~2 Deg C delta" means.

Why 12? And what does this program try to do with the interrupt(if (ADC12MEM0 <= FirstADCVal + ADCDeltaOn)
P1OUT &= ~0x01; // LED off
else P1OUT |= 0x01; // LED on)?I don't understand.Please help!

  • Edward,

    What MSP430 are you using? Also, what is the name of the code example?

    From what the code above says, the value 12 is possibly an experimentally found (or estimated) value for a change of ~2 degrees Celsius. I am assuming this code example has something to do with a temperature sensor from that bit of code. I cannot be sure without knowing the exact code example and the application that it was meant to serve.

    In the interrupt, the 430 is just checking to see if the digitized value coming from the ADC has increased by the 12 that would be necessary to show a 2 degree increase. If the temperature has increased at least 2 degrees from the original sample, the LED will turn on, if not, the LED will turn off.

    Hopefully this helps to answer your questions.

  • It's MSP430F169 and the code name is fet140_adc12_03.c
    I understand now.Thank you very much!

**Attention** This is a public forum