OSC.CTRL has to be written twice to disable 2MHz OSC

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have been having an issue with an XMEGA D where when switching to an external 32KHz xtal for low power operation the 2MHz oscillator was not being disabled.

If I write to OSC.CTRL once it will disable the PLL and 32MHz oscillators, but not the 2MHz internal oscillator. If I write to it a second time immediately afterwards the 2MHz oscillator disables. I was using the Atmel driver and had to modify it to this to work:

uint8_t CLKSYS_Disable( uint8_t oscSel )
{
        OSC.CTRL &= ~(oscSel);
		OSC.CTRL &= ~(oscSel);
        uint8_t clkEnabled = OSC.CTRL & oscSel;
        return clkEnabled;
}

I did some more testing with OSC.CTRL = OSC_RC2MEN_bm and the same thing applies. It has to be written twice for the 2MHz oscillator to be disabled. Here is my code:

		case CPU_CLOCK_32KHZ_XTAL:
			CLKSYS_XOSC_Config(OSC_FRQRANGE_04TO2_gc, true, OSC_XOSCSEL_32KHz_gc);			// 32.768KHz crystal
			CLKSYS_Enable(OSC_XOSCEN_bm);
			CLKSYS_Prescalers_Config(CLK_PSADIV_1_gc, CLK_PSBCDIV_1_1_gc);					// scaled clocks B and C not used
			while (CLKSYS_IsReady(OSC_XOSCEN_bm) == 0);										// wait for oscillator to become stable
			CLKSYS_Main_ClockSource_Select(CLK_SCLKSEL_XOSC_gc);							// switch watch crystal
			CLKSYS_Disable(OSC_RC32MEN_bm | OSC_RC2MEN_bm | OSC_RC32KEN_bm | OSC_PLLEN_bm);	// turn off other oscillators
			CLKSYS_AutoCalibration_Disable(DFLLRC32M);
			CLKSYS_AutoCalibration_Disable(DFLLRC2M);

I have tried inserting NOPs and even a 10ms delay after switching to the 32KHz external oscillator but it doesn't make any difference.

Any ideas? Silicone bug? I could swear it worked on a 128A1, if I find time I will go back and test it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have also noticed that no amount of writes to DFLL2M.CTRL will disable it (clear bit zero).