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.

关于ADC12MEM高四位乱码的问题

Other Parts Discussed in Thread: MSP430F149

各位好:

  我在用msp430f149的ADC12测四个电阻串联的各分级电压时,测得3.3v,2.47v,1.68v都还比较正确,然后应该是0.84v,但实际测得的是1.54v左右,换3个电阻,5个电阻的去测,都是在与0v相隔一个电阻的位置测得1.54v,选择的是AVcc和AVss,ADC12MEM0的值和显示的错误值一致,请问这种情况是ADC12自身的问题吗?有没有什么解决的办法?新人一个,请各位大神指点一下!

  又尝试了一下十个电阻的,5、6电阻之间的电压是1.68v,约为3.3v的一般,没问题,但发现从第6个电阻开始电压分别为1.57v,1.50v,1.41v,1.22v,0v。

  • 芯片肯定不会有问题,这个系列是很古老的一个系列了,用了十多年都没事情。不知道你的代码是自己写的还是用的官方给的例程序。

    /* --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--*/
    //******************************************************************************
    //  MSP-FET430P140 Demo - ADC12, Repeated Sequence of Conversions
    //
    //  Description: This example shows how to perform a repeated sequence of
    //  conversions using "repeat sequence-of-channels" mode.  AVcc is used for the
    //  reference and repeated sequence of conversions is performed on Channels A0,
    //  A1, A2, and A3. Each conversion result is stored in ADC12MEM0, ADC12MEM1,
    //  ADC12MEM2, and ADC12MEM3 respectively. After each sequence, the 4 conversion
    //  results are moved to A0results[], A1results[], A2results[], and A3results[].
    //  Test by applying voltages to channels A0 - A3. Open a watch window in 
    //  debugger and view the results. Set a breakpoint in the last line to see the 
    //  array values change sequentially.
    //
    //  Note that a sequence has no restrictions on which channels are converted.
    //  For example, a valid sequence could be A0, A3, A2, A4, A2, A1, A0, and A7.
    //  See the MSP430x1xx User's Guide for instructions on using the ADC12.
    //
    //
    //                 MSP430F149
    //            -----------------
    //           |                 |
    //   Vin0 -->|P6.0/A0          |
    //   Vin1 -->|P6.1/A1          |
    //   Vin2 -->|P6.2/A2          |
    //   Vin3 -->|P6.3/A3          |
    //           |                 |
    //
    //
    //  M. Mitchell
    //  Texas Instruments Inc.
    //  Feb 2005
    //  Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.21A
    //******************************************************************************
    
    #include <msp430.h>
    
    #define   Num_of_Results   8
    
    static unsigned int A0results[Num_of_Results];  // These need to be global in
    static unsigned int A1results[Num_of_Results];  // this example. Otherwise, the
    static unsigned int A2results[Num_of_Results];  // compiler removes them because
    static unsigned int A3results[Num_of_Results];  // they are not used
    
    int main(void)
    {
      WDTCTL = WDTPW+WDTHOLD;                   // Stop watchdog timer
      P6SEL = 0x0F;                             // Enable A/D channel inputs
      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_register(LPM0_bits + GIE);       // Enter LPM0, Enable interrupts
    }
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=ADC12_VECTOR
    __interrupt void ADC12ISR (void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
      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
    }
    
    
    
    
    这是官方的例子,你跑个试试看。另外确认电路没问题,比如用个电位器测个试试,连续变化下测量结果是怎么变的。