} } }

    MSP430进修笔记2-ADC12

    添加时间:2013-6-16 点击量:

    接《MSP430进修笔记1-I/O端口》


    开辟版型号:SEED—MSP430F5529A


    开辟对象   :CCS 5.4v


    以下内容是CCS中ADC12操纵的一些简单的demo,现收拾如下:


    有关MSP430F5529芯片ADC12相干材料,可参考《MSP430 x5xx and MSP430 x6xx Family Users Guide (Rev. M)——Chapter 28 ADC12_A》




    1:demo描述



    Description: A single sample is made on A0 with reference to AVcc.


    Software sets ADC12SC to start sample and conversion - ADC12SC 


    automatically cleared at EOC. ADC12 internal oscillator times sample (16x)


    and conversion. In Mainloop MSP430 waits in LPM0 to save power until ADC12


    conversion complete, ADC12_ISR will force exit LPM0 in Mainloop on


    reti. If A0 > 0.5AVcc, P1.0 set, else reset.



    参考AVcc电压、以A0按时器作为采样输入旌旗灯号源的、单通道单次模式采样,当采样旌旗灯号大于0.5AVcc时,P1.0置位,不然为0。

    代码如下:



     1 #include <msp430.h>
    
    2
    3 int main(void
    4 {
    5 WDTCTL = WDTPW + WDTHOLD; // Stop WDT
    6 ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on
    7 ADC12CTL1 = ADC12SHP; // Use sampling timer
    8 ADC12IE = 0 x01; // Enable interrupt
    9 ADC12CTL0 |= ADC12ENC;
    10 P6SEL |= 0 x01; // P6.0 ADC option
    11 P1DIR |= 0 x01; // P1.0 output
    12
    13 while1
    14 {
    15 ADC12CTL0 |= ADC12SC; // Start sampling/conversion
    16
    17 __bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit
    18 __no_operation(); // For debugger
    19 }
    20 }
    21
    22 #pragma vector = ADC12_VECTOR
    23 __interrupt void ADC12_ISR(void
    24 {
    25 switch(__even_in_range(ADC12IV,34))
    26 {
    27 case 0: break; // Vector 0: No interrupt
    28 case 2: break; // Vector 2: ADC overflow
    29 case 4: break; // Vector 4: ADC timing overflow
    30 case 6: // Vector 6: ADC12IFG0
    31 if (ADC12MEM0 >= 0 x7ff// ADC12MEM = A0 > 0.5AVcc?
    32 P1OUT |= BIT0; // P1.0 = 1
    33 else
    34 P1OUT &= ~BIT0; // P1.0 = 0
    35
    36 __bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
    37 case 8: break; // Vector 8: ADC12IFG1
    38 case 10: break; // Vector 10: ADC12IFG2
    39 case 12: break; // Vector 12: ADC12IFG3
    40 case 14: break; // Vector 14: ADC12IFG4
    41 case 16: break; // Vector 16: ADC12IFG5
    42 case 18: break; // Vector 18: ADC12IFG6
    43 case 20: break; // Vector 20: ADC12IFG7
    44 case 22: break; // Vector 22: ADC12IFG8
    45 case 24: break; // Vector 24: ADC12IFG9
    46 case 26: break; // Vector 26: ADC12IFG10
    47 case 28: break; // Vector 28: ADC12IFG11
    48 case 30: break; // Vector 30: ADC12IFG12
    49 case 32: break; // Vector 32: ADC12IFG13
    50 case 34: break; // Vector 34: ADC12IFG14
    51 default: break;
    52 }
    53 }


    2:代码解析


    1)主函数中代码:



    1 ADC12CTL0 = ADC12SHT02 + ADC12ON;         // Sampling time, ADC12 on
    
    2 ADC12CTL1 = ADC12SHP; // Use sampling timer
    3 ADC12IE = 0 x01; // Enable interrupt
    4 ADC12CTL0 |= ADC12ENC;
    5
    6 ADC12CTL0 |= ADC12SC; // Start sampling/conversion



    参考把握存放器如下:


     


    ADCSHT0 x :采样对峙按时器0,该四位定义了保存在转换存储存放器中转换成果的采样周期;

    ADC12ENC:转换容许

    ADC12SHP:选择采样按时器A0输出 

    ADC12IE:中断容许 (来自中断容许存放器)

     


    2)中断项目组代码:



    中断存放向量ADC12IV中的数字(0-36)用来断定中断标记存放器中相干位是否置位,此时注解转换成果已经装入转换存储存放器中,具体数字的含义拜见下图:



    3)



    1  if (ADC12MEM0 >= 0 x7ff// ADC12MEM = A0 > 0.5AVcc?
    
    2 P1OUT |= BIT0; // P1.0 = 1
    3 else
    4 P1OUT &= ~BIT0; // P1.0 = 0


    参考电压应用VCC,因为ADC精度为12位(4095),所以0 x7FF(2047)就是0.5Vcc的AD值

      


    StevenMeng

    2013 6.14

     


    容易发怒的意思就是: 别人做了蠢事, 然后我们代替他们, 表现出笨蛋的样子。—— 蔡康永
    分享到: