Hello Guys,
I am trying to understand how the MSP430 timer works. I am running the sample code that comes from TI, and trying to play around with the number of counts. I understand the formula time(s) = counts/Frequency. This is why the sample code comes with a count of 50000, which turns into 50000/1.045Mhz = 0.5 seconds.
However, using this logic, if I want the interrupt to trigger every second, I should do count/1.045Mhz = 1 seconds -> count = 1.045e6 counts. I try this, and for some reason the LED does not blink every second. It blinks much faster.
Here is the code:
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= 0x01; // P1.0 output
TA0CCTL0 = CCIE; // CCR0 interrupt enabled
TA0CCR0 = 1045000; // 1 second?
TA0CTL = TASSEL_2 + MC_1 + TACLR; // SMCLK, upmode, clear TAR
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, enable interrupts
__no_operation(); // For debugger
}
// Timer0 A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR(void)
{
P1OUT ^= 0x01; // Toggle P1.0
}
How do I set the count to make it so the timer interrupt triggers every 1 second? or every 5 seconds, etc??
Thank you!!