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.

关于MSP430F169的使用

我用MSP430的DAC输出一个锯齿波电压,然后用ADC进行单通道多次采样,可是这两部分进行初始化的时候都会对ADC12CTL0进行设置,会不会互有影响,下面是部分程序。

#include <msp430x16x.h>
#include "Config.h" //开发板配置头文件,主要配置IO端口信息
#include <stdio.h>

uint TEMP=0; //ADC值暂存变量
uchar count=0;

//***********************************************************************
// DAC初始化
//***********************************************************************

void DAC12_Init(void)
{
DAC12_0CTL |= DAC12CALON; //启动校验DAC
while((DAC12_0CTL & DAC12CALON) != 0){_NOP();}//等待校验完成

ADC12CTL0 = REFON + REF2_5V; // 参考电压为内部2.5v
DAC12_0CTL = DAC12AMP_5 + DAC12IR + DAC12LSEL_0;//控制寄存器设置,自动更新数据,内基准为满量程
DAC12_0CTL |= DAC12SREF_0;
DAC12_0CTL |= DAC12ENC; // 启动DAC模块(DAC12LSEL_0时此句可以省,这里设置为1)
DAC12_0DAT = 0x0000; //DAC初值为0,更新这个寄存器就可以更改DAC输出数据
}

//*************************************************************************
// ADC初始化程序,用于配置ADC相关寄存器
//*************************************************************************
void ADC_Init()
{
P6SEL|=0x01; //选择ADC通道
ADC12CTL0|= ADC12ON+ MSC + SHT0_2 + REF2_5V + REFON; //ADC电源控制开,16个CLK,内部基准2.5V
ADC12CTL1|= SHP + CONSEQ_2 + ADC12SSEL1 + ADC12SSEL0; //SMCLK做时钟源
ADC12MCTL0= SREF0 + INCH_0; //参考控制位及通道选择,这里选择通道0
ADC12IE|= 0x01; //中断允许
ADC12CTL0|= ENC; //使能转换器
}

//*************************************************************************
// ADC中断服务程序
//*************************************************************************
#pragma vector=ADC_VECTOR
__interrupt void ADC12ISR(void)
{uchar buf[10];
uchar j;
uint result[10];

result[count]=ADC12MEM0; //读取ADC转换值,存入暂存区
count++;
while(count>10)
{
count=0;
for(j=0;j<10;j++)
{
TEMP+=result[j]; //求和,10次转换的结果相加
}
TEMP=TEMP/10; //求平均值
//读取ADC转换值

sprintf((char*)buf,"%d\r\n",TEMP);
Print_Str(buf);

}
}

//*************************************************************************
// 主程序
//*************************************************************************

void main(void)
{ uchar buf[10];
uint i;
WDT_Init(); //看门狗初始化
Clock_Init(); //时钟初始化
Port_Init(); //端口初始化,用于控制IO口输入或输出

ADC_Init(); 
DAC12_Init(); //初始化DAC12 //初始化ADC配置

_EINT(); //使能中断

ADC12CTL0 |= ADC12SC; //开启转换
while(1)

for(i=300;i<1930;i=i+5) //连续转换,输出电压从小到大

// P5OUT &= ~BIT4; //DAC片选信号置低

DAC12_0DAT = i; //数据写入寄存器,写入激活DAC转换

delay_ms(5);//验证是否是阶梯型




}

  • 建议您参考下官网例程

    /* --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 - DAC12_0, Output Voltage Ramp on DAC0
    //
    //  Description: Using DAC12.0 and 2.5V ADC12REF reference with a gain of 1,
    //  output positive ramp on P6.6. Normal mode is LPM0 with CPU off.  WDT used
    //  to provide ~0.064ms interrupt used to wake up the CPU and update the DAC
    //  with software. Use internal 2.5V Vref.
    //  ACLK= n/a, SMCLK= MCLK= WDTCLK= default DCO ~ 800kHz.
    //  //* MSP430F169 Device Required *//
    //
    //               MSP430F169
    //            -----------------
    //        /|\|              XIN|-
    //         | |                 |
    //         --|RST          XOUT|-
    //           |                 |
    //           |        DAC0/P6.6|--> Ramp_positive
    //           |                 |
    //
    //  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 = WDT_MDLY_0_064;                  // WDT ~0.064ms interval timer
      IE1 = WDTIE;                              // Enable WDT interrupt
      ADC12CTL0 = REF2_5V + REFON;              // Internal 2.5V ref on
      DAC12_0CTL = DAC12IR + DAC12AMP_5 +DAC12ENC;  // Internal ref gain 1
    
      for (;;)
      {
        __bis_SR_register(CPUOFF + GIE);        // Enter LPM0, Enable interrupts
        DAC12_0DAT++;                           // Positive ramp
        DAC12_0DAT &= 0xFFF;                    //
      }
    }
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=WDT_VECTOR
    __interrupt void watchdog_timer (void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(WDT_VECTOR))) watchdog_timer (void)
    #else
    #error Compiler not supported!
    #endif
    {
        __bic_SR_register_on_exit(CPUOFF);      // Clear LPM0 bits from 0(SR)
    }