Part Number: MSP432P401R
I am using the DriverLib ADC14 example that measures the internal temperature of the chip I am using the new red Launchpad:
/******************************************************************************* * MSP432 ADC14 - Single Channel Repeat Temperature Sensor * * Description: This example shows the use of the internal temperature sensor. * A simple continuous ADC sample/conversion is set up with a software trigger. * The sample time is set to TBD as speced by the User's Guide. All calculations * take place in the ISR which take advantage of the Stacking Mode of the FPU. * The temperature is calculated in both Celsius and Fahrenheit. * * MSP432P401 * ------------------ * /|\| | * | | | * --|RST P5.5 | * | | * | | * | | * * Author: Timothy Logan ******************************************************************************/ /* DriverLib Includes */ #include "driverlib.h" /* Standard Includes */ #include <stdint.h> #include <string.h> volatile float tempC; volatile float tempF; int main(void) { /* Halting WDT */ WDT_A_holdTimer(); Interrupt_enableSleepOnIsrExit(); /* Enabling the FPU with stacking enabled (for use within ISR) */ FPU_enableModule(); FPU_enableLazyStacking(); /* Initializing ADC (MCLK/1/1) with temperature sensor routed */ ADC14_enableModule(); ADC14_initModule(ADC_CLOCKSOURCE_MCLK, ADC_PREDIVIDER_1, ADC_DIVIDER_1, ADC_TEMPSENSEMAP); /* Configuring ADC Memory (ADC_MEM0 A22 (Temperature Sensor) in repeat * mode). */ ADC14_configureSingleSampleMode(ADC_MEM0, true); ADC14_configureConversionMemory(ADC_MEM0, ADC_VREFPOS_AVCC_VREFNEG_VSS, ADC_INPUT_A22, false); /* Configuring the sample/hold time for TBD */ ADC14_setSampleHoldTime(ADC_PULSE_WIDTH_192,ADC_PULSE_WIDTH_192); /* Enabling sample timer in auto iteration mode and interrupts*/ ADC14_enableSampleTimer(ADC_AUTOMATIC_ITERATION); ADC14_enableInterrupt(ADC_INT0); /* Setting reference voltage to 2.5 and enabling temperature sensor */ REF_A_setReferenceVoltage(REF_A_VREF2_5V); REF_A_enableReferenceVoltage(); REF_A_enableTempSensor(); /* Enabling Interrupts */ Interrupt_enableInterrupt(INT_ADC14); Interrupt_enableMaster(); /* Triggering the start of the sample */ ADC14_enableConversion(); ADC14_toggleConversionTrigger(); /* Going to sleep */ while (1) { PCM_gotoLPM0(); } } /* This interrupt happens every time a conversion has completed. Since the FPU * is enabled in stacking mode, we are able to use the FPU safely to perform * efficient floating point arithmetic.*/ 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 it, cal30 = 4702, cal85 = 5401 and my ADC reads about 3500.
Firstly:
In case someone measures temp below 30 C, I think you should make all the int variables signed. I got really confused when I measured a huge temperature. 8^)
However, even after I fixed that, I still measured about -60C, which is obviously not correct. What am I doing wrong?