Hi,
I am using msp430F5528 in my project. I want to use two timers TIMER_A0 and TIMER_B0 simultaneously. I am using timer_A0 with 2ms interrupt, and I have implemented delay_100ms() using timer_B.
I see issue while using delay_100ms() i.e. Timer_B0, I need to stop Timer_A0 before using delay_100ms().
Could you please explain me the reason?
Do you have any sample code of using multiple timers together?
Main()
{
[ --- -]
//Timer A0 init
TA0CCR0 = 66 ; // 2 ms
TA0CCTL0 = CCIE; // Enable Timer interrupt
TA0CTL = TASSEL__ACLK + MC__STOP | TACLR; // ACLK, stopped
While(1) {
// start timer A0
TA0CTL |= MC__UP;
[ ---- ]
//TA0CTL &= ~MC_3; // stop timer_A0 ?????
// implemented delay using timer_B0
Delay_100ms();
}
}
void Delay_100ms(void)
{
TB0CCTL0 &= ~CCIFG; // reset CCIFG Interrupt Flag
TB0CCTL0 = CCIE; // TBCCR0 interrupt enabled
TB0CTL = TBSSEL_1 + MC_1 + TBCLR; // Timer A select, clock source ACLK, count up to TACCR0, activate Interrupt Request
TB0CCR0 = 3277; // 100ms
__bis_SR_register(LPM0_bits + GIE);
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TickTimerIsr(void)
{
TA0CCTL1 ^= CCIS0; // Create SW capture of CCR1
//count = TA0CCR1; // Save result
TA0CCTL1 ^= CCIS0; // Re-enable capture on CCR1
LPM0_EXIT; // exit LPM
__no_operation();
}
#pragma vector=TIMER0_B0_VECTOR
__interrupt void Timer0_B0_ISR(void)
{
TB0CCTL0 &= ~CCIE; // TBCCR0 interrupt disable
__bic_SR_register_on_exit(LPM0_bits + GIE); // Clear LPM0 bits and GIE
}
Thanks
-rajib