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.

MSP4305324 configure UCS: XT2 is 4Mhz MCLK is 8M

 Hello ! everyone, I`m configure MSP4305324  UCS

XT2 is connected 4Mhz crystal

then I want to configure it to FLL then MCLK select DCOCLK to 8Mhz

but not succeed,Does anyone help me to figure out it ?  Thanks。

code:

P5SEL |= BIT2+BIT3;                       // Port select XT2

//System clock Set(XT2 4M to 8M)
UCSCTL6 &= ~XT2OFF; // Enable XT2 
UCSCTL6 &= ~XT2DRIVE0; 
UCSCTL6 &= ~XT2DRIVE1; 
UCSCTL6 &= ~XT2BYPASS; 
UCSCTL3 = SELREF__XT2CLK; // FLLref = XT2

UCSCTL4 = SELA_2+ //ACLK=REFOCLK
SELS__DCOCLK + //SMCLK=DCOCLK
SELM__DCOCLK; //MCLK=DCOCLK

__bis_SR_register(SCG0); // Disable the FLL control loop
UCSCTL0 = 0x0000; 
UCSCTL1 = DCORSEL_5; 
UCSCTL2 = FLLD_0 + 1 ; //4M*(N+1)=8M
__bic_SR_register(SCG0); // Enable the FLL control loop

// Loop until XT1,XT2 & DCO stabilizes - in this case loop until XT2 settles
do
{
UCSCTL7 &= ~XT2OFFG; // Clear XT2,XT1,DCO fault flags
}while ( UCSCTL7 & XT2OFFG ); // Test oscillator fault flag

  • Don't see any reason for running DCO when there is XT2 already present on board. Use 8 MHz XT2 or 24 MHz XT2 and scale it down (divide by 2, 4, 8...) to requested MCLK.

  • There are several differences between this code and the equivalent driverlib functions (UCS_XT2Start(), UCS_clockSignalInit(), UCS_initFLLSettle()). I'm too lazy to list them here; why don't you just use driverlib, or copy the code from there?

  • I used MSP430F55xx_UCS_02.c as a basis for the following. Measured MCLK output, which was roughly 2x the input clock on X2.

    #include <msp430.h>

    int main(void)
    {
      volatile unsigned int i;

      WDTCTL = WDTPW+WDTHOLD;                   // Stop WDT
      P1DIR |= BIT1;                            // P1.1 output

      P1DIR |= BIT0;                            // ACLK set out to pins
      P1SEL |= BIT0;                           
      P2DIR |= BIT2;                            // SMCLK set out to pins
      P2SEL |= BIT2;                           
      P7DIR |= BIT7;                            // MCLK set out to pins
      P7SEL |= BIT7;          

      P5SEL |= BIT2+BIT3;                       // Port select XT2
     
      UCSCTL3 = SELREF_5;                       // Set DCO FLL reference = XT2
      UCSCTL4 |= SELA_2;                        // Set ACLK = REFO
      UCSCTL0 = 0x0000;                         // Set lowest possible DCOx, MODx

      // Loop until XT1,XT2 & DCO stabilizes - In this case only DCO has to stabilize
      do
      {
        UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);
                                                // Clear XT2,XT1,DCO fault flags
        SFRIFG1 &= ~OFIFG;                      // Clear fault flags
      }while (SFRIFG1&OFIFG);                   // Test oscillator fault flag
     
      __bis_SR_register(SCG0);                  // Disable the FLL control loop
      UCSCTL1 = DCORSEL_4;                      // Select DCO range 16MHz operation
      UCSCTL2 |= 1;                           // Set DCO Multiplier for 8MHz
                                                // (N + 1) * FLLRef = Fdco
                                                // (249 + 1) * 32768 = 8MHz
      __bic_SR_register(SCG0);                  // Enable the FLL control loop

      // Worst-case settling time for the DCO when the DCO range bits have been
      // changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx
      // UG for optimization.
      // 32 x 32 x 8 MHz / 32,768 Hz = 250000 = MCLK cycles for DCO to settle
      __delay_cycles(250000);
     
      while(1)
      {
        P1OUT ^= BIT0;                          // Toggle P1.0
        __delay_cycles(600000);                 // Delay
      }
    }

     

    Hopefully, this helps.

     

  • Oh, made the following changes:

    1. Added the P5SEL code for XT2.

    2. Changed UCSCTL3 to SELREF_5 for XT2.

    3. Changed to DCORSEL_4

    4. Changed multipler to 1(+1 = 2).

    Probably need to set up the drive strength, capacitive loading, etc. But, I wanted to see if I could get "in the ballpark."

    I would probably opt for what Zrno said, just use an 8 MHz input...

     

  • Thanks a lot for solution,I can use the XT2 crystal !
    I follow these steps that Todd said:

    1.Changed to DCORSEL_4

    2.Changed multipler to 1(+1 = 2).

    The problem is solved,thanks a lot!
  • It is not recommended to use the FLL with a low multiplier. In case of fDCO=8MHz and fREF=4MHz, this means the FLL will do an adjustment to DCO every second DCO clock tick. Which leads to a very instable regulation. The most stable regulation is to be expected for a factor >=32 as this is the modulation cycle duration.
    A possible way to relax the adjustment jitter is to run the DCO on a higher frequency than required and use additional dividers on the clocks (DIVM/DIVS). This will also reduce the modulation jitter.
    Or use a reference clock divider together with a higher multiplication factor.
    Best results can be achieved with a combination of both, e.g. FLLD_4, FLLN=15, FLLREFDIV_8 and using DCOCLKDIV as output. This dividers the 4MHz down to 500kHz as reference, programs the DCOCLKDIV output to 16*500kHz = 8MHz but runs the DCO on 32MHz.
    As a result, the FLL will update the DOC only every 32 DCO clock cycles (which is a complete modulation cycle), and 4 clock cycles are combined into one, reducing the modulation jitter. Don't forget to adjust DCORSEL for 32MHz.

    btw: the default settings already use DCOCLKDIV, running the DCO on 2MHz for 1MHz MCLK, to reduce modulation jitter.

**Attention** This is a public forum