Part Number: MSP430G2553
I want to use timer to generate interrupt every 1 microsecond. Setup timer with following code:
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = F_CPU / 1000000; // F_CPU = 1MHz or 8MHz or 16MHz
TACTL = TASSEL_2 + MC_1; // SMCLK, Up to CCR0
Inside ISR I increment counter variable and toggle Pin1 when this variable reach 1000, which should give 1 millisecond.
cnt += 1;
if(cnt == 1000)
{
cnt = 0;
P1OUT ^= 0x01;
}
Measuring output pin with oscilloscope and it gives period 1.7 ms. However if I set timer to generate interrupt e.g. every 1000 uS and increment variable up to 1, then period is 1.0 ms. Is there reasonable explanation and sometging I could improve in code?