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.

MSP430F149使用P6口采集外部电压时受IO口电压影响,怎么解决??



P6口上电后就有2.7V左右电压。将外部待采集电压接入后外部电压受到IO口输出电压的影响改变实际电压。特别是当采集小电压(零点几伏)时,电压被拉高到1.6V左右。请问这问题该如何解决??感谢解答!!

  • 你好,你的io是怎么配置的?电路又是怎么样的?

  • void Port_Init()
    {
    P6DIR = 0x00; //设置IO口方向为输入
    P6OUT = 0xFF; //P6口初始设置为FF
    }

    这是我对P6口的初试。电路的话使用的是开发板,将输出为0-3V左右的太阳能电池板的正负极直接接入P6.0口和地来进行电压采集。

  • 这样配置是有问题的,建议参考官网的例程。

    /* --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, 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 CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.21A
    //******************************************************************************
    
    #include <msp430.h>
    
    int 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_register(CPUOFF + GIE);        // LPM0, ADC12_ISR will force exit
      }
    }
    
    // ADC12 interrupt service routine
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=ADC12_VECTOR
    __interrupt void ADC12_ISR (void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
        if (ADC12MEM0 < 0x7FF)
          P1OUT &= ~0x01;                       // Clear P1.0 LED off
        else
          P1OUT |= 0x01;                        // Set P1.0 LED on
        __bic_SR_register_on_exit(CPUOFF);      // Clear CPUOFF bit from 0(SR)
    }