MSP430F149的ADC12应用
MSP430F149的ADC12應(yīng)用
1 概述
MSP430F149的ADC12為SAR型12位AD,共有16路輸入通道,其中8路獨(dú)立的外部輸入通道,2路接外部Vref+,Vref-,3路內(nèi)部通道可分別測(cè)內(nèi)部溫度傳感器、AVCC、和外部參考源。
P6口第二功能為AD輸入端。MSP430F149的10、11分別接外部電壓參考源正負(fù)極,7腳可將內(nèi)部電壓參考源輸出。
ADC12共有18個(gè)中斷源,公用一個(gè)中斷向量ADC12_VECTOR。
AD的參考源可選擇內(nèi)部電壓參考源或外部電壓參考源。內(nèi)部電壓參考源有1.5V,2.5V可選,使用時(shí)向ADC12CTL0寫(xiě)入REFON+ REF2_5V就打開(kāi)了2.5V。外部電壓參考源由REF+接入。上電時(shí)若不設(shè)置參考源,則參考源為系統(tǒng)供電電壓3.3V。
參考框圖:
2 使用方法概述
2.1程序架構(gòu)
中斷方式
- 1、設(shè)置 ADC12工作模式,啟動(dòng)轉(zhuǎn)換,開(kāi)全局中斷,等待中斷
- 2、寫(xiě)中斷處理函數(shù)
查詢方式
- 設(shè)置ADC12工作模式,啟動(dòng)轉(zhuǎn)換,查詢中斷標(biāo)志ADC12IFG
while (!(0x01 & ADC12IFG)); - 轉(zhuǎn)換完畢讀取采樣值,系統(tǒng)自動(dòng)清除中斷標(biāo)志
- 設(shè)置ADC12工作模式,啟動(dòng)轉(zhuǎn)換,查詢中斷標(biāo)志ADC12IFG
2.2 使用概述
主要參數(shù)進(jìn)行配置
- 設(shè)置工作方式:四種方式選一: sing;sequence;re-sing;re-sequence;
- 設(shè)置轉(zhuǎn)換時(shí)間:SHTx
- 設(shè)置觸發(fā)源:ADC12SC;MSC;TimerA;TimerB
- 設(shè)置通道:外部通道;內(nèi)部Temperature sensor
- 設(shè)置參考電壓:系統(tǒng)電壓;內(nèi)部參考源;外部參考源
- 其他細(xì)節(jié)配置
一般要配置采樣轉(zhuǎn)換模式為脈沖(SHP),打開(kāi)ADC12(ADC12ON),使能ADC12轉(zhuǎn)換(ENC),使能中斷(如果采取中斷模式),觸發(fā)轉(zhuǎn)換(若采用ADC12SC觸發(fā))。
ADC12模數(shù)轉(zhuǎn)換是在SHI的上升沿初始化的。
SHI信號(hào)有四個(gè)來(lái)源–參考ADC12CTL1寄存器說(shuō)明:
- The ADC12SC bit;
- The Timer_A Output Unit 1;
- The Timer_B Output Unit 0;
The Timer_B Output Unit 1。
故單次采樣時(shí)只需要每次設(shè)置ADC12CTL0 |= ADC12SC就采樣一次;重復(fù)采樣時(shí),如Rep-sing,設(shè)置ADC12CTL1 = SHS_1 +CONSEQ_2就選擇了Rep-sing模式,每次采樣通過(guò)定時(shí)器A觸發(fā)。
3 相關(guān)寄存器
1、ADC12CTL0
SHT1x Bits:15-12; Sample-and-hold time.
These bits define the number of ADC12CLK cycles in the sampling period for registers ADC12MEM8 to ADC12MEM15.
SHT0x Bits: 8-11; Sample-and-hold time.
These bits define the number of ADC12CLK cycles in the sampling period for registers ADC12MEM0 to ADC12MEM7.
MSC: Bit 7; Multiple sample and conversion.
Valid only for sequence or repeated modes.
0 : The sampling timer requires a rising edge of the SHI signal to trigger each sample-and-conversion.
1 : The first rising edge of the SHI signal triggers the sampling timer, but further sample-and-conversions are performed automatically as soon as the prior conversion is completed.
- ADC12ON : Bit 4; ADC12 on
- 0 : ADC12 off
- 1 : ADC12 on
- ENC: ENC Bit 1; Enable conversion
- 0 : ADC12 disabled
- 1 : ADC12 enabled
- ADC12SC: Bit 0; Start conversion.
Software-controlled sample-and-conversion start. ADC12SC and ENC may be set together with one instruction. ADC12SC is reset automatically.
- 0 : No sample-and-conversion-start
- 1 : Start sample-and-conversion
2、ADC12CTL1
CSTARTADDx: Bit 15-12;
Conversion start address. These bits select which ADC12 conversion-memory register is used for a single conversion or for the first conversion in a sequence. The value of CSTARTADDx is 0 to 0Fh, corresponding to ADC12MEM0 to ADC12MEM15.
SHSx: Bits 11-10; Sample-and-hold source select
- 00 : ADC12SC bit
- 01 : Timer_A.OUT1
- 10 : Timer_B.OUT0
- 11 : Timer_B.OUT1
SHP:Bit 9; Sample-and-hold pulse-mode select.
This bit selects the source of the sampling signal (SAMPCON) to be either the output of the sampling timer or the sample-input signal directly.
- 0 SAMPCON signal is sourced from the sample-input signal.
- 1 SAMPCON signal is sourced from the sampling timer.
- ISSH: Bit 8; Invert signal sample-and-hold
- 0 The sample-input signal is not inverted.
- 1 The sample-input signal is inverted.
ADC12DIVx: Bits 7-5; ADC12 clock divider
- 000 /1
- 001 /2
- 010 /3
- 011 /4
- 100 /5
- 101 /6
- 110 /7
- 111 /8
ADC12 SSELx: Bits 4-3; ADC12 clock source select.
- 00 ADC12OSC
- 01 ACLK
- 10 MCLK
- 11 SMCLK
CONSEQx: Bits 2-1; Conversion sequence mode select
- 00 : Single-channel, single-conversion
- 01 : Sequence-of-channels
- 10 : Repeat-single-channel
- 11 : Repeat-sequence-of-channels
ADC12 BUSY: Bit 0; ADC12 busy. This bit indicates an active sample or conversion operation.
- 0 No operation is active.
- 1 A sequence, sample, or conversion is active.
3、ADC12IE
ADC12 Interrupt Enable Register
- ADC12IEx: Bits 15-0
– 0 : Interrupt disabled
– 1 : Interrupt enabled
4、ADC12IFG
ADC12 Interrupt Flag Register
- ADC12IFGx Bits 15-0
ADC12MEMx Interrupt flag. These bits are set when corresponding
ADC12MEMx is loaded with a conversion result. The ADC12IFGx bits are
reset if the corresponding ADC12MEMx is accessed, or may be reset with software.
- 0 : No interrupt pending
- 1 : Interrupt pending
5、ADC12MCTLX
ADC12 Conversion Memory Control Registers
- EOS: Bit 7; End of sequence.
Indicates the last conversion in a sequence.
- 0 Not end of sequence
- 1 End of sequence
SREFx: Bits 6-4; Select reference
- 000 VR+ = AVCC and VR? = AVSS
- 001 VR+ = VREF+ and VR? = AVSS
- 010 VR+ = VeREF+ and VR? = AVSS
- 011 VR+ = VeREF+ and VR? = AVSS
- 100 VR+ = AVCC and VR? = VREF?/ VeREF?
- 101 VR+ = VREF+ and VR? = VREF?/ VeREF?
- 110 VR+ = VeREF+ and VR? = VREF?/ VeREF?
- 111 VR+ = VeREF+ and VR? = VREF?/ VeREF?
INCHx: Bits 3-0; Input channel select
- 0000 A0
- 0001 A1
- 0010 A2
- 0011 A3
- 0100 A4
- 0101 A5
- 0110 A6
- 0111 A7
- 1000 VeREF+
- 1001 VREF?/VeREF?
- 1010 Temperature sensor
- 1011 (AVCC – AVSS) / 2
- 1100 (AVCC – AVSS) / 2
- 1101 (AVCC – AVSS) / 2
- 1110 (AVCC – AVSS) / 2
- 1111 (AVCC – AVSS) / 2
6、ADC12MEMx
ADC12 Conversion Memory Registers
Conversion Results: Bit 15-0;
4 實(shí)例
4.1 single采樣,參考電源為系統(tǒng)電源
- 1.設(shè)置ADC12CTL0,使ADC12通道0采樣保持時(shí)間為16 ADC12CLK(SHT0_2),開(kāi)啟ADC12模塊(ADC12ON);
- 2.設(shè)置ADC12CTL1,選擇采樣保持脈沖模式即SAMPCON為采樣定時(shí)器(SHP)
- 3.設(shè)置ADC12IE,是通道0中斷使能(0x01);
- 4.設(shè)置ADC12CTL0,使能AD轉(zhuǎn)換(ENC)
- 5.設(shè)置模擬信號(hào)輸入IO口P60
- 7.設(shè)置ADC12CTL0,開(kāi)啟AD轉(zhuǎn)換(ADC12SC),等待中斷
- 8.中斷中讀取通道0轉(zhuǎn)換值A(chǔ)DC12MEM0
4.2 single采樣參考源為2.5V
在ADC12CTL0中設(shè)置參考源
在ADC12MCTL0中為通道0選擇參考源
4.3 Repeat-single采樣,模擬輸入為內(nèi)部Temperature sensor
設(shè)置ADC12CTL1,采樣保持源為定時(shí)器A,脈沖保持模式,Repeat-single模式
ADC12CTL1 = SHS_1 + SHP + CONSEQ_2; // TA trig., rpt conv.// 設(shè)置ADC12MCTL0,通道0參考源為內(nèi)部REF,模擬輸入通道0選擇為T(mén)emperature sensorADC12MCTL0 = SREF_1 + INCH_10; // Channel A10, Vref+ADC12IE = 0x01; // Enable ADC12IFG.0ADC12CTL0 = SHT0_8 + REF2_5V + REFON + ADC12ON + ENC; // Config ADC12TACCTL1 = OUTMOD_4; // Toggle on EQU1 (TAR = 0)TACTL = TASSEL_2 + MC_2; // SMCLK, cont-modewhile (!(0x01 & ADC12IFG)); // First conversion? - 等待設(shè)置完成FirstADCVal = ADC12MEM0; // Read out 1st ADC value_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt#pragma vector=ADC12_VECTOR __interrupt void ADC12ISR (void) {if (ADC12MEM0 <= FirstADCVal + ADCDeltaOn)P1OUT &= ~0x01; // LED offelse P1OUT |= 0x01; // LED on }攝氏溫度和溫度傳感器電壓轉(zhuǎn)換關(guān)系:0攝氏度對(duì)應(yīng)986mv,1攝氏度溫差對(duì)應(yīng)1.97mv溫差
// oF = ((x/4096)*1500mV)-923mV)*1/1.97mV = x*761/4096 - 468 // IntDegF = (ADC12MEM0 - 2519)* 761/4096IntDegF = (temp - 2519) * 761;IntDegF = IntDegF / 4096; // oC = ((x/4096)*1500mV)-986mV)*1/3.55mV = x*423/4096 - 278 // IntDegC = (ADC12MEM0 - 2692)* 423/4096IntDegC = (temp - 2692) * 423;IntDegC = IntDegC / 4096;4.4 Repeat-sequence mode
Sequence模式時(shí)可以設(shè)置多個(gè)采樣通道。在最后一個(gè)通道加上EOS就表明的采樣通道結(jié)束位置。中斷允許只需要設(shè)置最后一個(gè)通道。
為了采樣速率盡可能快,可設(shè)置MSC,此時(shí)當(dāng)SHI上升沿觸發(fā)第一次采樣后,后面的采樣在上一次采樣結(jié)束后自動(dòng)進(jìn)行。
總結(jié)
以上是生活随笔為你收集整理的MSP430F149的ADC12应用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 郭明錤:预计苹果 iPhone 16 系
- 下一篇: 需求疲软,SK 海力士四季度净亏损 3.