This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I want to get a timed interrupt every 10 milliseconds.
I set up the MSP430FR2355 to run at 16 MHz using the following code:
// Change DCO main frequency to 16 MHz from 1 MHz
__bis_SR_register(SCG0); // disable FLL
CSCTL3 |= SELREF__REFOCLK; // Set REFO as FLL reference source
CSCTL0 = 0; // clear DCO and MOD registers
CSCTL1 &= ~(DCORSEL_7); // Clear DCO frequency select bits first
CSCTL1 |= DCORSEL_5; // Set DCO = 16MHz
CSCTL2 = FLLD_0 + 487; // DCOCLKDIV = 16MHz
__delay_cycles(3);
__bic_SR_register(SCG0); // enable FLL
while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1)); // FLL locked
CSCTL4 = SELMS__DCOCLKDIV | SELA__REFOCLK; // set default REFO(~32768Hz) as ACLK source, ACLK = 32768Hz
// default DCOCLKDIV as MCLK and SMCLK source
CSCTL5 |= DIVM__2; // SMCLK = MCLK = DCO/2 = 16 MHz/2 = 8 MHz
SetupTimer2();
StartTimer2();
Then I have the following code to set up TimerB2:
void SetupTimer2()
{
// Timer B clocks per period
TB2CCR0 = 326; // PWM Period (Drive 100 Hz square wave on P5.0/TB2.1)
TB2CCTL1 = OUTMOD_7 | CCIE_1; // CCR1 reset/set; enable interrupt
TB2CCR1 = 163; // CCR1 PWM duty cycle (50%)
}
void StartTimer2(void)
{
// Start Timer 2 (TB2)
// 16-bit counter
// ACLK clock selection (32.768 KHz)
// Clock divider: 1
// UP counter mode (count up to 163)
// Clear the count and clock divider (TB2R)
// Disable interrupt
TB2CTL = CNTL__16 | TBSSEL__ACLK | ID_0 | MC__UP | TBCLR;
}
#pragma vector=TIMER2_B1_VECTOR
__interrupt void TIMER2_B1_ISR (void)
{
LED2_TOGGLE;
}
This code generates a 100 Hz (10 millisecond period) square wave on P5.0.
But the TIMER2_B1_ISR fires every 3.25 microseconds and toggles an LED, apparently due to the TBCCR1 / CCI interrupt.
How do I set it up such that I only receive the interrupt when the TB2 compare register reaches the TB2CL1 value?
Is the issue due to the TBCCR1 interrupt not being cleared?
Clearing the capture/compare interrupt worked!
I didn't see any similar examples in the MSP430Ware sample code, hence my confusion.
Thank you for your quick response.
**Attention** This is a public forum