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.

MSP430f149 timer

Other Parts Discussed in Thread: MSP430F149

Hi,

   I am using MSP430F149 controller

    I have written a timer code in continuous mode, SMCLK as clock  source, 

       TACTL = MC_2|ID_3|TASSEL_2|TACLR;

         - MC- continuous mode

             ID - divided by --- 8

            TASSEL -- SMCLk.

 I need to count no. of pulses at incoming port. I am polling the particular port for 1 sec. of time duration. BUT with this configuration i am able to get EXACT count only if the frequency is 1 Hz ( i.i 1 pulse /sec). As I go on increasing, the count doesn't give the right count. (for i/p frequency of 4 Hz. respected count is - 3 Hz.    and for i/p frequency of 60Hz, the count is only 45!!!! ). 

        I am confused, y is it happening when  My clock is SMCLK i.e. 32768Hz. i.e. approx. only  30 uSec  for each instruction!!!. I need to know is, if this problem will get resolved if i use some other clock source???? and what r the possible options????

   Kindly help...

 

 

 

 

  • Manmesha,

    i am not sure whether i understand your problem completely. Maybe if you could provide your code that will be helpful to understand how you do the polling.

    However i also see that the information you gave is somehow confusing. You said that you are using SMCLK to source the Timer_A (TASSEL_2), and the SMCLK is 32768 Hz. Referring to the User's Guide document, Figure 4-1 the Basic Clock Block Diagram, you can see that SMCLK can only be source from either DCO or XT2 by selectin SELS bit. The XT2 itself only accepts 1-8MHz frequency. So the question is what do you exactly mean by using 32768 Hz SMCLK?

    -Leo-

  • hi,

     

     Thanks for your  reply....

    Yes, u r right. SMCLK uses the DCO clock. But according to my info DCO frequency is= 32768Hz. !!!

     

     

     

    #include "io430.h"

     //#include <io430x11x1.h> // Specific device
    //#include <msp430f149.h>
    // Pins for LEDs
    #define LED1 BIT3
    #define LED2 BIT4
    #define SW1 BIT0
    #define B1 BIT1
    unsigned int x,i,w;



    void delay_1_sec(void)

    {
          int i,x;
         
          x=0;
         // WDTCTL = WDTPW|WDTHOLD; // Stop watchdog timer
          P2OUT =  LED1; // Preload LED1 on , LED2 off
          P2DIR = LED1|LED2; // Set pins for LED1 ,2 to output
          TACTL = MC_2|ID_0|TASSEL_1|TACLR; // Set up and start Timer A
    // Continuous up mode , divide clock by 8, clock from SMCLK , clear timer
          //for (;;)
         
         
          do
         // {   
          //for(i=0; i<1; i++)
         { // Loop forever
             {
                // do
           //{

            if(( P1IN & SW1)==0)
                      {
                        
         
                                   do
                                       {
                                         P2DIR=   0X0a;  // PORT PIN P1.1 IS SET AS OUTPUT PIN
                                           P2OUT = 0x0a;  //set the LED connected to the port pin p2.3(timer led  1sec ) and p2.1 (not connected)
                                 }while ((P1IN & SW1)==0);  
                                                
                                             x=x+1;    
                          }            
            else
             {
                  P2DIR=   0X0a;  // PORT PIN P1.1 IS SET AS OUTPUT PIN
                  P2OUT = 0x08; // only timer led is on and the led for switch is off.
             }
            //do
         //    {
            //     } while ((P1IN & SW1)==0);  //wait till the switch is released...
       
                //P2DIR=   0X0a;  // PORT PIN P1.1 IS SET AS OUTPUT PIN
                //P2OUT = 0x0a;  // LED connected to the port pin p2.1 indicating switch status is kept on. and led connected to p2.3 indicating time delay of 1 sec. is kept on.  
                // x=x++;
         // }while(1);
    // Wait for overflow
    } // doing nothing
         
         
       
         
    }  while (TACTL_bit.TAIFG == 0);
     // Back around infinite loop

    P2DIR=   0X0a;  // PORT PIN P1.1 IS SET AS OUTPUT PIN
    P2OUT = 0x02;  // LED connected to the port pin p2.1 indicating switch status is kept on. and led connected to p2.3 indicating time delay of 1 sec. is kept on.  
       //   P2OUT =(((LED1)|(LED2))^P2OUT); // Toggle LEDs    /switch off the led as the 1sec. of time is over.
       // x= (x/2);

    do{
    }while(1);

    }






    void main (void)
    {
     
        // P1OUT = 0x02; // only timer led is on and the led for switch is off.
         //                   P1DIR=   0X02;  // PORT PIN P1.1 IS SET AS OUTPUT PIN
            WDTCTL = WDTPW|WDTHOLD; // Stop watchdog timer
          x=0;
          w=0;
      // do
          for (w=0; w<1; w++)
          {   
          delay_1_sec();
          }//while();
    }
    ---------------------------------------------------------------------------------------------------------------- 

     

    //

    //explaination---

    In above code, I am polling port pin P2.1 to a switch/ function generator.

    and P2.3 to a LED that will glow till the timer of 1 sec. is running. 

    hope u will get some more info from above code. thanks once again..


     
     
     
     
     
     

     

  • manmesha patankar said:

    Yes, u r right. SMCLK uses the DCO clock. But according to my info DCO frequency is= 32768Hz. !!!

    Where did you get this information? Please refer to the device datasheet, page 32 for the list of DCO output frequency

     

    manmesha patankar said:

    void delay_1_sec(void)

    {
         
          TACTL = MC_2|ID_0|TASSEL_1|TACLR; // Set up and start Timer A

     

    I see here that you are using ACLK now for sourcing the Timer_A module (probably with external 32.768 kHz). However you are using continous mode to set the delay. This will result actually to 2 seconds delay (65536/32768). If you want to create 1 second delay, use the up mode and set CCR0 to 32768.

     

    manmesha patankar said:

    #define SW1 BIT0

            if(( P1IN & SW1)==0)

    In above code, I am polling port pin P2.1 to a switch/ function generator.

    You said that you are polling P2.1, but as i see here you are polling P1.0 instead.

    If you really want to count the frequency coming into P2.1, look into the datasheet once again page 41, you can see that P2.1 can be used as INCLK (input clock of Timer_A). Then feed the P2.1 as the input clock of Timer_A and use the watchdog instead to create the 1s window (this can be easily done by setting WDTCTL = WDT_ADLY_1000 in IAR/CCS). In this case you can just read the TAR register in the watchdog interrupt.

    I hope this helps.

    -Leo-

**Attention** This is a public forum