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.

MSP430F5529: Shall I use crystal XT2 as direct clock signal for MCLK or to stabilize the DCO and use the DCOCLK for MCLK?

Expert 1140 points
Other Parts Discussed in Thread: MSP430F5529

Hi!

What is the better attitude in case I have both XT1 and XT2 populated on the PCB (in this case MSP430F5529 LaunchPad) - use the XT2 crystal (4MHz) as clock signal (XT2CLK) for MCLK or to stabilize the DCO via FLL and use the DCOCLK for MCLK? In my application I do not care much about processing speed therefore I can use 4MHz, I can see these two options presented below - which will be better (the device is going to operate in the field with temperatures changing along the year from -30 to +40 deg of Celsius).

With Regards,

tml

  • HF crystal oscillators consume mode power than DCO. On the other hand crystal oscillators are much more precise than FLL-driven DCO, especially if FLL reference sourced from internal calibrated RC oscillator. Xtal start-up speed is slower. So knowing which property of clock is important to you - you can use one or another.

  • tml said:

    Hi!

    What is the better attitude in case I have both XT1 and XT2 populated on the PCB (in this case MSP430F5529 LaunchPad) - use the XT2 crystal (4MHz) as clock signal (XT2CLK) for MCLK or to stabilize the DCO via FLL and use the DCOCLK for MCLK? In my application I do not care much about processing speed therefore I can use 4MHz, I can see these two options presented below - which will be better (the device is going to operate in the field with temperatures changing along the year from -30 to +40 deg of Celsius).

    With Regards,

    tml

    On all my MSP430F5xx USB boards, XT2 is used for USB module and MCLK. Don't know about DCO/XT1/XT2 working temperature relation.

  • tml said:
    use the XT2 crystal (4MHz) as clock signal (XT2CLK) for MCLK or to stabilize the DCO via FLL and use the DCOCLK for MCLK? In my application I do not care much about processing speed therefore I can use 4MHz,

    It makes no sense stabilizing the DCO to 4MHz by FLL with a 4MHz crystal. Use the crystal directly and disable the DCO to preserve energy.

    Also, FLL works better, the higher the factor between reference and DCO output is. At a factor of 1, it becomes instable.

    Besides this, you should tell what you want to achieve (and why!), not ask how to do something that you think you need but perhaps don't need at all.

  • Does the following code makes sense?

    	WDTCTL = WDTPW + WDTHOLD;
    
    	// ACLK = XT1 = 32768 Hz
    	// MCLK = SMCLK = XT2 = 4.0 MHz
    
    	//////////////////////// use XT1 32768 Hz ////////////////////////////////////////////
    	P5SEL |= BIT4 + BIT5;						// Select XT1
    	UCSCTL6 &= ~XT1OFF;							// Enable XT1
    	UCSCTL6 |= XCAP_3;							// Internal load cap
    
    	WDTCTL = WDTPW + WDTCONFIG;
    
    	// Increase Vcore setting to level3 to support fsystem=25MHz
    	// NOTE: Change core voltage one level at a time..
    	SetVcoreUp (0x01);
    	SetVcoreUp (0x02);
    	SetVcoreUp (0x03);
    
        //////////////////////// use XT2 4.0 MHz ////////////////////////////////////////////
    	P5SEL |= BIT2 + BIT3;						// Select XT2
    
    	UCSCTL6 &= ~XT2OFF;							// Enable XT2
    	UCSCTL3 |= SELREF__XT1CLK;					// FLLref = XT1
    
    	do											// Loop until XT1 and XT2 stabilize
    	{
    		UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);		// Clear XT2, XT1 fault flags
    		SFRIFG1 &= ~OFIFG;						// Clear oscillator fault flag
    	} while (SFRIFG1 & OFIFG);					// Test oscillator fault flag
    
    	UCSCTL4 |= SELA__XT1CLK + SELS__XT2CLK + SELM__XT2CLK;			// ACLK = XT1, MCLK = SMCLK = XT2
    

    There are 2 resons for which I ask:

    1. without increasing the Vcore (lines 19-21) the launchpad works pretty unstable, encountering resets when in active mode, I also think that sometimes the contents of RAM is lost while CPU keeps running

    2. with and without increasing the Vcore the MSP gets reset when there is a thunderstorm nearby.

    The application of the Launchpad is the weather station that I described here: http://eltomek.blogspot.com/2014/10/diy-weather-station.html

    Regards,
    tml

  • tml said:
    Does the following code makes sense?

    Almost, but I would set it up as followed;

    int main(void)
    {
    	// ACLK = XT1 = 32768 Hz
    	// MCLK = SMCLK = XT2 = 4.0 MHz
    
    	WDTCTL = WDTPW + WDTHOLD;	// Stop watchdog timer
    
    
    	// Increase Vcore setting to required level to support fsystem.
    	// 0 = 8MHz, 1 = 12MHz, 2 = 20MHz, 3 = 25MHz.
    	// NOTE: Change core voltage one level at a time.
    	//SetVcoreUp (0x01);
    	//SetVcoreUp (0x02);
    	//SetVcoreUp (0x03);
    
    
    	// *** Setup XT1 *********************************
    	P5SEL |= BIT4 | BIT5;					// Port select XT1
    	UCSCTL6 &= ~XT1OFF;						// XT1 On
    	// If required enable internal XT1 load cap's
    	UCSCTL6 |= XCAP_3;
    	//
    	// Loop until XT1 fault flag is cleared
    	do {UCSCTL7 &= ~XT1LFOFFG;}				// Clear XT1 fault flags
    	while ((UCSCTL7 & XT1LFOFFG) != 0);	// Test XT1 fault flag
    	//
    	// Decrease XT1 Drive according to expected frequency
    	UCSCTL6 &= ~XT1DRIVE0;
    
    
    	// *** Setup XT2 *********************************
    	P5SEL |= BIT2 | BIT3;					// Port select XT2
    	UCSCTL6 &= ~XT2OFF;						// XT2 On
    	//
    	// Loop until XT2 fault flag is cleared
    	do {UCSCTL7 &= ~XT2OFFG;}				// Clear XT2 fault flags
    	while ((UCSCTL7 & XT2OFFG) != 0);		// Test XT2 fault flag
    	//
    	// Decrease XT2 Drive according to expected frequency
    	UCSCTL6 &= ~XT2DRIVE0;
    
    
    	// Set Clock sources
    	UCSCTL4 = SELA__XT1CLK | SELS__XT2CLK | SELM__XT2CLK;
    
    
    	// Stop DCO
    	__bis_SR_register(SCG0 | SCG1);
    	// Clear DCO fault flag
    	UCSCTL7 &= ~DCOFFG;
    
    
    	// Now that osc is running enable fault interrupt.
    	// Add an UNMI_ISR to handle the fault.
    	SFRIFG1 &= ~OFIFG;		// Clear Oscillator fault interrupt flag
    	SFRIE1 |= OFIE;			// Enable fault interrupt
    
    	// Enable Interrupts
    	__bis_SR_register(GIE);
    
    	while(1)
    	{
    		// ...
    	}
    }
    

    Why it is necessary to increase Vcore I do not know, but I understand that you get the 3.3V via a LDO from the 3.8V, this may give an unstable 3.3V.

    Your weather stations is a great project, but to protect it against ESD you have to do more than add a few low-ESR capacitors.

  • The unified clock system in your F5xx is very limber and you can switch clock sources on the fly. You do not need to stick to one clock configuration all the time.

    Working in a weather station, I guess you cannot close the shutters, curtail your activities, take it easy and sit out the storm ;) Can you?

    Do you use the USB interface? During that, you probably need to turn on XT2. In most other situations, I think FLL with REFO as reference is quite adequate and robust.
  • old_cow_yellow said:
    Do you use the USB interface? During that, you probably need to turn on XT2. In most other situations, I think FLL with REFO as reference is quite adequate and robust.

    No, although I use UART communication at 115200 and I found it to be a bit unstable so I switched to XT2.

  • True, REFO is not accurate enough as FLL reference when you need to cover a wide range of operating temperature and voltage for UART baudrate.

    The other alternative is to use 32768 Hz crystal controlled XT2 as FLL reference. The advantage of that over using XT1 as a reference is that (a) you have more choices of the FLL DCO frequency, and (2) if and when XT2 fails, REFO will automatically kick in and help.
  • old_cow_yellow said:
    The other alternative is to use 32768 Hz crystal controlled XT2 as FLL reference

    As far as I know XT2 is only HF and 4MHz or higher.

    old_cow_yellow said:
    (a) you have more choices of the FLL DCO frequency

    I don’t see any difference, maybe you can clarify this a bit.

    old_cow_yellow said:
    (2) if and when XT2 fails, REFO will automatically kick in and help

    I think this applies only to XT1-LF, but I could be wrong.

  • Leo is absolutely right.

    I made a mental slip and said "XT2" in all the place where I should have said "XT1"
  • OCY thanks, I was afraid I was getting age problems.
  • Thanks Guys!

    Anyway, do you see any particular issue in my initial code that could cause resets that sometimes end up with total system hangup (i.e no WDT active, I suppose the infinite do loops because then WDT is held).

    Why would increasing Vcore help in this case? Without increasing Vcore I had approx. 4h, 2k, sometimes 7k minutes of uptime after which reset occured, with Vcore lifted up I had more then 25k minutes and would probably have even more but the thunderstorm came and triggered a reset.

    I'd love to understand what happens but I don't have the possibility of attaching the debugger and waiting for that long.

  • tml said:
    ...Anyway, do you see any particular issue in my initial code that could cause resets that sometimes end up with total system hangup ...


    Yes, your line 29 caused chaos to the DCO (under FLL setting of Fref * 32), which was the source of MCLK at that time. And the rest of your code will not have any history to speak of.

    Leo tried to help, but he was too polite and said you were "Almost right" instead of "Entirely wrong". Did you make any attempt to read Leo's code?
  • old_cow_yellow said:
    Leo tried to help, but he was too polite and said you were "Almost right" instead of "Entirely wrong". Did you make any attempt to read Leo's code?

    :-) I am ok with "entirely wrong" as long as I take a lesson out of it.

    Yes, I've studied it and saw a major difference to be disabling the DCO and not assigning XT1 as a reference for FLL. I am currently testing the updated clock setup procedure as adviced by Leo, so far with promising results.

  • But also look at my comment regarding the 3.3V (Vcc). How is this achieved?
    This may be important in relation to your comment by memory loss.
  • The 3.3V is provided from the following cascade: lead-acid 6V battery -> ST1S10 PWM drop-down to 3.8V -> TI's LDO to 3.3V. I didn't check their stability on the oscilloscope although ST1S10 powers the GSM modem with no issues even during TX burst. The 3.3V LDO itself is loaded only by the launchpad which is almost no load for it.
  • Hi Leo,

    Unfortunately with the code presented the MCU still resets, I've observed a reset after ~7500 minutes (5 days). I will try to inrease the Vcore.

    Best Regards,
    Tomek

  • Unless your code needs 5 days to execute once, it seems very unlikely (but not impossible) that it is a software problem (or solvable by software). I presume, after 6 days, the battery is still sufficiently loaded. Or does it break down during the charge cycles of the PWM regulator? What about bypass capacitances for the ST1510 stability? With slowly dropping source voltage, the regulator might become instable and start to oscillate. However, I'd then expect the device to reset over and over again or in constantly reducing intervals.

    Long-time issues are difficult to track down. But you might set-up a digital scope with pre-trigger and set it up for some software-generated pulse at startup (so it gets triggered at a reset), then hook it up for the supply voltages. It might give you some clue about what happened right before the reset.
  • At least this setup is wrong; 3.8V -> LDO 3.3V. As I understood the GSM can draw high current (1A or more?). If the LDO not starts to oscillate, the noise or (short) voltage drops/spikes will be transferred to your 3.3V (Vcc), increasing Vcore gives the core more playroom but there will be an end.
    If your battery drops below 5.5V it might not be able to supply the GSM high current, do you measure the battery voltage and/or current?
  • Yes, I do measure the battery voltage and as it drops below 6.0V I don't activate the GSM modem. Thank you for your input on the electrical setup, you may be correct. I should have attached 3.3V LDO to battery instead and leave the 3.8V work separately.
  • Good choice! And if you rewiring the power, add an leaded inductor 3/6uH (leaded resistor shape) between battery and 3.8V SMPS and one to 3.3V LDO to separate/block noise.

**Attention** This is a public forum