This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430F6638的ADC采用内部2.5V参考电压时,用ADC通道0(P6.0)读出数据准确,但是运用AD1或者AD2等其他通道加或者不加电压读出值都为4096,求大神帮看看程序是不是有问题?

Other Parts Discussed in Thread: MSP430F6638

MSP430F6638的ADC采用内部2.5V参考电压时,用ADC通道0(P6.0)读出数据准确,但是运用AD1或者AD2等其他通道不加电压读出值为4096,求大神帮看看程序是不是有问题?

程序为采用通道AD1时:

       

void Init_ADC__2(void)
{

P6SEL |= BIT1; // 使能ADC通道 
ADC12CTL0 = ADC12ON+ADC12SHT0_15+ADC12REFON+ADC12REF2_5V; // 打开ADC,设置采样时间
ADC12CTL1 =ADC12CSTARTADD_1+ADC12SHP+ADC12CONSEQ_0; // 选择存储器地址,使用采样定时器
ADC12MCTL1 =ADC12SREF_1+ADC12INCH_1; // 选择采样通道0 ADC12SREF_1+
//delay_1(1);
ADC12CTL0 |= ADC12ENC; // 使能转换
}

void ADC_SUM_2(unsigned char counter)
{

unsigned long average;//均值滤波总和变量,当counter过大可能导致溢出
float testing=0;//滤波后的测试值
average = 0;
testing=0;
test=0;
for(unsigned char j=0;j<counter;j++)//循环采集三次
{

ADC12CTL0 |=ADC12SC; // 开始转换
delay(10);
while (ADC12IFG ==BIT1)//等待AD转换结束
{

average +=ADC12MEM1;//采集值叠加到均值滤波总和变量

ADC12IFG&=~BIT1;//清 ADC12IFG中断标志位

}
}
testing=average/counter;//滤波后的测试值

delay(1000);//延时

}

***********************主函数***********************/
void main( void )
{

WDTCTL = WDTPW + WDTHOLD; //关狗
Init_ADC__2();

_EINT();

while(1)
{
ADC_SUM_2(35);

LPM3;
}

  • io在外部未连接电路的时候,是悬空状态,电平的大小由周围的电磁环境决定。也就是说有可能是任何值。

    建议连接到固定的电压再测试

  • 不管连接多少伏的固定电压(电压<2.5V)也都是显示4096
  • 您现在是自己设计的板子?建议您用下面的程序测试一下

    /* --COPYRIGHT--,BSD_EX
     * Copyright (c) 2012, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     *******************************************************************************
     * 
     *                       MSP430 CODE EXAMPLE DISCLAIMER
     *
     * MSP430 code examples are self-contained low-level programs that typically
     * demonstrate a single peripheral function or device feature in a highly
     * concise manner. For this the code may rely on the device's power-on default
     * register values and settings such as the clock configuration and care must
     * be taken when combining code from several examples to avoid potential side
     * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
     * for an API functional library-approach to peripheral configuration.
     *
     * --/COPYRIGHT--*/
    //******************************************************************************
    //  MSP430F66x Demo - ADC12, Using the Internal Reference
    //
    //  Description: This example shows how to use the internal reference of REF 
    //  module using the ADC12 control registers.
    //  The ADC12 uses the internal 2.5V reference and performs a single conversion
    //  on channel A0. The conversion results are stored in ADC12MEM0. Test by
    //  applying a voltage to channel A0, then setting and running to a break point
    //  at the "__no_operation()" instruction. To view the conversion results,
    //  open an ADC12 register window in debugger and view the contents of ADC12MEM0
    //
    //  NOTE:REFMSTR bit in REFCTL0 regsiter is reset to allow the ADC12_A reference
    //    control regsiters handle the reference setting. Upon resetting the REFMSTR
    //    bit, all the settings in REFCTL are 'dont care' and the legacy ADC12  
    //    control bits (ADC12REFON, ADC12REF2_5, ADC12TCOFF and ADC12REFOUT) control 
    //    the reference system. 
    //
    //                MSP430F66x
    //             -----------------
    //         /|\|                 |
    //          | |                 |
    //          --|RST              |
    //            |                 |
    //     Vin -->|P6.0/CB0/A0      |
    //            |                 |
    //
    //   Priya Thanigai
    //   Texas Instruments Inc.
    //   Nov 2009
    //   Built with IAR Embedded Workbench Version: 4.20 & Code Composer Studio V4.0
    //******************************************************************************
    #include <msp430.h>
    
    int main(void)
    {
      volatile unsigned int i;
      WDTCTL = WDTPW+WDTHOLD;                   // Stop watchdog timer
      P6SEL |= 0x01;                            // Enable A/D channel A0
      REFCTL0 &= ~REFMSTR;                      // Reset REFMSTR to hand over control to 
                                                // ADC12_A ref control registers
      ADC12CTL0 = ADC12ON+ADC12SHT02+ADC12REFON+ADC12REF2_5V;
                                                // Turn on ADC12, Sampling time
                                                // On Reference Generator and set to
                                                // 2.5V
      ADC12CTL1 = ADC12SHP;                     // Use sampling timer
      ADC12MCTL0 = ADC12SREF_1;                 // Vr+=Vref+ and Vr-=AVss
    
      for ( i=0; i<0x30; i++);                  // Delay for reference start-up
    
      ADC12CTL0 |= ADC12ENC;                    // Enable conversions
    
      while (1)
      {
        ADC12CTL0 |= ADC12SC;                   // Start conversion
        while (!(ADC12IFG & BIT0));
        __no_operation();                       // SET BREAKPOINT HERE
    
      }
    }
    
    

  • 您给我的这个程序 我在自己的板子上对P6.0/AD0测试结果是正常的,但是如果我在这个程序上将P6.0/AD0改成P6.1/AD1通道采集该怎么改呢?按我之前的程序我测出的结果不对
  • REFCTL0 &= ~REFMSTR; 我错误的原因 跟缺少这条语句有关系 加上这句就好了 这句在这里起什么作用呢?
  • 很高兴您能解决问题

    上面程序内的note有相关说明

    REFMSTR bit in REFCTL0 regsiter is reset to allow the ADC12_A reference control regsiters handle the reference setting. Upon resetting the REFMSTR bit, all the settings in REFCTL are 'dont care' and the legacy ADC12 control bits (ADC12REFON, ADC12REF2_5, ADC12TCOFF and ADC12REFOUT) control the reference system.