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.

use of multiple TIMERS simultaneously in msp430

Other Parts Discussed in Thread: MSP430F5528

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

  • rajib mahapatra said:
    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.

    You don't need to "waste" another timer to implement 100ms delay. Use timer_a0 for both - 2ms tick and delay functions.

  • There is a simple reason why you have to stop TimerA0 before you can make a delay with TimerB0 using LPM: The TimerA0 ISR also exits LPM.
    LPM0_EXIT (as used in the TimerA0 ISR) is an alias for __bic_SR_register_on_exit(LPM0_bits).

    BTW: if you add GIE to the __on_exit instruction, this will disable all interrupts when the ISR exits. So after TimerB0-Interrupt, no more interrupts will be handled unless main sets GIE again.

**Attention** This is a public forum