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.

Timers and Interrupts

I'm new to the MPS430 and I'm trying to get started with timers.

I'd like to measure the time between two rising edges of a signal connected to P2.0 with timer A1.

I also have to blink a bunch of LEDs with timer A0.

This is what I have to initialize the timers:

  P2DIR &= ~BIT0;     //P2.0 Input
  P2SEL |= BIT0;        / Set P2.0 to Primary Peripheral function

  TA1CCTL1 = CM_1 + SCS + CCIS_0 + CAP + CCIE;   //Capture on rising edge of P2.0
  TA1EX0 = TAIDEX_3;  //Divide clock input by 4
  TA1CTL = TASSEL_2 + MC_2 + ID_3;   //SMCLK, continuous, divide by 8
 
  TA0CCTL0 = CCIE;                 // CCR0 interrupt enabled
  TA0EX0 = TAIDEX_3;             //Divide clock input by 4
  TA0CTL = TASSEL_2 + MC_2 + ID_3; // SMCLCK div 8, Continuous
  __enable_interrupt();

This timer A0 interrupt to flash the LEDs

#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)

{ //flash leds here }

and this one for timer A1

#pragma vector=TIMER1_A0_VECTOR
__interrupt void Timer0A1(void)
{
    TA1CTL |= TACLR;
    P1OUT ^= 0x01; //just toggling an LED for test
}

I'm confused about what pragma vector to use. The datasheet talks about timer a and b, but the vectors are timer0 and timer1 with Ax.

Am I configuring timer A1 correctly to trigger a capture on the rising edge of P2.0?

What pragma vector should I use for A1, and what value of TA1IV should I check in the interrupt to know an edge occurred?

Thanks in advance,

Paul.

  • Hi Paul,

    What device are you working with? Thanks,

  • I'm using a MSP-EXP430F5529 development board.

    Thanks,

    Paul.

  • Hi Paul,

    Here you have set up Timer1 A1:

      TA1CCTL1 = CM_1 + SCS + CCIS_0 + CAP + CCIE;   //Capture on rising edge of P2.0
      TA1EX0 = TAIDEX_3;  //Divide clock input by 4
      TA1CTL = TASSEL_2 + MC_2 + ID_3;   //SMCLK, continuous, divide by 8

    So the correct Pragma vector is:  #pragma vector=TIMER1_A1_VECTOR

    For the other timer that you are using, you set up Timer0 A0:

      TA0CCTL0 = CCIE;                 // CCR0 interrupt enabled
      TA0EX0 = TAIDEX_3;             //Divide clock input by 4
      TA0CTL = TASSEL_2 + MC_2 + ID_3; // SMCLCK div 8, Continuous

    So the correct pragma vector is :  #pragma vector=TIMER0_A0_VECTOR and not TIMER1_A0_VECTOR as you have.

    The way it works is the following:

    You have two timer modules (A and B). For timer A, you have three independent timers A0, A1 and A2. Now, each of these timers (A0 and A1) have 7 "blocks" and the naming convention is TAxCCTLn, here is note from the Users guide (SLAU208H):

    There may be multiple instantiations of Timer_A on a given device. The prefix TAx is used,where x is a greater than equal to zero indicating the Timer_A instantiation. For devices with

    one instantiation, x = 0. The suffix n, where n = 0 to 6, represents the specific capture/compare registers associated with the Timer_A instantiation.

     

    I recommend that you look at the code examples available on the TI website for MSP430F55xx:

    http://focus.ti.com/mcu/docs/mcuflashtools.tsp?familyId=342&sectionId=95&tabId=1538

     

     

  • Thanks for the explanation. The only other thing was to set the TAIE bit in TA1CTL to get an interrupt on overflow too.

    I use the TIMER1_A1_VECTOR interrupt and check TA1IV. If it's 2 I can get the timer value from TA1CCR1.

    If it is 14 the frequency is either too low or there are no pulses.

    The MSP430x5xx User's Guide is very useful, but the software documentation is very confusing.

    Thanks,

    Paul.

  • Paul B said:
    the software documentation is very confusing

    Which one? Usually, there's only the copyright notice and maybe a few useless comments scattered across the source code - if at all..

    Yes, the documentation of the example software is, well, 'sparse' is an understatement at least.

    You're definitely not the only one who's lost with the example codes.

**Attention** This is a public forum