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, time calculating?

Other Parts Discussed in Thread: MSP430F2274, MSP430FG4618

I'm using msp430f2274, in the part of my project, i want to toggle my leds using Timer A but i can not calculate the time intervals. For example i want to toggle leds every 15 seconds. How can i calculate TACCR0 value for 15 seconds? Which clock source should i use?

  • Hi,

    First, download the MSP430x2xx Family user's guide and read chapter 12 - Timer_A. If you select the ACLK (32768 Hz) as Timer_A clock source and then divide it by 8, you  will found the value that you need to put in the TACCR0 register.

     

    Best regards,

    AES

  •   Hi aes,

      I wrote here a part of my code. It suppose to work but it didn't. Where did i make mistake

      ....

      TACCTL0=CCIE;
      TACCR0=4096;
      TACTL=TASSEL_1+MC_1+ID_3;
      __bis_SR_register(LPM0_bits+GIE);

      ....

    #pragma vector=TIMERA0_VECTOR

      ....

     

  • Hi,

     

    Try this

    //******************************************************************************
    #include <msp430xG46x.h>
    //******************************************************************************
    //TIMER_A interrupt service routine - (CCRO)
    //******************************************************************************
    #pragma vector = TIMERA0_VECTOR
    __interrupt void TIMER_A (void)
    {
      P2OUT ^= 0x02;
      //TACCTL0 &= 0xfffe;                           // clean interrrupt flag
    }
    //******************************************************************************
    // main code
    //******************************************************************************
    void main (void)
    {
      WDTCTL = WDTPW + WDTHOLD;                  // wd stop
     
      P2SEL = 0x00;                              // config P2 to I/O
      P2DIR = 0x02;                              // config P2.1 output
       
      TACCTL0 = CCIE;                             // TACCRO interrupt enable
      TACCR0 = 61440;                            // counting time CCR0
      TACTL = TASSEL_1 + ID_3 + MC_1;            // TIMER_A
     
      _BIS_SR (LPM3_bits + GIE);                    //LPM3 with GIE 
    }

     

     

     

     

     

  • Hi ferhat,

       here is a simple solution use any TIMER A example in slac123 ,which uses auxiliary  clock i.e., 32768Hz  for ON/OFF ur led check with CRO how much time it is taking let it is 100 ms if u want some 10 secs  do a simple calculation ( 10 secs/100 ms= 100) make a use a flag and inside the timer interrupt loop increment it and wait for 100 if it reaches 100 make the led glow and clear the flag.

    a Very simple solution am i right??

    Regards

    Kshatriya

  • Aes, i tried your code but it didn't work. Why did you use TACCR0's value 61440 and LPM3? I want to learn how can we calculate TACCR0 for different time intervals?

    Kshatriya, how can i check my led with CR0 how much time it is taking?

    Thanks.

  •  

    Hi,

     

    I tested the code in a MSP430FG4618/F2013 Experimenter Board. If you are using IAR please check if the FET option is selected (not in simulation mode).

    The TACCR0 value is computed as follow:

    1-     TIMER A input clock is 32768 Hz. This clock is dived by 8, TIMER A frequency will be 4096 Hz.

    2-     Each TIMER tick count 1/4096 sec.

    3-     If you need 15 sec this will be equivalent to 4096*15 = 61440 tick counts.

     

    Regards,

    AES

     

     

     

  • Hi, connect ur CRO GND pin to ur board GND pin, and the touch the other probe with ur LED pin where u connect with the controller, or simply touch with the controller pin which pin u connected with controller.

    follow AES suggestions for to get  proper count value,  i think u didn't get any count value for a delay of 15 secs so make a maximum delay of 1 sec. and do the procedures what i said in previous post.

    Regards

    Khatriya

  • Thanks for help.

    Regards.

  • AES said:

    Hi,

     

    Try this

    //******************************************************************************
    #include <msp430xG46x.h>
    //******************************************************************************
    //TIMER_A interrupt service routine - (CCRO)
    //******************************************************************************
    #pragma vector = TIMERA0_VECTOR
    __interrupt void TIMER_A (void)
    {
      P2OUT ^= 0x02;
      //TACCTL0 &= 0xfffe;                           // clean interrrupt flag
    }
    //******************************************************************************
    // main code
    //******************************************************************************
    void main (void)
    {
      WDTCTL = WDTPW + WDTHOLD;                  // wd stop
     
      P2SEL = 0x00;                              // config P2 to I/O
      P2DIR = 0x02;                              // config P2.1 output
       
      TACCTL0 = CCIE;                             // TACCRO interrupt enable
      TACCR0 = 61440;                            // counting time CCR0
      TACTL = TASSEL_1 + ID_3 + MC_1;            // TIMER_A
     
      _BIS_SR (LPM3_bits + GIE);                    //LPM3 with GIE 
    }

     

     

     

     

     

    Hi AES!

    What if we use this code to show texts for a period of time? I don't know why the Timer A function is not called in the main?!!!

**Attention** This is a public forum