/*
* -------------------------------------------
* MSP432 DriverLib - v3_21_00_05
* -------------------------------------------
*
* --COPYRIGHT--,BSD,BSD
* Copyright (c) 2016, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --/COPYRIGHT--*/
/*******************************************************************************
* 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 "LibG2_main.h"
volatile float tempC;
volatile float tempF;
int64_t status;
uint32_t cal30, cal85;
int main(void)
{
/* Halting WDT */
WDT_A_holdTimer();
/* 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)
{
/*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;
}*/
}
}
/* 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;
uint16_t temp;
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);
temp=ADC14_getResult(ADC_MEM0);
tempC = (float) (((uint32_t) ADC14_getResult(ADC_MEM0) - cal30) * (85 - 30))
/ (cal85 - cal30) + 30.0f;
tempF = tempC * 9.0f / 5.0f + 32.0f;
}
}