TI中文支持网
TI专业的中文技术问题搜集分享网站

msp430f149中ad采集的问题

为什么我进行在线调试的时候,在Register栏中查看MEM0,MEM1,MEM2,MEM3都是0000,这说明AD没有采样成功而且采样的值也没有写入MEMX寄存器吗?我该怎么解决,求告知,谢谢!!下面是我的程序:

#include<msp430.h>
#define Num_of_Results 32
#define ulong unsigned long
#define uint unsigned int#define uchar unsigned char
ulong caltmp[4];
static uint results[Num_of_Results]; //保存ADC转换结果的数组
uint i;
/********************************************
函数名称:Init_ADC
功 能:初始化ADC
参 数:无
返回值 :无
********************************************/
void Init_ADC(void)
{
P6SEL |= 0x0f; // 使能ADC通道
ADC12CTL0 = ADC12ON+SHT0_15+MSC; // 打开ADC,设置采样时间
ADC12CTL1 = SHP+CONSEQ_3+CSTARTADD2; // 使用采样定时器,脉冲模式+单通道多次转换
ADC12MCTL0=INCH_0;
ADC12MCTL1=INCH_1;
ADC12MCTL2=INCH_2;
ADC12MCTL3=INCH_3+EOS; //以EOS结束此次转换
ADC12IE = 0x0f; // 使能ADC中断
//ADC12IV=ADC12IV_ADC12IFG3;
ADC12CTL0 |= ENC; // 使能转换
ADC12CTL0 |= ADC12SC; // 开始转换
// _BIS_SR(LPM0_bits + GIE);
for(i=0;i<50;i++)
_NOP();
_EINT();
//_BIS_SR(LPM0_bits + GIE);
}

函数名称:ADC12ISR
功 能:ADC中断服务函数,在这里用多次平均的
计算P6.0口的模拟电压数值
参 数:无返回值 :无
********************************************/
#pragma vector=ADC_VECTOR
__interrupt void ADC12ISR(void)
{
//while((ADC12CTL1&0X01)==1); caltmp[0]=ADC12MEM0;
caltmp[1]=ADC12MEM1;
caltmp[2]=ADC12MEM2;
caltmp[3]=ADC12MEM3;
}

/******************************************************************************************************************/

主程序

#include <msp430.h>
#include"AD_BAT.c"

#define uint unsigned int#define uchar unsigned char
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
BCSCTL1 &= ~XT2OFF; //打开XT2高频晶体振荡器
uchar i,j;
do
{
IFG1 &= ~OFIFG; //清除晶振失败标志
for (i = 0xFF; i > 0; i–); //等待8MHz晶体起振
}
while ((IFG1 & OFIFG)); //晶振失效标志仍然存在?(判断晶振是否起振)
BCSCTL2 |= SELM_2 + SELS; //MCLK和SMCLK选择高频晶振
TACTL |= TASSEL_2 + ID_3; //计数时钟选择SMLK=8MHz,1/8分频后为1MHz
//_EINT();
Init_ADC();
for(j=0;j<100;j++)
_NOP();

return 0;
}

gaoyang9992006:

/* --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, Sequence of Conversions (non-repeated)
//
//Description: This example shows how to perform A/D conversions on a sequence
//of channels. A single sequence of conversions is performed - one conversion
//each on channels A0, A1, A2, and A3. Each conversion uses AVcc and AVss for
//the references. The conversion results are stored in ADC12MEM0, ADC12MEM1,
//ADC12MEM2, and ADC12MEM3 respectively and are moved to 'results[]' upon
//completion of the sequence. Test by applying voltages to pins A0, A1, A2,
//and A3, then setting and running to a break point at the "_BIC..."
//instruction in the ISR. To view the conversion results, open a watch window
//in debugger and view 'results' or view ADC12MEM0, ADC12MEM1, ADC12MEM2, and
//ADC12MEM3 in an ADC12 SFR window.
//This can run even in LPM4 mode as ADC has its own clock
//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>static unsigned int results[4];// Needs to be global in this example// Otherwise, the compiler removes it// because it is not used for anything.int main(void)
{WDTCTL = WDTPW+WDTHOLD;// Stop watchdog timerP6SEL = 0x0F;// Enable A/D channel inputsADC12CTL0 = ADC12ON+MSC+SHT0_2;// Turn on ADC12, set sampling timeADC12CTL1 = SHP+CONSEQ_1;// Use sampling timer, single sequenceADC12MCTL0 = INCH_0;// ref+=AVcc, channel = A0ADC12MCTL1 = INCH_1;// ref+=AVcc, channel = A1ADC12MCTL2 = INCH_2;// ref+=AVcc, channel = A2ADC12MCTL3 = INCH_3+EOS;// ref+=AVcc, channel = A3, end seq.ADC12IE = 0x08;// Enable ADC12IFG.3ADC12CTL0 |= ENC;// Enable conversionswhile(1){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
{results[0] = ADC12MEM0;// Move results, IFG is clearedresults[1] = ADC12MEM1;// Move results, IFG is clearedresults[2] = ADC12MEM2;// Move results, IFG is clearedresults[3] = ADC12MEM3;// Move results, IFG is cleared__bic_SR_register_on_exit(LPM0_bits);// Clear LPM0, SET BREAKPOINT HERE
}给你个参考,跟你的非常类似了,你看看你的是咋回事。你用了中断,但是你中断的名字好像定义的都不大对

user5767411:

回复 gaoyang9992006:

您好,请问为什么我编译这个程序时会有一个警告,就是results 定义了但未被使用

user5767411:

回复 gaoyang9992006:

您好,请问为什么我编译这个程序时会有一个警告,就是results 定义了但未被使用

赞(0)
未经允许不得转载:TI中文支持网 » msp430f149中ad采集的问题
分享到: 更多 (0)