Quantcast
Channel: MSP 低功耗微控制器论坛 - 最近的话题
Viewing all articles
Browse latest Browse all 3634

MSP430f149捕获10KHZ的频率

$
0
0


#include "msp430f149.h"
#include"oled1.h"
//#include"in430.h"

#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long

static unsigned int new_cap,old_cap,diff_cap,aver_cap,index,count=0,t,num;
static unsigned int diff_array[16],cap_array[16];

void main( void )
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT

LCD12864_Init(); //初始化时钟

P1SEL |= BIT1;
P2SEL |= BIT0;
P2SEL |= BIT0;
CCTL0 = CM_1+SCS+CAP+CCIE;
TACTL = TACLR+TASSEL_2+MC_2;+TAIE;
_EINT();

while(1)
{
lcd_show_long_num(6,0,1,3,1,100000,t);
}
}

// Timer A0 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A0 (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMERA0_VECTOR))) Timer_A0 (void)
#else
#error Compiler not supported!
#endif
{
new_cap=TACCR0;
num++;
t = 65536*count+new_cap-old_cap+1;
lcd_show_long_num(6,0,5,3,1,100000,t);
diff_cap=new_cap-old_cap;
cap_array[index]=new_cap;
diff_array[index++]=diff_cap;
aver_cap+=diff_cap;
old_cap=new_cap;
if (index==16)
{
aver_cap/=16;
index=0;
}
/* if(num==2)
{
num=0;
_DINT();
}*/
}

// Timer_A3 Interrupt Vector (TAIV) handler
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A1(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMERA1_VECTOR))) Timer_A1 (void)
#else
#error Compiler not supported!
#endif
{
switch( TAIV )
{
case 10: count++; // Timer_A3 overflow
break;
default: break;
}
}

以下标注内容为 一位TI员工的解答:

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

楼主,

    其实你可以使能定时器的溢出中断,在TAR到达0xFFFF的时候将一个计数变量加1,比如count++;,当第二个捕捉中断到来之后做一个运算:

(65535-第一次捕捉的数值)+65535*count+第二次捕捉的数值

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

以上标注内容为 一位TI员工的解答:

下面是我发的疑问:

        由于CCR0的中断优先级大于定时器溢出中断(定时器中最低的中断),,所以即使定时器溢出也不会进入定时器溢出中断使得count++,因为我CCRO一直是运行,


Viewing all articles
Browse latest Browse all 3634

Trending Articles