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.

CCS/MSP430FR4133: Calculation problem

Part Number: MSP430FR4133


Tool/software: Code Composer Studio

Hi team,

I want to calculate temperature by using MSP430.

But I couldn't get correct result.

please give me some advice.

following is my code.

            percentage=ADC_getResults(ADC_BASE)/0x3FF;
            volt=1500.0*percentage;
            temperature=CalcTemp(volt,2);
            showTemp(temperature);
            //Clear CPUOFF bit from 0(SR)
            //Breakpoint here and watch ADC_Result
            __bic_SR_register_on_exit(CPUOFF);

            break;
        default: break;
    }
}

#ifdef __MSP430_HAS_TBx__
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER0_B0_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrup
        t(TIMER0_B0_VECTOR)))
#endif
void TB0_ISR (void)
{
      TB0CTL = 0;
      LPM0_EXIT;                                // Exit LPM0 on return
}
#else
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER0_A0_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(TIMER0_A0_VECTOR)))
#endif
void TA0_ISR (void)
{
      TA0CTL = 0;
      LPM0_EXIT;                                // Exit LPM0 on return
}
#endif // __MSP430_HAS_TBx__

double CalcTemp(double volt,int mode){
    switch(mode){
    case 1: return -0.193*volt+212.009;
    case 2: return -0.000007857923*volt*volt-0.1777501*volt+204.6398;
    case 3: return -8.451576E-6*volt*volt-1.769281*volt+204.3937;
    case 4: return -1.809628E-9*volt*volt*volt-3.325395E-6*volt*volt-0.1814103*volt+205.5894;
    //case 5: return -1.064200E-9*volt*volt*volt-5.759725E-6*volt*volt-0.1789883E*volt+204.8570;
    }
    //break;
}



void showTemp(double temperature){
    if (temperature>=1)
                   {
                       if (temperature>=100) showChar(((uint32_t) temperature/100)%10 + '0',pos3);
                       if (temperature>=10) showChar(((uint32_t) temperature/10)%10 + '0',pos4);
                       if (temperature>=1) showChar(((uint32_t) temperature/1)%10 + '0',pos5);
                   }
                   else
                   {
                       LCDMEM[pos1] |= 0x01;
                       if (temperature<=-100) showChar(((uint32_t) (400-(400+temperature))/100)%10 + '0',pos3);
                       if (temperature<=-10) showChar(((uint32_t) (400-(400+temperature))/10)%10 + '0',pos4);
                       if (temperature<1) showChar(((uint32_t) (400-(400+temperature))/1)%10 + '0',pos5);
                   }
                   LCDMEM[pos4+1] |= 0x01; // Decimal point
                   LCDMEM[pos5+1] |= 0x04; // Degree symbol
                   showChar('C',pos6);
}

  • > percentage=ADC_getResults(ADC_BASE)/0x3FF;

    This result will be 0 (or maybe 1), since getResults will return an "int" less than 1024. Try:

    > percentage=ADC_getResults(ADC_BASE)/1024.0;

    [Edit: I'm supposing "percentage" is declared "double". If not, you should fix that too.]

**Attention** This is a public forum