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.

CCS/msp430g2553: Starting timer from pin

Part Number: MSP430G2553
Other Parts Discussed in Thread: MSP430G2553

Tool/software: Code Composer Studio

Greetings

I am currently trying to figure out all the possibilities of the timer module of msp430g2553. I would like to start the timer directly from an input pin. At the moment I am using an interrupt to start the timer with TACTL. I was wondering if starting the timer could be possible without any code, directly from a pin.

Code at the moment:

#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
   TACTL |= MC_1;
}

  • The MC bits can be changed only from software.

    But what is the actual problem you're trying to solve?
  • The problem itself is not that difficult. A pulse with measured length must be triggered after a falling edge of an input signal. I was hoping to bypass software as much as possible to avoid any chance of timing errors due to program execution.
  • When you use a timer output for the pulse, its length can be easily controlled.

    Is the time between the input edge and the start of the pulse important?
  • Thank You for the answers!

    The time between the edge and the start of the timer is important. I suppose, the right answer would be to use correct priorities of interrupts so nothing else will affect the triggering function. About using the timer output, I know that I the pin can be connected to timer with P1SEL command, but I have been struggling with single pulse output. I have only achieved flashing or constantly on states with that. Do I need to experiment with TACTL |= TAIE and the switch case interrupts?

  • In compare mode, the CCR output is changed when the programmed time is reached. At the same time, an interrupt can be triggerd; use this to stop the timer.
  • For the past few days, I have tried to study the CCR interrupt, but only achieved desired result with following declarations:

      P1DIR |= BIT6;            //P1.6 output
      P1SEL |= BIT6;            //P1.6 TA1/2 options
      TACCTL0 |= CCIE;          //Enable Interrupts on Timer
      TACCR0 = 30;              //Number of cycles in the timer
      TACTL |= TASSEL_2;        //Use SMCLK as source for timer
      TACTL &= ~MC_1;           
      TACTL |= MC_0;
      TACTL |= ID_1;            //Divider
      TACCTL1 = OUTMOD_2;
      TACCR1 = 1;

    At the moment I have no idea why my code did not work without TACCR1 = 1 and OUTMOD declarations. The following is in the interrupt sequence:

    #pragma vector=TIMER0_A0_VECTOR
    __interrupt void Timer_A0(void)
    {
        TACTL &= ~MC_1;
        TACTL |= TACLR ;
     
    }
    

  • You should start the timer in the pin change interrupt.

    OUTMOD_2 means toggle/reset. So the CCR1 output toggles when its own count (1) is reached, and resets when the CCR0 count (30) is reached.
  • Finally got the timer output module working with pin P1.5 and using OUTMOD_7. Somehow, without using OUTMOD, it did not output signal to the pin.  The working setup part of the code is following:

      P1DIR |= BIT5;                            // P1.5 output
      P1SEL |= BIT5;                            // P1.5 TA1/2 options
      TACCTL0 |= CCIE+OUTMOD_7;                 //Enable Interrupts and outmod
      TACCR0   = 30;
      TACTL   |= TASSEL_2;                      //Use SMCLK as source for timer                  
      TACTL   |= MC_1;
      TACTL   |= ID_2;
    
    

    And the interrupt

    // Timer_A interrupt service routine
    #pragma vector=TIMER0_A0_VECTOR
    __interrupt void Timer_A0(void)
    {
       TACTL &= ~MC_1;
       TACTL |= TACLR ;
    }
    

**Attention** This is a public forum