Other Parts Discussed in Thread: MSP430F1611
Hi everybody,
I have a question about the Timer A in my MSP430F1611. I am using this timer as a counter and using the next example to start knowing how it works:
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= 0x01; // P1.0 output
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = 1000-1;
TACTL = TASSEL_1 + MC_1; // ACLK, upmode
_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/ interrupt
}
// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
P1OUT ^= 0x01; // Toggle P1.0
CCR0 += 1000-1; //add offset to CCR0
}
I have three questions that i couldn't solve with the help of this forum or google...:
1. What does it means when it sais "add offset to CCR0"? Maybe that when the interrupt is executed, at the end we start again to count? Am i wrong? Please tell me the meaning of that line.
2. I need to know the formula to know the number that i must put into the CCR0 register to count. In the help of this code (I only added the last line about the offset to make the question 1) i found this:
Description: Toggle P1.0 using software and the TA_0 ISR. Timer_A is
// configured for up mode, thus the timer overflows when TAR counts
// to CCR0. In this example, CCR0 is loaded with 1000-1.
// Toggle rate = 32768/(2*1000) = 16.384
// ACLK = TACLK = 32768Hz, MCLK = SMCLK = default DCO ~800kHz
Is the formula in bold the one that i need to use to select the number into the CCR0 register?. I don't understand very well this formula. There is a factor 2 at the denominator... What does it mean?. How is the formula to find the number i am looking for? In my final application i will use ACLK = MCLK= 8MHz and need to trigger the interruption every 5 seconds... Can you help me with this calculation?
3. And the last question: why the example use CCR0 = 1000-1; I suppose that is because the counter starts in zero and must substract one count... Am i right?
Thank you very much for your help in advance.
Regars
Alejos