Electrical – xmega external crystal won’t stabilize

avrclockcrystalxmega

I'm using an ATxmega64A3U, I've connected a 4MHz external crystal and two 18pF load caps. I'm using the ASF module for clock configuration, however when starting up I can see that the code hangs in the following spot:

static inline void osc_wait_ready(uint8_t id)
{
    while (!osc_is_ready(id)) {
        /* Do nothing */
    }
}

The while waits for the clock source to stabilize but that never happens. Does anyone have any suggestions why this could be?

Addition

The code I've posted above is from the ASF, to make sure I know what I'm executing I wrote the following code and could see that the code gets stuck in the while loop that waits for the oscillator to stabilize.

OSC_CTRL |= OSC_XOSCEN_bm;
while(!(OSC_STATUS & OSC_XOSCRDY_bm));
CCP = CCP_IOREG_gc;
CLK_CTRL = (CLK_CTRL & ~CLK_SCLKSEL_gm) | CLK_SCLKSEL_XOSC_gc;
OSC_CTRL &= ~OSC_RC2MEN_bm;

I enable the external oscillator, wait for it to get stable, disable lock on register, switch over to external oscillator, disable internal 2MHz oscillator.

Best Answer

Note that 18pF load capacitance from the data sheet does not mean to put two 18pF capacitors on the board.

Its the total capacitance the crystal should "see". Assuming a stray capacitance of 5pF, you would have

Cl = (18pF*18pF)/(36pF) + 5pF = 14pF

You may want to try something like 24pF for the load capacitors.

Furthermore, the ESR of the crystal you choose it pretty high. This may become an issue if the oscillator circuit cannot adequately drive the crystal.

Higher frequency crystal tend to have lower ESR, so try a crystal with 8 or 16MHz from that series.