新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應用 > MSP430F149的ADC12模塊

MSP430F149的ADC12模塊

作者: 時間:2016-11-27 來源:網(wǎng)絡(luò) 收藏

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

EOS Bit 7 End of sequence. Indicates the last conversion in a sequence.

0 Not end of sequence

1 End of sequence

4實例

4.1 single采樣,參考電源為系統(tǒng)電源

1.設(shè)置ADC12CTL0,使ADC12通道0采樣保持時間為16 ADC12CLK(SHT0_2),開啟ADC12模塊(ADC12ON);

2.設(shè)置ADC12CTL1,選擇采樣保持脈沖模式即SAMPCON為采樣定時器(SHP)

3.設(shè)置ADC12IE,是通道0中斷使能(0x01);

4.設(shè)置ADC12CTL0,使能AD轉(zhuǎn)換(ENC)

5.設(shè)置模擬信號輸入IO口P60

7.設(shè)置ADC12CTL0,開啟AD轉(zhuǎn)換(ADC12SC),等待中斷

8.中斷中讀取通道0轉(zhuǎn)換值A(chǔ)DC12MEM0

ADC12CTL0 = SHT0_2 + ADC12ON; // Set sampling time, turn on ADC12

ADC12CTL1 = SHP; // Use sampling timer

ADC12IE = 0x01; // Enable interrupt

ADC12CTL0 |= ENC; // Conversion enabled

P6SEL |= 0x01; // P6.0 ADC option select

P2DIR |= 0x01;

ADC12CTL0 |= ADC12SC;

#pragma vector=ADC12_VECTOR

__interrupt void ADC12_ISR (void)

{

if (ADC12MEM0 < 0x7FF)

P2OUT = 0; // Clear P1.0 LED off

else

P2OUT = 0XFF; // Set P1.0 LED on

__low_power_mode_off_on_exit();

// 與上面等價_BIC_SR_IRQ(CPUOFF); // Clear CPUOFF bit from 0(SR)

}

4.2 single采樣參考源為2.5V

在ADC12CTL0中設(shè)置參考源

在ADC12MCTL0中為通道0選擇參考源

ADC12CTL0 = ADC12ON+SHT0_2+REFON+REF2_5V; // Turn on and set up ADC12

ADC12CTL1 = SHP; // Use sampling timer

ADC12MCTL0 = SREF_1; // Vr+=Vref+

for ( i=0; i<0x3600; i++); // Delay for reference start-up

ADC12CTL0 |= ENC;

while (1)

{

ADC12CTL0 |= ADC12SC; // Start conversion

while ((ADC12IFG & BIT0)==0);

_NOP(); // SET BREAKPOINT HERE

}

4.3 Repeat-single采樣,模擬輸入為內(nèi)部Temperature sensor

設(shè)置ADC12CTL1,采樣保持源為定時器A,脈沖保持模式,Repeat-single模式

ADC12CTL1 = SHS_1 + SHP + CONSEQ_2; // TA trig., rpt conv.

設(shè)置ADC12MCTL0,通道0參考源為內(nèi)部REF,模擬輸入通道0選擇為Temperature sensor

ADC12MCTL0 = SREF_1 + INCH_10; // Channel A10, Vref+

ADC12IE = 0x01; // Enable ADC12IFG.0

ADC12CTL0 = SHT0_8 + REF2_5V + REFON + ADC12ON + ENC; // Config ADC12

TACCTL1 = OUTMOD_4; // Toggle on EQU1 (TAR = 0)

TACTL = TASSEL_2 + MC_2; // SMCLK, cont-mode

while (!(0x01 & ADC12IFG)); // First conversion?

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 off

else P1OUT |= 0x01; // LED on

}

攝氏溫度和溫度傳感器電壓轉(zhuǎn)換關(guān)系:0攝氏度對應986mv,1攝氏度溫差對應1.97mv溫差

// oF = ((x/4096)*1500mV)-923mV)*1/1.97mV = x*761/4096 - 468

// IntDegF = (ADC12MEM0 - 2519)* 761/4096

IntDegF = (temp - 2519) * 761;

IntDegF = IntDegF / 4096;

// oC = ((x/4096)*1500mV)-986mV)*1/3.55mV = x*423/4096 - 278

// IntDegC = (ADC12MEM0 - 2692)* 423/4096

IntDegC = (temp - 2692) * 423;

IntDegC = IntDegC / 4096;

4.4 Repeat-sequence mode

Sequence模式時可以設(shè)置多個采樣通道。在最后一個通道加上EOS就表明的采樣通道結(jié)束位置。中斷允許只需要設(shè)置最后一個通道。

為了采樣速率盡可能快,可設(shè)置MSC,此時當SHI上升沿觸發(fā)第一次采樣后,后面的采樣在上一次采樣結(jié)束后自動進行。

ADC12CTL0 = ADC12ON+MSC+SHT0_8; // Turn on ADC12, extend sampling time

// to avoid overflow of results

ADC12CTL1 = SHP+CONSEQ_3; // Use sampling timer, repeated sequence

ADC12MCTL0 = INCH_0; // ref+=AVcc, channel = A0

ADC12MCTL1 = INCH_1; // ref+=AVcc, channel = A1

ADC12MCTL2 = INCH_2; // ref+=AVcc, channel = A2

ADC12MCTL3 = INCH_3+EOS; // ref+=AVcc, channel = A3, end seq.

ADC12IE = 0x08; // Enable ADC12IFG.3

ADC12CTL0 |= ENC; // Enable conversions

ADC12CTL0 |= ADC12SC; // Start conversion

_BIS_SR(LPM0_bits + GIE); // Enter LPM0, Enable interrupts

#pragma vector=ADC12_VECTOR

__interrupt void ADC12ISR (void)

{

static unsigned int index = 0;

A0results[index] = ADC12MEM0; // Move A0 results, IFG is cleared

A1results[index] = ADC12MEM1; // Move A1 results, IFG is cleared

A2results[index] = ADC12MEM2; // Move A2 results, IFG is cleared

A3results[index] = ADC12MEM3; // Move A3 results, IFG is cleared

index = (index+1)%Num_of_Results; // Increment results index, modulo; Set Breakpoint here

}


上一頁 1 2 下一頁

關(guān)鍵詞: MSP430F149ADC12模

評論


技術(shù)專區(qū)

關(guān)閉