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.

MSP430F5438A: Capture program issue

Part Number: MSP430F5438A


Hi team,

Here're some issues from the customer may need your help:

Q1.Timer B uses the capture function and is set up as rising edge capture. The following are two ways to write the interrupt program:

A.

#pragma vector = TIMER0_B0_VECTOR
__interrupt void timer_b0_isr(void)
{
   if(  TB0CCTL0 & CCI  ){ //low level captured

      //Process
      TB0CCTL0 &= (~CCIFG) ; //clear interrupt flag

  }

}

B.

#pragma vector = TIMER0_B0_VECTOR
__interrupt void timer_b0_isr(void)
{
      //process
      TB0CCTL0 &= (~CCIFG) ; //clear interrupt flag

}

If set to only the rising edge capture, they can no longer judge it in the interrupt program and process it directly, i.e. you don't have to use the "if( TB0CCTL0 & CCI )" statement. Is that right?

Q2. When Timer B is selected for pulse count, P4.7 is used as the clock input and P4.0 is used as the input square wave as the capture signal. When TBSSEL = 0, an external clock input is selected. Is the count based on the rising or falling edge of the external signal?

Could you help check this case? Thanks.

Best Regards,

Cherry

  • Q1: If you're only triggering on one of the edges, you don't need to check CCI. Arguably you Shouldn't check CCI (in this case) since you're really interested in the event, not the pin state. (This distinction is unlikely to matter with a 156:1 ratio, but it could in tighter spots.)

    Q2: The timer counts at the rising edge of the input clock [Ref (e.g.) User Guide (SLAU208Q) Fig 18-3]

    Unsolicited:

    >      TB0CCTL0 &= (~CCIFG) ; //clear interrupt flag

    You should not do this (i.e. remove this line). The CCIFG (for CCR0 only) is auto-cleared on entry to the ISR [Ref User Guide Sec 18.2.6.1], so if it's on at this moment it indicates another event which you don't want to lose. (Here again, this is unlikely to matter in your case but it might someday.)

  • Hi Bruce,

    Thanks for your help.

    The results of the customer test are as follows:

    After the count starts, the first jump edge is not counted and the second jump edge starts counting. If the first jump edge is the rising edge, then the subsequent counts are the falling edge count. If the first transition edge is the falling edge, then the subsequent count is the rising edge count.

    Could you help check this? Thanks.

    Regards,

    Cherry

  • I tried a similar experiment using an F5529 (I don't have an F5438A) and TA1CLK (no access to P7.7/TB0CLK). I found that the counter counts on a rising edge.

    Specifically this program generates a single rising edge on P1.2, which is patch-wired to P1.6 configured as TA1CLK, and TA1R counts to 1 (LED lights).

    It's possible that the F5529/F5438A, or TA1/TB0, act differently in this regard, but it seems more probable that your results are being influenced by code which you haven't posted.

    ///
    #include <msp430.h>
    #define HZ  1000000UL
    int main(void)
    {
        WDTCTL = WDTPW | WDTHOLD;   // stop watchdog timer
        P1OUT  &= ~BIT0;            // Launchpad LED, initially off
        P1DIR  |= BIT0;
        //  P1.2 is an ordinary GPIO, patched to P1.6
        P1OUT  &= ~BIT2;            // P1.2 output, initially low
        P1DIR  |= BIT2;             //  (patched to P1.6)
        //  P1.6 is TA1CLK, fed from P1.2
        P1SEL  |= BIT6;             // P1.6 as TA1CLK
        TA1CTL = TASSEL_0 | ID_0 | MC_2 | TACLR; // TA1CLK/1, Continuous [,clear]
        __delay_cycles(HZ/2);       // Dawdle for a half-second
        P1OUT  |= BIT2;             // Rising edge to TA1CLK
        __delay_cycles(10);         // Allow for wire delay
        if (TA1R != 0u)             // If it ticked,
            P1OUT |= BIT0;          //  light LED
        while (1)
        {
            LPM0;
        }
        /*NOTREACHED*/
        return 0;
    }
    

**Attention** This is a public forum