Part Number: MSP430G2553
Tool/software: Code Composer Studio
every 1 second the timer will go into interrupt and the counter will increase by 1.
In this case, the value of the counter should be 60 in 1 minute. With the help of stopwatch, I measured 1 minute and stopped the program. The value of the counter was 54. Sensitive 1 second did not occur.
/***I created 1 second in the program as follows.***/
I used ACLK modules. its frequency is 12000 hz. The period in this case is 1/12000 seconds.
If I multiply 1/12000 seconds by 12000, I get 1 second. Everything is right up to here.
(I'm not sure after that). i continue. If I set TA0CCR0 to 12000, I would get 1 second.
1second=(1/12000)*TA0CCR0=(1/12000)*12000
If this is wrong, with which formula should I determine the CCR0 value?
#include <msp430.h>
/* every 1 secont counter ++*/
unsigned int counter=0;
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
/***SET UP ACLK ----> 12khz=12000hz ***/
BCSCTL1 &= ~XTS; //set ACLK
BCSCTL3 &= ~LFXT1S0;
BCSCTL3 |= LFXT1S1;
/***TA0 Set Up***/
TA0CTL |= MC_1 + TASSEL_1+TAIE ; //up mode(Up to TA0CCR0)-Source Select ACLK
/*** for 1second set up ***/
/* ACLK period 1/12000 second. *
* (1/12000).TA0CCR0=(1/12000)*12000=1s (1second) So,TA0CCR0 value must be 12000*/
TA0CCR0=12000;
__bis_SR_register( LPM3_bits+GIE); // only ACLK Available-General intterupt active
}
#pragma vector=TIMER0_A1_VECTOR
__interrupt void TA0_kesme_func(void)
{
switch (TA0IV){
case 2: break; //CCR1 not use
case 4: break; //CCR2 not use
case 10: // overflow - counter++
counter++;
break;
}
}