MSP430 Timer_A - 寄存器的比例

时间:2015-11-27 14:20:49

标签: c timer msp430

在CCS中对MSP430进行编程

使用Timer_A,ACLK和他的中断使LED闪烁(现在只是闪烁 - 同样长时间关闭 - 同时打开)。

此代码闪烁导致2秒延迟。存在寄存器TA1CCR0可以是max 0xFFFF = 65535(ACLK为2秒)的问题。对于我的应用(闪烁的LED只是一个例子),我需要从1秒到999秒的刻度。 (代码中的第6-7行)。我怎样才能做到这一点?有可能吗?

#include <msp430.h> 
#include <msp430f6736.h>

void CfgTA(unsigned long delayCycles)
{
    int t2=2;  // must be variable from 1 to 999
    t2=delayCycles*t2;
    TA1CCTL0 |= CCIE;   //Enable Interrupts on Timer
    TA1CCR0 = t2-1;     //Number of cycles in the timer
    TA1CTL |= TASSEL_1 | MC_1;  //ACLK , UP mode

}

void ledblink()
{
    //LED config
     P4DIR |= BIT6;
     P4OUT &= ~BIT6;

     CfgTA(32768);  //Timer configuration to blink every 1 sec
    while (1)
    {
        _bis_SR_register(LPM3_bits + GIE); //Enter Low Power Mode 3 with interrupts
    }

}


#pragma vector=TIMER1_A0_VECTOR
__interrupt void Timer_A0(void)
{

   P4OUT ^= BIT6;   // Swapping on/off LED
}


int main(void) {
    WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer

    ledblink();

    return 0;
}

2 个答案:

答案 0 :(得分:1)

如何计算1秒钟中断的秒数。

1)初始化中断每秒发生一次并重新加载其中断。定时器/计数器寄存器

2)将全局变量设置为延迟的秒数:

int delaySeconds = 10;

3)在中断函数内

static int count =0;
count++;
if( count >= delaySeconds )
{
    count = 0;
    P4OUT ^= BIT6;   // Swapping on/off LED
}

我认为中断函数在退出之前还需要清除time1中断挂起标志

答案 1 :(得分:1)

在MSP430上,可以使用UCSCTL5寄存器中的DIVA字段减慢ACLK,并且可以使用TAxCTL和TAxEX0寄存器中的ID和IDEX字段进一步分频定时器的时钟输入。

当定时器输入分频为16 Hz时,您可以计算最多4096秒。