万安文 发表于 2012-4-15 21:32:32

求助:关于msp430f149的ADC12的问题

前辈们好,我刚接触430,现在遇到了点问题,在下面TI所提供的例子中,中断服务程序里面的“ADC12MEM0 < 0x7FF”怎么就表示A0<0.5Vcc了呢,还有上面因为没有开转换,是不是ADC12MEM0里面存储的是A0里面的值?刚接触,问的问题可能没技术含量,还望前辈们不吝赐教。//******************************************************************************
//MSP-FET430P140 Demo - ADC12, Sample A0, Set P1.0 if A0 > 0.5*AVcc
//
//Description: A single sample is made on A0 with reference to AVcc.
//Software sets ADC10SC 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 from LPM0 in Mainloop on
//reti. If A0 > 0.5*AVcc, P1.0 set, else reset.
//
//                MSP430F149
//             -----------------
//         /|\|            XIN|-
//          | |               |
//          --|RST          XOUT|-
//            |               |
//      Vin-->|P6.0/A0      P1.0|--> LED
//
//M. Buccini
//Texas Instruments Inc.
//Feb 2005
//Built with IAR Embedded Workbench Version: 3.21A
//******************************************************************************

#include<msp430x14x.h>

void main(void)
{
WDTCTL = WDTPW + WDTHOLD;               // Stop WDT
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
P1DIR |= 0x01;                            // P1.0 output

for (;;)
{
    ADC12CTL0 |= ADC12SC;                   // Sampling open
    _BIS_SR(CPUOFF + GIE);                  // LPM0, ADC12_ISR will force exit
}
}

// ADC12 interrupt service routine
#pragma vector=ADC_VECTOR
__interrupt void ADC12_ISR (void)
{
    if (ADC12MEM0 < 0x7FF)
      P1OUT &= ~0x01;                     // Clear P1.0 LED off
    else
      P1OUT |= 0x01;                        // Set P1.0 LED on
    _BIC_SR_IRQ(CPUOFF);                  // Clear CPUOFF bit from 0(SR)
}

ccstc 发表于 2012-4-15 23:25:59

设置连续转换
ADC12CTL0 = SHT0_2 + ADC12ON;             // Set sampling time, turn on ADC12
ADC12CTL1 = SHP;                        // Use sampling timer
启动转换
ADC12CTL0 |= ADC12SC;                   // Sampling open
每次转换完成后进入中断服务函数

ADC12MEM0里面就是转换结果了
参考电压使用VCC,因为ADC精度为12位(4096),所以0x7FF(2047)就是0.5Vcc的AD值

万安文 发表于 2012-4-16 07:22:54

ccstc 发表于 2012-4-15 23:25 static/image/common/back.gif
设置连续转换
ADC12CTL0 = SHT0_2 + ADC12ON;             // Set sampling time, turn on ADC12
ADC12CTL1 ...

你好,我不明白的是TI所提供的例子里面并没有开始转换,那ADC12MEM0 所存储的是哪个量?

15085362 发表于 2012-4-16 07:47:09

ADC12CTL0 |= ADC12SC;                  开始转换

万安文 发表于 2012-4-16 12:18:14

万安文 发表于 2012-4-16 07:22 static/image/common/back.gif
你好,我不明白的是TI所提供的例子里面并没有开始转换,那ADC12MEM0 所存储的是哪个量? ...

对不起,我看漏了,谢谢你的解答

万安文 发表于 2012-4-16 12:19:36

15085362 发表于 2012-4-16 07:47 static/image/common/back.gif
ADC12CTL0 |= ADC12SC;                  开始转换

嗯,谢谢,我看漏了。不管怎样还是谢谢你的帮忙,以后有问题希望还能请教各位
页: [1]
查看完整版本: 求助:关于msp430f149的ADC12的问题