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.

msp430f5436a/5438a Increasing MCLK with DCO wont work

Other Parts Discussed in Thread: MSP430F5436A

Hello,

I am facing a problem that driving me crazy.

I am trying to increase MCLK/SMCLK of the MSP430F5436A (MSP-EXP430F5438A) with the following code:

void initClk(void)
{
	SetVcoreUp (PMMCOREV_1);				//Increase slowly Vcore
	SetVcoreUp (PMMCOREV_2);				//Increase slowly Vcore
	SetVcoreUp (PMMCOREV_3);				//Increase slowly Vcore to work with DCO = 25MHz
	P11DIR |= BIT0 | BIT1 | BIT2;			// Set pin 11.0,11.1,11.2 to output ACLK, MCLK, SMCLK
	P11SEL |= BIT0 | BIT1 | BIT2;			// Select pin 11.0,11.1,11.2 to output ACLK, MCLK, SMCLK

	UCSCTL3 = SELREF__REFOCLK;				// select REFO as FLL source
	UCSCTL6 = XT1OFF | XT2OFF;				// turn off XT1 and XT2

	/* Initialize DCO to 25.00MHz */
	__bis_SR_register(SCG0);				// Disable the FLL control loop
	UCSCTL0 = 0x1f<<8;						// Set possible DCOx=31, MODx=0
	UCSCTL1 = DCORSEL_4;					// Set DCORSELx for DCO = 12.3 MHz - 28.2 MHz
	UCSCTL2 = 625u;							// Set DCO Multiplier for 20.5MHz
	                                        // (N + 1) * FLLRef = Fdco
	                                        // (625 + 1) * 32768 = 20.5MHz
	UCSCTL4 = SELA__REFOCLK | SELS__DCOCLK | SELM__DCOCLK;
											// Select Aclock = REF0CLK
											// Select SMclock = DCOCLK
											// Select Mclock = DCOCLK

	__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*32*20.5MHz/32768Hz = 640625 = MCLK cycles for DCO to settle
	__delay_cycles(640625);

	/* Loop until XT1,XT2 & DCO fault flag is cleared */
	do
	{
		UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG);
											// Clear XT2,XT1,DCO fault flags
		SFRIFG1 &= ~OFIFG;					// Clear fault flags
	}
	while (SFRIFG1&OFIFG);					// Test oscillator fault flag


}

while the SetVcoreUp is:

void SetVcoreUp (unsigned int level)
{
	// Open PMM registers for write
	PMMCTL0_H = PMMPW_H;
	// Set SVS/SVM high side new level
	SVSMHCTL = SVSHE + SVSHRVL0 * level + SVMHE + SVSMHRRL0 * level;
	// Set SVM low side to new level
	SVSMLCTL = SVSLE + SVMLE + SVSMLRRL0 * level;
	// Wait till SVM is settled
	while ((PMMIFG & SVSMLDLYIFG) == 0);
	// Clear already set flags
	PMMIFG &= ~(SVMLVLRIFG + SVMLIFG);
	// Set VCore to new level
	PMMCTL0_L = PMMCOREV0 * level;
	// Wait till new level reached
	if ((PMMIFG & SVMLIFG))
		while ((PMMIFG & SVMLVLRIFG) == 0);
	// Set SVS/SVM low side to new level
	SVSMLCTL = SVSLE + SVSLRVL0 * level + SVMLE + SVSMLRRL0 * level;
	// Lock PMM registers for write access
	PMMCTL0_H = 0x00;
}

From the Data Sheet of the msp430f5436a:

for DCORSELx = 4, DCOx = 31, MODx = 0 - the MCLK is between 12.3MHz and 28.2 MHz.

I use the following formula to create 20.5MHz CLK:

(N + 1) * FLLRef = Fdco
(625 + 1) * 32768 = 20.5MHz
=> N=625.

the problem is that it sometimes work, and sometimes not.
when it's not working, its either stuck on the "__delay_cycles(640625);" line, or it has a DCO Fault Flag:

 

I have tried it with a different CPU ( the MSP430F5438A) and still it doesn't work all the time.

Please help, i just want a 20.5MHz MCLK.

P.S
I do not have any other EXT crystal.

  • I guess you misinterpreted the datasheet.

    UCSCTL1 = DCORSEL_4;                    // Set DCORSELx for DCO = 12.3 MHz - 28.2 MHz

    This is wrong. On DCORSEL_4, the DCO can range from a minimum of 1.3 to 3.2MHt (DCOx=0) to a maximum of 12.3 to 28.8MHz (DCOx=31). However, both extremes will cause DCOFFG to be set.

    The min/max values are the rage this specific DCORSELx/DCOx combination will give on different MSPs. It is not the DCO range. The worst case range for DCORSEL_4 is therefore 3.2 to 12.3MHz but on some MSPs it may even range from 1.3 to 28.8MHz.
    You already init the DCO to maximum, so the only way for the FLL is do adjust it down (if appropriate) or give up.
    Please re-read the chapter about how the DCO and the FLL work.

  • so let me see if i got that right.

    i should set the DCORSEL to 5, and leave the DCOx to 0, and than using the   UCSCTL2 = 625u, i will get my 20.5MHz of MCLK?

    That should work?

  • 20.48Mhz +-1.5% (REFO tolerance, if not using  an external watch crystal). With a little short-term (DCO modulation) and long-term (FLL adjustment loop) jitter.

**Attention** This is a public forum