////ADC12, Sample A10 Temperature and Convert to C and F
//MSP430基礎(chǔ)實驗開發(fā)組件 - ADC12內(nèi)部模塊演示程序之內(nèi)部溫度傳感器
//時鐘設(shè)置:
////ACLK = n/a, MCLK = SMCLK = default DCO ~ 800kHz, ADC12CLK = ADC12OSC
//當前演示程序功能描述:
////利用MSP430F14X內(nèi)部的溫度傳感器,通過ADC12的通道10進行AD轉(zhuǎn)換
////計算取得攝氏溫度和華氏溫度,通過斷點在View->Watch中觀察溫度值
////由于定標問題, 可能會存在溫度的誤差
#include <msp430x14x.h>
unsigned int long temp;
unsigned int long TemperF; //華氏溫度
unsigned int long TemperC; //攝氏溫度
void main(void) {
WDTCTL = WDTPW + WDTHOLD; //關(guān)閉系統(tǒng)看門狗
ADC12CTL0 = SHT0_8 + REFON + ADC12ON; //內(nèi)部1.5V參考電壓,打開ADC12模塊,設(shè)置采樣保持定時器
ADC12CTL1 = SHP; //采使用采樣定時器
ADC12MCTL0 = SREF_1 + INCH_10; //參考電壓和通道選擇
ADC12IE = BIT0; //ADC12MEM0
ADC12CTL0 |= ENC; //允許轉(zhuǎn)換
_BIS_SR(GIE); //開啟系統(tǒng)中斷
while(1) {
ADC12CTL0 |= ADC12SC; //開始采樣并AD轉(zhuǎn)換
//oF = ((x/4096)*1500mV)-923mV)*1/1.97mV = x*761/4096 - 468
//IntDegF = (ADC12MEM0 - 2519)* 761/4096
TemperF = (temp - 2519) * 761;
TemperF = TemperF / 4096; //簡化的華氏溫度轉(zhuǎn)換公式
//oC = ((x/4096)*1500mV)-986mV)*1/3.55mV = x*423/4096 - 278
//IntDegC = (ADC12MEM0 - 2692)* 423/4096
TemperC = (temp - 2692) * 423;
TemperC = TemperC / 4096; //簡化的攝氏溫度轉(zhuǎn)換公式
_NOP(); //加入斷點可用來觀察IntDegF和IntDegC結(jié)果
}
}
#pragma vector=ADC_VECTOR
__interrupt void ADC12ISR(void) {
temp = ADC12MEM0; //保存轉(zhuǎn)換結(jié)果
}
評論