Other Parts Discussed in Thread: MSP430F2013
Hi Everyone!
I am new to this MCU world. I have been trying out some examples in the book and have looked over some posts in this forum pertaining to timing.
I am using a MSP430F2013 and CCSv4 as my IDE.
I want to toggle LEDs with a period of 2s. I am trying to learn the ISR of TIMER_A and work it.
After I debug it to the MSP device, I do not see the LEDs toggling. In order to have it toggle anywhere near my desired amount, I have to reduce the TACCR0 value to something like 29 or so. Did I go wrong with my calculation?
I understand that ACLK has a freq of 32768Hz. After dividing it by ID_2 (=4), I get 8192Hz. So, I will have 2s*8192Hz= 16384 ticks in total, but I should put 16384-1=16383 into TACCR0.
The following is the code.
void main (void)
{
WDTCTL = WDTPW|WDTHOLD; // Stop watchdog timer
P1OUT = LED2; // Preload LED1 on, LED2 off
P1DIR = LED1|LED2; // Set pins with LED1,2 to output
TACCR0 = 16383; // Upper limit of count for TAR
TACCTL0 = CCIE; // Enable interrupts on Compare 0
TACTL = MC_1|ID_2|TASSEL_1|TACLR; // Set up and start Timer A
// "Up to CCR0" mode, divide clock by 4, clock from ACLK, clear timer
__enable_interrupt(); // Enable interrupts (intrinsic)
for (;;) { // Loop forever doing nothing
} // Interrupts do the work!
}
//----------------------------------------------------------------------
// Interrupt service routine for Timer A channel 0
//----------------------------------------------------------------------
#pragma vector = TIMERA0_VECTOR
__interrupt void TA0_ISR (void)
{
P1OUT ^= LED1|LED2; // Toggle LEDs
}
If my way of calculating the time period of the toggling is wrong, please let me know if there is a better way. Also, is there a different between the time period of the LED toggle to that of the TIMER? I was reading the text, and it got confusing.
thanks!
UE