簡體   English   中英

MSP430 Timer_A-寄存器的比例

[英]MSP430 Timer_A - scale of a register

在CCS中對MSP430進行編程

使用Timer_A,ACLK和他的中斷使LED閃爍(現在閃爍-長時間被撕裂-相同時間打開)。

此代碼閃爍導致2秒鍾的延遲。 問題是寄存器TA1CCR0的最大值為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;
}

如何計算1秒中斷的秒數。

1)將中斷初始化為每秒發生一次,然后重新加載其定時器/計數器寄存器

2)將全局變量設置為延遲秒數:

int delaySeconds = 10;

3)內部中斷功能

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

我認為中斷功能在退出之前還需要清除time1中斷掛起標志

在MSP430上,可以使用UCSCTL5寄存器中的DIVA字段來減慢ACLK,還可以通過TAxCTL和TAxEX0寄存器中的ID和IDEX字段來進一步分頻定時器的時鍾輸入。

將計時器輸入分頻為16 Hz,您最多可以計數4096秒。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM