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.

Timer A, ACLK, continuous mode, LPM3

Hey guys,

I'm trying to get a simple LED to flash on/off following Timer A saturation with LFXT1 sourcing ACLK in LPM3.


I've written this bit of code which manages to turn the LED on, however LED does not turn off and therefore does not blink as hoped...I am resetting the TAIFG in my interrupt routine so I'm not sure where I'm going wrong.

Any help would help would be greatly appreciated...

  • code below...

    #include "msp430.h"

    void main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                       // Stop WDT

      BCSCTL1 = DIVA_3;                                                // set clock module to 32KHz
      BCSCTL3 = XCAP_3;

      TACTL = TASSEL_1 + MC_2 + ID_0 + TAIE;        // ACLK, continuous mode, int enable

      P1DIR |= BIT0;                                                           // LED setup
      P1OUT |= BIT0;

      _BIS_SR(LPM3_bits + GIE);                                   // LPM3

      while(1)                                                                       // loop & wait for interrupts
      {}
    }

    #pragma vector=TIMER0_A0_VECTOR                // Timer A0 interrupt service routine
    __interrupt void Timer_A (void)
    {

        TACTL &= ~TAIFG;                                                 // reset flag
        P1OUT ^= BIT0;                                                     // Toggle P1.0
    }

  • Try defining TIMER0_A1_VECTOR instead of TIMER0_A0_VECTOR.

    TIMER0_A0_VECTOR is only triggered by TA0CCTL.CCIFG, TIMER0_A1_VECTOR is triggered by all other interrupt flags on TimerA0.

  • Hi Robert,


    Thanks for your reply.

    Unfortunately that did not work...

  • Hi again,

    Thanks for the tip, it's working OK now...

    Bizarrely, the LED stayed on constantly for about 20 minutes and then suddenly it started to blink normally.  I wonder, could this have something to do with using the crystal for the first time and needing to stabilize? 20 minutes seems a long time...


    Anyway, I've tried various divider settings for ACLK and Timer and it now seems to be behaving correctly.

    Thanks again.

  • You state that clock module is 32Khz, but as you are dividing it by 8 aclk is really 4Khz

    #define DIVA_3              (0x30)   /* ACLK Divider 3: /8 */

    Nothing takes 20minutes, your overflow counter IRQ takes 16seconds in this  case.
    BUT you have to use TA0.1 VECTOR!!!
    as TA0.0 has its own vector and a overflow does not jump to it.

    As you have NOT set up any other CCR register and enabled their IRQs,
    overflow-IRQ  thanks to TAIE being set is the ONLY IRQ you will get (at 16seconds interval)

  • Hi Tony,

    Thanks for the reply.

    Yes I was/am aware of all that you have said...and have resolved the issue.

    The LED was prob staying on forever since the interrupt vector was not correct. All working fine now.

    Thanks again.

**Attention** This is a public forum