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

msp430g2553捕获中断只进入一次,怎么回事?

本人写了个程序,想看看捕获功能的计数值,即每次捕获时TA1CCR1的值是多少,还没写测频函数。.程序的功能是用TA0定时模块产生pwm的输出信号,然后用TA1模块进行捕获,但是很奇怪,程序运行时只进入了一次中断,而且TA1CCR1的值为0,不知为何,按照逻辑不应该是不断的产生捕获终端,计数值应该是1000才对吧,请各位大神帮忙看看程序出了什么问题,可能注释也有不对,欢迎更正。

//P1.6 pwm输出,P2.1捕获

int flag=0;
unsigned int temp;
char data[15] = {0x00};
void main()
{
WDTCTL = WDTPW+WDTHOLD; //stop WDT
TA0CTL = TASSEL_2+MC_1+TACLR; //选择smclk,up to ccr0
TA0CCTL1 |= OUTMOD_7; 
CCR0 = 2000; //pwm 周期,频率1000000/2000=500HZ
CCR1 = 1000; //占空比50% 

TA1CTL = TASSEL_2+MC_1+TACLR; //选择smclk,up to ccr0
TA1CCTL1 |= CM_3+SCS+CAP+CCIE;//捕获设置,上升沿下降捕获,同步,中断使能

P1SEL |= BIT6;
P1DIR = BIT6; //P1.6 output,pwm的输出pin
P2SEL |= BIT1; //P2.1作为捕获输入脚 
//_BIS_SR(GIE);
_EINT();
while(1)
{while(flag){_DINT();flag=0;temp = TA1CCR1; //保存计数值/*sprintf(data,"%u",temp1);SendString(data);SendString("\r\n");注释部分为串口打印到电脑端查看TA1CCR1的值*/_EINT();}
}
}

#pragma vector=TIMER1_A1_VECTOR
__interrupt void Timer_A1(void)
{TA1CTL &= ~CCIFG;switch(TA1IV){case 2:flag = 1;break;case 4:break;case 10:break;}return;
}
Lina Lian:

long huang2,

TI MSP430 code example中有个类似的例程,你可以参考一下。具体见附件,说明见下!

//******************************************************************************// MSP430G2xx3 Demo – Timer_A0, Normal Timer Mode Input Period and Dutycycle// measurement// Description: This code example implements input capture in single capture// mode using TimerA in normal timer mode. TA1.1 is configured to output PWM// of 25% dutycycle, that is used as capture input at TA0.1. TA0.1 is// configured as timer input capture that is triggered by both the rising and// the falling edges. An external connection between TA1.1 and TA0.1 is// required in this example. Rising and Falling edges are captured and the// dutycycle is computed. If the measured dutycycle is != 25%, then LED on// P1.0 is set.//// ACLK = LFXT1 = 32kHz crystal ; SMCLK = MCLK = 8 MHz;//// MSP430F51x2// —————–// /|\| XIN|-// | | | 32kHz// –|RST XOUT|-// | |// | P1.2/TA0.1|<– CCI1A <-|// | P2.1/TA1.1|–> CCR1 –>|// | |// | P1.0|–> LED "ON" when dutycycle != 25%// | |

Lina Lian:

回复 Lina Lian:

long huang2,

建议你把对应例程都下载下来吧,或者你已经安装了MSPWare, 具体方法如下:

1. 安装了MSPWare, 见此路径: C:\ti\msp430\MSPWare_2_21_00_39\examples\devices\MSP430G2xx

2. 直接下载对应code example,到TI官网, 搜索对应型号,进入产品页,Tools&software, 下可以看到。其他型号,也可以以类似的方法找。

NamePart#Type

MSP430G2x53, MSP430G2x33, MSP430G2x13, MSP430G2x03 Code Examples (Rev. F)  (ZIP 471 KB )    3,252 views, 18 May 2015  

赞(0)
未经允许不得转载:TI中文支持网 » msp430g2553捕获中断只进入一次,怎么回事?
分享到: 更多 (0)