1、关于内部温度传感器如何使用?
2、如何将内部采集的值转化为实际的温度值?
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.
1、关于内部温度传感器如何使用?
2、如何将内部采集的值转化为实际的温度值?
mspware里有例程
//******************************************************************************
// MSP430F543xA Demo - ADC12_A, Sample A10 Temp and Convert to oC and oF
//
// Description: A single sample is made on A10 with reference to internal
// 1.5V Vref. Software sets ADC12SC to start sample and conversion - ADC12SC
// automatically cleared at EOC. ADC12 internal oscillator times sample
// and conversion. In Mainloop MSP430 waits in LPM4 to save power until
// ADC10 conversion complete, ADC12_ISR will force exit from any LPMx in
// Mainloop on reti.
// ACLK = n/a, MCLK = SMCLK = default DCO ~ 1.045MHz, ADC12CLK = ADC12OSC
//
// Uncalibrated temperature measured from device to devive will vary due to
// slope and offset variance from device to device - please see datasheet.
// Note:Use the TLV calibrated temperature to measure temperature
// (the TLV CALIBRATED DATA IS STORED IN THE INFORMATION SEGMENT, SEE DEVICE DATASHEET)
//
// MSP430F5438A
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// |A10 |
//
// F. Chen
// Texas Instruments Inc.
// Dec. 2012
// Built with IAR Embedded Workbench Version: 5.51.1 & Code Composer Studio V5.2.1
//******************************************************************************
#include <msp430.h>
#define CALADC12_15V_30C *((unsigned int *)0x1A1A) // Temperature Sensor Calibration-30 C
//See device datasheet for TLV table memory mapping
#define CALADC12_15V_85C *((unsigned int *)0x1A1C) // Temperature Sensor Calibration-85 C
unsigned int temp;
volatile float temperatureDegC;
volatile float temperatureDegF;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
/* Initialize the shared reference module */
REFCTL0 |= REFMSTR + REFVSEL_0 + REFON; // Enable internal 1.5V reference
/* Initialize ADC12_A */
ADC12CTL0 = ADC12SHT0_8 + ADC12ON; // Set sample time
ADC12CTL1 = ADC12SHP; // Enable sample timer
ADC12MCTL0 = ADC12SREF_1 + ADC12INCH_10; // ADC input ch A10 => temp sense
ADC12IE = 0x001; // ADC_IFG upon conv result-ADCMEMO
__delay_cycles(75); // delay to allow Ref to settle
// based on default DCO frequency.
// See Datasheet for typical settle
// time.
ADC12CTL0 |= ADC12ENC;
while(1)
{
ADC12CTL0 &= ~ADC12SC;
ADC12CTL0 |= ADC12SC; // Sampling and conversion start
__bis_SR_register(LPM4_bits + GIE); // LPM4 with interrupts enabled
__no_operation();
// Temperature in Celsius. See the Device Descriptor Table section in the
// System Resets, Interrupts, and Operating Modes, System Control Module
// chapter in the device user's guide for background information on the
// used formula.
temperatureDegC = (float)(((long)temp - CALADC12_15V_30C) * (85 - 30)) /
(CALADC12_15V_85C - CALADC12_15V_30C) + 30.0f;
// Temperature in Fahrenheit Tf = (9/5)*Tc + 32
temperatureDegF = temperatureDegC * 9.0f / 5.0f + 32.0f;
__no_operation(); // SET BREAKPOINT HERE
}
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(ADC12IV,34))
{
case 0: break; // Vector 0: No interrupt
case 2: break; // Vector 2: ADC overflow
case 4: break; // Vector 4: ADC timing overflow
case 6: // Vector 6: ADC12IFG0
temp = ADC12MEM0; // Move results, IFG is cleared
__bic_SR_register_on_exit(LPM4_bits); // Exit active CPU
break;
case 8: break; // Vector 8: ADC12IFG1
case 10: break; // Vector 10: ADC12IFG2
case 12: break; // Vector 12: ADC12IFG3
case 14: break; // Vector 14: ADC12IFG4
case 16: break; // Vector 16: ADC12IFG5
case 18: break; // Vector 18: ADC12IFG6
case 20: break; // Vector 20: ADC12IFG7
case 22: break; // Vector 22: ADC12IFG8
case 24: break; // Vector 24: ADC12IFG9
case 26: break; // Vector 26: ADC12IFG10
case 28: break; // Vector 28: ADC12IFG11
case 30: break; // Vector 30: ADC12IFG12
case 32: break; // Vector 32: ADC12IFG13
case 34: break; // Vector 34: ADC12IFG14
default: break;
}
}