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: Is it possible to get 1 second sensitive without using an external 32768 crystalcrystal?

Part Number: MSP430G2553

Tool/software: Code Composer Studio

every 1 second the timer will go into interrupt and the counter will increase by 1.

In this case, the value of the counter should be 60 in 1 minute. With the help of stopwatch, I measured 1 minute and stopped the program. The value of the counter was 54. Sensitive 1 second did not occur.

 

/***I created 1 second in the program as follows.***/

I used ACLK modules. its frequency is 12000 hz. The period in this case is 1/12000 seconds.

If I multiply 1/12000 seconds by 12000, I get 1 second. Everything is right up to here.

 

(I'm not sure after that). i continue. If I set TA0CCR0 to 12000, I would get 1 second.

1second=(1/12000)*TA0CCR0=(1/12000)*12000

If this is wrong, with which formula should I determine the CCR0 value?

#include <msp430.h> 

/* every 1 secont counter ++*/

unsigned int counter=0;
int main(void)

{
    WDTCTL = WDTPW | WDTHOLD;	// stop watchdog timer

	

	/***SET UP ACLK  ----> 12khz=12000hz ***/
	 BCSCTL1 &= ~XTS;        //set ACLK
	 BCSCTL3 &= ~LFXT1S0;
	 BCSCTL3 |= LFXT1S1;


	 /***TA0 Set Up***/

	 TA0CTL  |= MC_1 + TASSEL_1+TAIE ; //up mode(Up to TA0CCR0)-Source Select ACLK



	 /*** for 1second set up ***/

	 /*  ACLK period 1/12000 second. *
	  * (1/12000).TA0CCR0=(1/12000)*12000=1s (1second)  So,TA0CCR0 value must be 12000*/

	 TA0CCR0=12000;


	 __bis_SR_register( LPM3_bits+GIE);  // only ACLK Available-General intterupt active

}

#pragma vector=TIMER0_A1_VECTOR
__interrupt void TA0_kesme_func(void)
{
 switch (TA0IV){
 case  2: break;          //CCR1 not use

 case  4: break;         //CCR2  not use

 case 10:               //  overflow - counter++
           counter++;
           break;
               }

 }




  • The VLO is very inaccurate -- +/-60% per data sheet (SLAS735J) p.32. Note also the large temperature drift.

    Your best bet is probably to use SMCLK with ID=3 and count half-seconds. Supposing SMCLK=1MHz, CCR0 would be 500000/8=62500, which would just fit.

    In order to do this, you should also set the DCO constants (CALDCO/CALBC1) using something like:

    >BCSCTL1 = CALBC1_1MHZ; 
    >DCOCTL = CALDCO_1MHZ; 

  • thank you.Bruce . so my theoretical calculation is correct. Isn't there a waste of time when the program enters interrupt? Is this time worth considering?

  • Your arithmetic was correct, but the 12000 is (almost always) wrong -- in this case off by 54/60->10%. Based on that Table the 12000 could be 4000 or 20000. But the VLOCLK is very cheap (low power) so sometimes it's just the thing you want.

    My rule of thumb is that it takes about 25 CPU clocks to get into and out of an ISR. That's 25 microseconds at 1MHz. If your program isn't doing anything else, 25us/1sec introduces a 25ppm fixed skew in the resulting clock, which won't be noticeable. If it is doing other things, this shows up as jitter, but not drift.

    As far as that goes, the DCO is only specified to +/-3% (30000ppm), and that's drift, which is why a 20ppm (e.g.) crystal is recommended if you want to build a Real-Time Clock.

    [Edit: I just noticed you're using LPM3, so (as you note) SMCLK isn't available. I think I once saw a TI document describing how to calibrate the VLO using the DCO.]

  • I did what you said. Every half a second went into a cut. The counter value should be 120 per minute. But when I stopped the program, the counter value was 180. I think SMCK selection came very quickly.

    SMCLK DIV3=125000hz .So, Periot =1/125000 second.

    are we sure is the 1 unit increase in TA0R equal to 1/125000 seconds?

    For eaxmple: TA0R=1    than TA0R=2 ......  than   TA0R=62500

    When the TA0 value comes from 1 to 2, is the time elapsed equal to 1/125000 seconds? Is this really so?

    #include <msp430.h> 
    
    /* every 0,5 secont counter ++*/
    
    unsigned int counter=0;
    int main(void)
    
    {
        WDTCTL = WDTPW | WDTHOLD;   // stop watchdog timer
    
        
    
        /***SET UP SMCLK  ---->      1mhz=1000.000 Hz ***/
         DCOCTL |= CALDCO_1MHZ;  
         BCSCTL1 |= CALBC1_1MHZ;
         BCSCTL2|=DIVS_3;           //1000.000/8=125000
    
    
         /***TA0 Set Up***/
    
         TA0CTL  |= MC_1 + TASSEL_2+TAIE ; //up mode(Up to TA0CCR0)-Source Select SMCLK
    
    
    
         /*** for 0,5 second set up ***/
    
         /*  SMCLK period 1/125000 second. *
          * (1/125000).TA0CCR0=(1/125000)*62500=0.5s (0.5second)  So,TA0CCR0 value must be 62500*/
    
         TA0CCR0=62500;
    
    
         __bis_SR_register( LPM0_bits+GIE);  // SMCLK Available-General intterupt active
    
    }
    
    #pragma vector=TIMER0_A1_VECTOR
    __interrupt void TA0_kesme_func(void)
    {
     switch (TA0IV){
     case  2: break;          //CCR1 not use
    
     case  4: break;         //CCR2  not use
    
     case 10:               //  overflow - counter++
               counter++;
               break;
                   }
    
     }

  • Bruce McKenney47378 said:

    Aritmetiğin doğruydu, ancak 12000 (neredeyse her zaman) yanlış - bu durumda% 54 / 60-> 10 oranında. Bu Tabloya dayanarak 12000, 4000 veya 20000 olabilir. Ancak VLOCLK çok ucuzdur (düşük güç), bu yüzden bazen sadece istediğiniz şeydir.

    Temel kuralım, bir ISR'ye girip çıkmak için yaklaşık 25 CPU saatinin alınması. Bu 1MHz'de 25 mikrosaniye. Programınız başka bir şey yapmazsa, 25us / 1sec, sonuçta ortaya çıkan saatte 25ppm'lik bir sabit eğri tanıtır ve bu fark edilmeyecektir. Başka şeyler yapıyorsa, bu bir titreşim olarak görünür, ancak sürüklenmez.

    Bu kadarıyla, DCO sadece +/-% 3 (30000ppm) olarak belirtilir ve bu sapmadır, bu yüzden Gerçek Zamanlı Saat oluşturmak istiyorsanız 20ppm (örn.) Kristal önerilir.

    [Düzenle: LPM3 kullandığınızı fark ettim, bu nedenle (not ettiğiniz gibi) SMCLK mevcut değil. Bir keresinde DCO kullanarak VLO'nun nasıl kalibre edileceğini açıklayan bir TI belgesi gördüm.]

    thank you very much for giving valuable information.

  • >     DCOCTL |= CALDCO_1MHZ; 
    >     BCSCTL1 |= CALBC1_1MHZ;

     These should be "=", not "|=". They're non-0 at reset, so I'm not quite sure what settings you're ending up with.

  • You're right. I edited it and tried again. The counter came out 121. It works.thanks 

**Attention** This is a public forum