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.

MSP430FG4619--timer

Other Parts Discussed in Thread: MSP430FG4619

hello professors,

These days I met a problem when I configure the timer module in fg4619. here is the thing:

I initiate the Timer:

void Init_TIMERA0(void)
{
  TA0CCR0 = 1000;  //count limit (16 bit) 12000
  TA0CCTL0 = CCIE;  //enable counter interrupts, bit 4=1, TACCR0 interrupt enabled
  TA0CTL = TASSEL_2 + MC_1;  //SMCLK
 
}

#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer0_A0 (void)
{



            milsec_rt++;
            if(milsec_rt>999)
            {
                milsec_rt = 0;
                timer++;
                if(timer>59)
                {
                    timer = 0;
                }
                
            }
 
  asm("nop");
}

But the problem is every one second the millisec counter should be around 1000, cause the interrupt is called in every 1ms, but the millisec counter finished 3 or 4 times when the time goes into 1 second. I didnt find there is some mistakes in the configuration, TACCR0=1000. only when I change the number to 10000 to TACCR0, every one second the millisec runs to 800.... it is wierd also... could you give me some suggestion? thanks so much

Best Regards

  • What are your SMCLK frequency settings?

    Also, TA0CTL is normally configured as

    TA0CTL = TASSEL_2 + MC_1 + TACLR;         // SMCLK, upmode, clear TAR

    though it may not create your problem...

  • in datasheet it says 1M hz for the SMCLK, so I am confusing about that....

  • ??? Which datasheet? SMCLK frequency is configurable and could have any value...

  • I'm new to this part.. The SMCLK value is not default?  because in the msp430fg4619 datasheet, I didnt find how to set it? if it needs to set, how could I set it? could you give me some suggestions? thanks for your time

    Best Regards

  • There are code examples for your part. Go to 

    http://www.ti.com/product/MSP430FG4619/toolssoftware#softTools

    and there look for MSP430FG461x Code Examples(Rev.G).

    I am pretty sure there must be an example to set up your clocks.

    By the way, do you use external crystal? If yes and your crystal f=32768Hz, and you did not touch any clock-related registers, then your default SMCLK should be around 1MHz after power-up.

  • Thanks for your information . I just use the internal generator, and the crystal is 32768Hz,  the FG4619 I initiate is to use 8Mhz system clock. so you mean the smclk is 1Mhz?

  • Please post the rest of your code (ie main() function and any code that sets FLL registers).

  • Hi Robert,

    Thanks for your reply. the code I used to initiate to the lcd part is as followed:

    /****************************************************************************/
    /*  Init system frequency                                                   */
    /*  Function : InitFreq_XT2                                                 */
    /*      Parameters                                                          */
    /*          Input   :  Nothing                                              */
    /*          Output  :  Nothing                                              */
    /****************************************************************************/
    void InitFreq_XT2(void)
    {
      int i=0;  //,j=0

      // External oscilator 8MHz

      /* Watchdog */
      // Stop watchdog timer
      WDTCTL = WDTPW + WDTHOLD;

      /* FLL+ Control Register 0 */
      // Low Frequency, Oscillator capacitor ~6 pF
      FLL_CTL0 = XCAP0PF;

      /* System Clock Control Register */
      // Disable modulation
      // SCFQCTL = 0x80;

      // Stop DCO
      // _BIS_SR(SCG1+SCG0);
      _BIS_SR(SCG1);

      /* FLL+ Control Register 1 */
      // Activate XT2 high freq xtal
      FLL_CTL1 &= ~XT2OFF;

      // Wait for xtal to stabilize
      do {
      IFG1 &= ~OFIFG;                           // Clear OSCFault flag
      for (i = 5; i > 0; i--);                  // Time for flag to set
      //if((++j)>1000) break;
      }while ((IFG1 & OFIFG));

      /* FLL+ Control Register 1 */
      // SMCLK on, XT2 on, XT2 for main oscilator, ACLK By 1
      FLL_CTL1 = SELM1 + SELS + FLL_DIV_1;

      //  SCFI0 = 0x40;
      //  SCFI1 = 0xE0;


    }

    The above code I used , after I used the OSC to test the smclk, I found the frequency is around 8Mhz, but I dont know why, could you give me some instructions, thank you so much

  • Your part has 2 oscillators inside, LFXT1 and XT2.

    LFXT1 has pins XIN and XOUT for connecting external crystal 1, normally cheap watch one, with f=32768 Hz;

    XT2 has pins XT2IN, XT2OUT for connecting external crystal 2, normally with frequency of several MHz.

    Could you tell us:

    1. Do you have both crystal 1 and crystal 2 connected to your MSP430 part?

    2. What are the frequencies of these crystals?

    Your code above makes us think that you do have a crystal with f=8MHz connected to XT2IN, XT2OUT and you select it as a reference for your SMCLK. That's why your SMCLK = 8MHz, regardless of any other FLL settings.

    Back to your original question, in timer settings use constant of 8000 instead of 1000 when you set your timer:

    TA0CCR0 = 8000;

  • milsec_rt and timer should be declared volatile. It shouldn't make a difference here, but things that 'magically' change or are 'unexpectedly' used outside the normal program floe (by ISR or DMA) should be declared volatile.

    Also, you shouldn't fall out of main. "End" main by either entering LPM0 or doing while(1). It is undefined what happens when you exit main (depends on the compiler you use)

**Attention** This is a public forum