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.

msp430f5438 capture problem

sir im doing capture interrupt program but im not able to take forward it due to some problems

and the program goes like this

#include "msp430x54xA.h"
int a;
int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  P1DIR |= 0x03;                            // P1.0 output
  P8DIR |= 0x00;
 TA1CCTL0 = CCIE + CM_1+ CAP + CCIS1 ;                          // CCR0 interrupt enabled
 // TA1CCTL0 ^= CCIS0;
  //TA1R=0;
  P1OUT=0x00;
  TA1CTL = TASSEL_2 + MC_2 +TACLR;         // SMCLK, contmode, clear TAR
//  while(1)
//  {
//if(P8IN == 0x00)
//    {
//  P1OUT ^= 0x01;                            // Toggle P1.0
//    }  
//  }
 __bis_SR_register(GIE);       // Enter LPM0, enable interrupts
  __no_operation();                         // For debugger
}

// Timer A0 interrupt service routine
#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR(void)
{
    
  P1OUT ^= 0x01;                            // Toggle P1.0
          
 a=TA1CCR0;
}

i want to capture the timer value when the pin8.5 goes high (rising edge) but when  i am giving 3.3 volts externally to pin8.5 its not entering the interrupt

can u please give the appropriate solution so that i can proceed further

  • Hi,

    First of all, all the things I am going to tell you are available on User guide, and probably, better explained.

    you want to use the capture/compare function of this pin, but you do not configure it. Each pin has, at least, two possible configuration, as a general purpose input/output or as special function, ADC, UART, timers, etc. So,since you want to use for a special function, for selecting  the capture/compare function:

    P8SEL |= BIT5, during pin configuration.

     Moreover, the timer A1 has two possible ports. To use port 8, during timer configuration you have to add:

     TA1CCTL0 = CCIE + CM_1+ CAP + CCIS1 + CCIS_1 ;

    These two points are the more evident for me, check it, bu it could be more fails I have not seen.


  • Thank you Is T da S, your inputs helped me now im able to capture the timer value 

    TA1CCTL0 = CCIE + CM_3+ CAP + CCIS_1 ;

    I want to capture for both rising and falling edge how it acually works 

    my doubt is firstly it captures rising edge and then falling edge r vice versa?

    i want to calculate duration of the pulse being high please help me in this issue

  • Hi,

    I don not know what your time/accuracy requirements are, but right now, without a deeper knowledge about your project, there are two possibilities:

    1) Configure the timer to capture on rising edge, and when the  ISR starts, save the value and configure the timer to falling edge. So, next edge will be a falling edge and the difference of time between saved and current value will be the signal duration on high level. One problem of this solution is the requirement  of adding a mechanism to detect a overflowing of TA1R register.

    2) Let the configuration that you have posted now (interrupt on both edges), save the value in each ISR and calculate difference between current value and saved value (except in the first interurpt of course) and check the value of the input, reading CCI. If CCI is 0, it implies that the last interrupt was a falling edge, and the difference calculated is the duration of high level. I think that the same problem of the first option occurs, and we have to check exactly if CCI reading during ISR gives you the correct value, I have never tested on this way.

**Attention** This is a public forum