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.

MSP432P401R: Problems with the example "adc_14_single_channel_temperature_sensor" in version 3.21.00.05 of the driver library

Part Number: MSP432P401R

The code for the example "adc_14_single_channel_temperature_sensor" in version 3.21.00.05 of the driver library has a few problems.  The original code for the interrupt handler is:

void ADC14_IRQHandler(void)
{
    uint64_t status;
    uint32_t cal30, cal85;

    status = ADC14_getEnabledInterruptStatus();
    ADC14_clearInterruptFlag(status);

    if(status & ADC_INT0)
    {
        cal30 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF,
                SYSCTL_30_DEGREES_C);
        cal85 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF,
                SYSCTL_85_DEGREES_C);

        tempC = (float) (((uint32_t) ADC14_getResult(ADC_MEM0) - cal30) * (85 - 30))
                / (cal85 - cal30) + 30.0f;
        tempF = tempC * 9.0f / 5.0f + 32.0f;
    }

}


When I run the unmodified example on my version 2 MSP432 Launchpad, I get a temperature reading of 5.76 million degrees C.  Seems a little hot.  The problem is that the results from the adc are smaller than cal30.  Since the variables are uin32_t, subtracting cal30 gives a huge positive number rather than a negative number.  Changing the types to int32_t does the calculation correctly.  However, I am still not getting a reasonable temperature.  The values are:

cal30 = 4881
cal85 = 5626
ADC14_getResult returns (3638 or a number close to that)

This gives -61.77 deg C.  So either the calibration constants are wrong or there is something wrong with the way the example is reading the adc.

Update: I found from another forum entry that there is a bug in the adc setup.  The line:

ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A22, false);

should be

ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_INTBUF_VREFNEG_VSS, ADC_INPUT_A22, false);

Now the result is 25.7 deg C, which is reasonable.


Also, when I run the code on my version 1 MSP432 Launchpad, I get a divide by zero error.  That is because cal30 and cal85 are both defined as 0xffff on the XMS432 Rev B processor that I have, so the denominator (cal85 - cal30) is zero.  The code should check for that.

The interrupt routine that I am now using is:

void ADC14_IRQHandler(void)
{
    uint64_t status;
    int32_t cal30, cal85, adcval, denom;

    status = ADC14_getEnabledInterruptStatus();
    ADC14_clearInterruptFlag(status);

    if(status & ADC_INT0)
    {
        cal30 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF,
                SYSCTL_30_DEGREES_C);
        cal85 = SysCtl_getTempCalibrationConstant(SYSCTL_2_5V_REF,
                SYSCTL_85_DEGREES_C);

        adcval = (int32_t) ADC14_getResult(ADC_MEM0);
    
        denom = (cal85 - cal30);
    
        if (denom != 0)
            tempC = (float) ((adcval - cal30) * (85 - 30))
                / denom + 30.0f;
        else
            tempC = -40.0f;
    
        tempF = tempC * 9.0f / 5.0f + 32.0f;
    }

}

Along with the change to ADC14_configureConversionMemory, this seems to solve the problems.

**Attention** This is a public forum