MSP430 External crystal higher power - Page 1
Forum section: electronics / general

author: veryevil
author_rank: Unknown
timestamp: August 06, 2019, 07:56:17 pm
content: Hi, I have a board which uses a MSP430F5419A and has an external 16Mhz crystal on XT1.I have code which runs this board either from the internal DCO @ 16Mhz or using the external xtal.When configured for the external oscillator i'm getting about 350uA more current when in LMP4 mode than with the internal DCO.Is there something I should be doing to turn off the XT1 before going into LMP4?I have ACLK running from internal low power rc and wake up periodically.How would I make sure the xtal goes off and comes back on to service interrupts etc?Code:void InitXTAL(void){//Set Up Vcore Voltage Level 2 up to 20MhzPMM_setVCore(PMM_CORE_LEVEL_2);#ifdef INT_XTAL//Configure XTAL IOGPIOConfigOutputLow(IO_XTAL_XT1_XIN); //XT1 Output LowGPIOConfigOutputLow(IO_XTAL_XT1_XOUT); //XT1 Output LowUCSCTL3 = SELREF__REFOCLK; // FLL: REFOUCSCTL4 = SELA__REFOCLK | SELS__DCOCLK | SELM__DCOCLK; //ACLK: REFO, SMCLK: DCO, MCLK: DCOUCSCTL5 = DIVS__2; //SMCLK: /2UCSCTL6 = XT1OFF | XT2OFF; // turn off XT1 and XT2// Initialize DCO to 16.00MHz__bis_SR_register(SCG0); // Disable the FLL control loopUCSCTL0 = 0x0000u; // Set lowest possible DCOx, MODxUCSCTL1 = DCORSEL_7; // Set RSELx for DCO = 50 MHzUCSCTL2 = 488u; // Set DCO Multiplier for 16MHz// (N + 1) * FLLRef = Fdco// (488 + 1) * 32768 = 16MHz__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*16MHz/32768Hz = 500000 = MCLK cycles for DCO to settle__delay_cycles(500000u);#else //Ext XTAL//Config XTAL IOGPIODirInput(IO_XTAL_XT1_XIN); //InputGPIODirOutput(IO_XTAL_XT1_XOUT); //OutputGPIOPeripheralEnable(IO_XTAL_XT1_XIN); //Set XIN as peripheral function which is XT1GPIOPeripheralEnable(IO_XTAL_XT1_XOUT); //Set XOUT as peripheral function which is XT1//Enable XT1 with mid drive strengthUCSCTL6 = XTS | XT1DRIVE_1 | XT2OFF;//XTAL = 16MHz - MCLK 16MHz - SMCLK 8MHzUCSCTL4 = SELA__REFOCLK | SELS__XT1CLK | SELM__XT1CLK; //ACLK: REFO, SMCLK: XT1, MCLK: XT1UCSCTL5 = DIVS__2; //SMCLK: /2#endif//Make sure ACLK stays on all the timeBitSet(UCSCTL8, ACLKREQEN);/* Loop until XT1,XT2 & DCO fault flag is cleared */do{// Clear XT2,XT1,DCO fault flags (Reset if still in fault)BitClear(UCSCTL7, (XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG));// Clear Oscillator fault flagsBitClear(SFRIFG1, OFIFG);}while (BitTest(SFRIFG1,OFIFG)); //Test oscillator fault flag}

author: coppice
author_rank: Super Contributor
timestamp: August 06, 2019, 10:16:38 pm
content: Turning off the crystal oscillator will save a few hundred uA, but turning it back on during an interrupt service can be problematic. It takes a while for the oscillator to stabilise, and that time can vary quite a bit with things like temperature. This isn't the kind of behaviour you typically want in an interrupt service routine.

author: SiliconWizard
author_rank: Super Contributor
timestamp: August 06, 2019, 10:36:25 pm
content: I don't know much about MSP430, so can't say if this is supported, but this is basically what many Cortex MCUs allow when going to some of the sleep modes.Obviously if you're using those modes, you have to make sure the interrupt(s) waking up the MCU are not too time-critical. Yes oscillators take time to start up, and usually the oscillators with an external crystal will take longer to stabilize than internal RC oscillators (given you're not using a low-freq one). If you're using a PLL on top of that, it will take significant additional time! Typical times are normally given in datasheets.