日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

MSP430F149的ADC12应用

發布時間:2023/12/15 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MSP430F149的ADC12应用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

MSP430F149的ADC12應用


1 概述

MSP430F149的ADC12為SAR型12位AD,共有16路輸入通道,其中8路獨立的外部輸入通道,2路接外部Vref+,Vref-,3路內部通道可分別測內部溫度傳感器、AVCC、和外部參考源。

P6口第二功能為AD輸入端。MSP430F149的10、11分別接外部電壓參考源正負極,7腳可將內部電壓參考源輸出。

ADC12共有18個中斷源,公用一個中斷向量ADC12_VECTOR。
AD的參考源可選擇內部電壓參考源或外部電壓參考源。內部電壓參考源有1.5V,2.5V可選,使用時向ADC12CTL0寫入REFON+ REF2_5V就打開了2.5V。外部電壓參考源由REF+接入。上電時若不設置參考源,則參考源為系統供電電壓3.3V。

參考框圖:

2 使用方法概述

2.1程序架構

  • 中斷方式

    • 1、設置 ADC12工作模式,啟動轉換,開全局中斷,等待中斷
    • 2、寫中斷處理函數
  • 查詢方式

    • 設置ADC12工作模式,啟動轉換,查詢中斷標志ADC12IFG
      while (!(0x01 & ADC12IFG));
    • 轉換完畢讀取采樣值,系統自動清除中斷標志

2.2 使用概述

主要參數進行配置

  • 設置工作方式:四種方式選一: sing;sequence;re-sing;re-sequence;
  • 設置轉換時間:SHTx
  • 設置觸發源:ADC12SC;MSC;TimerA;TimerB
  • 設置通道:外部通道;內部Temperature sensor
  • 設置參考電壓:系統電壓;內部參考源;外部參考源
  • 其他細節配置

一般要配置采樣轉換模式為脈沖(SHP),打開ADC12(ADC12ON),使能ADC12轉換(ENC),使能中斷(如果采取中斷模式),觸發轉換(若采用ADC12SC觸發)。

ADC12模數轉換是在SHI的上升沿初始化的。
SHI信號有四個來源–參考ADC12CTL1寄存器說明:

  • The ADC12SC bit;
  • The Timer_A Output Unit 1;
  • The Timer_B Output Unit 0;
  • The Timer_B Output Unit 1。

    故單次采樣時只需要每次設置ADC12CTL0 |= ADC12SC就采樣一次;重復采樣時,如Rep-sing,設置ADC12CTL1 = SHS_1 +CONSEQ_2就選擇了Rep-sing模式,每次采樣通過定時器A觸發。

3 相關寄存器

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

Interrupt enable. These bits enable or disable the interrupt request for the ADC12IFGx bits.

– 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 實例

4.1 single采樣,參考電源為系統電源

  • 1.設置ADC12CTL0,使ADC12通道0采樣保持時間為16 ADC12CLK(SHT0_2),開啟ADC12模塊(ADC12ON);
  • 2.設置ADC12CTL1,選擇采樣保持脈沖模式即SAMPCON為采樣定時器(SHP)
  • 3.設置ADC12IE,是通道0中斷使能(0x01);
  • 4.設置ADC12CTL0,使能AD轉換(ENC)
  • 5.設置模擬信號輸入IO口P60
  • 7.設置ADC12CTL0,開啟AD轉換(ADC12SC),等待中斷
  • 8.中斷中讀取通道0轉換值ADC12MEM0
ADC12CTL0 = SHT0_2 + ADC12ON; // Set sampling time, turn on ADC12ADC12CTL1 = SHP; // Use sampling timerADC12IE = 0x01; // Enable interruptADC12CTL0 |= ENC; // Conversion enabledP6SEL |= 0x01; // P6.0 ADC option selectP2DIR |= 0x01;ADC12CTL0 |= ADC12SC;#pragma vector=ADC12_VECTOR __interrupt void ADC12_ISR (void) {if (ADC12MEM0 < 0x7FF)P2OUT = 0; // Clear P1.0 LED offelseP2OUT = 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中設置參考源
在ADC12MCTL0中為通道0選擇參考源

ADC12CTL0 = ADC12ON+SHT0_2+REFON+REF2_5V; // Turn on and set up ADC12ADC12CTL1 = SHP; // Use sampling timerADC12MCTL0 = SREF_1; // Vr+=Vref+for ( i=0; i<0x3600; i++); // Delay for reference start-upADC12CTL0 |= ENC; while (1){ADC12CTL0 |= ADC12SC; // Start conversionwhile ((ADC12IFG & BIT0)==0);_NOP(); // SET BREAKPOINT HERE}

4.3 Repeat-single采樣,模擬輸入為內部Temperature sensor

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

ADC12CTL1 = SHS_1 + SHP + CONSEQ_2; // TA trig., rpt conv.// 設置ADC12MCTL0,通道0參考源為內部REF,模擬輸入通道0選擇為Temperature 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? - 等待設置完成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 }

攝氏溫度和溫度傳感器電壓轉換關系:0攝氏度對應986mv,1攝氏度溫差對應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模式時可以設置多個采樣通道。在最后一個通道加上EOS就表明的采樣通道結束位置。中斷允許只需要設置最后一個通道。
為了采樣速率盡可能快,可設置MSC,此時當SHI上升沿觸發第一次采樣后,后面的采樣在上一次采樣結束后自動進行。

ADC12CTL0 = ADC12ON+MSC+SHT0_8; // Turn on ADC12, extend sampling time// to avoid overflow of resultsADC12CTL1 = SHP+CONSEQ_3; // Use sampling timer, repeated sequenceADC12MCTL0 = INCH_0; // ref+=AVcc, channel = A0ADC12MCTL1 = INCH_1; // ref+=AVcc, channel = A1ADC12MCTL2 = INCH_2; // ref+=AVcc, channel = A2ADC12MCTL3 = INCH_3+EOS; // ref+=AVcc, channel = A3, end seq.ADC12IE = 0x08; // Enable ADC12IFG.3ADC12CTL0 |= ENC; // Enable conversionsADC12CTL0 |= 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 clearedA1results[index] = ADC12MEM1; // Move A1 results, IFG is clearedA2results[index] = ADC12MEM2; // Move A2 results, IFG is clearedA3results[index] = ADC12MEM3; // Move A3 results, IFG is cleared// Increment results index, modulo; Set Breakpoint hereindex = (index+1)%Num_of_Results; }

總結

以上是生活随笔為你收集整理的MSP430F149的ADC12应用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。