ATxmega32A4:Crystal Oscillator : Trial and Error

30 posts / 0 new
Last post
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello all,

Over the last couple of days, we have been attemping to use the crystal oscillator on the ATxmega32A4.

In short, we have gotten one combination of crystals and caps to work, but we have tried many others that haven't been so lucky.

We designed our board with a 16MHz ABM8 crystal for which the datasheet is attached. We managed to get tis device working on an ATxmega128A1 with 22pF load caps.

However, on our new boards with a ATxmega32A4 (and we've tried a ATxmega16A4) we are yet to get any joy out of this device.

Scrounging whatever caps we've had around the lab, we've tried the following combinations (with two crystals each from a different batch):

6.8pF, no feedback resistor
2 x 6p8 = 13.6pF, no feedback resistor
2 x 6p8 = 13.6pF, 1M Feedback resistor
22pF, no feeback resistor.

In desparation, we tried a 8MHz crystal from our local electronics store and it worked nicely with 22pF capacitors.

Code-wise, we used the following routine for the 8MHz

void SetupExternalCrystal_8MHz()
{
    // Setup the crystal oscillator, wait 16K cycles to settle
	CLKSYS_XOSC_Config(OSC_FRQRANGE_2TO9_gc,
		               false,
		               OSC_XOSCSEL_XTAL_16KCLK_gc );
    
    // Enable the clock source
	CLKSYS_Enable( OSC_XOSCEN_bm );

    // Wait for the clock source to settle
	while ( CLKSYS_IsReady( OSC_XOSCRDY_bm ) == 0 )
    {
    }

    // Select the crystal oscillator as the main source
	CLKSYS_Main_ClockSource_Select( CLK_SCLKSEL_XOSC_gc );

    // Now, configure the PLL to use the XTAL, with a 4x multiplier
    // for a PLL clock of 32MHz
    CLKSYS_PLL_Config( OSC_PLLSRC_XOSC_gc, 4);
    CLKSYS_Enable(OSC_PLLEN_bm);

    // Prescalers config (Divider A, B, C by 1)
    CLKSYS_Prescalers_Config( CLK_PSADIV_1_gc, CLK_PSBCDIV_1_1_gc );

    // Wait for the PLL to be ready
    while ( CLKSYS_IsReady( OSC_PLLRDY_bm ) == 0 )
    {
    }

    // Select the main clock source to be the PLL
    CLKSYS_Main_ClockSource_Select( CLK_SCLKSEL_PLL_gc );
}

And we used the following routine for the not-working 16MHz crystal (but it did work on the 128A1):

void SetupExternalCrystal()
{
    // Setup the crystal oscillator, wait 16K cycles to settle
	CLKSYS_XOSC_Config(OSC_FRQRANGE_12TO16_gc,
		               false,
		               OSC_XOSCSEL_XTAL_16KCLK_gc );
    
    // Enable the clock source
	CLKSYS_Enable( OSC_XOSCEN_bm );

    // Wait for the clock source to settle
	while ( CLKSYS_IsReady( OSC_XOSCRDY_bm ) == 0 )
    {
    }

    // Select the crystal oscillator as the main source
	CLKSYS_Main_ClockSource_Select( CLK_SCLKSEL_XOSC_gc );

    // Now, configure the PLL to use the XTAL, with a 2x multiplier
    // for a PLL clock of 32MHz
    CLKSYS_PLL_Config( OSC_PLLSRC_XOSC_gc, 2);
    CLKSYS_Enable(OSC_PLLEN_bm);

    // Prescalers config (Divider A, B, C by 1)
    CLKSYS_Prescalers_Config( CLK_PSADIV_1_gc, CLK_PSBCDIV_1_1_gc );

    // Wait for the PLL to be ready
    while ( CLKSYS_IsReady( OSC_PLLRDY_bm ) == 0 )
    {
    }

    // Select the main clock source to be the PLL
    CLKSYS_Main_ClockSource_Select( CLK_SCLKSEL_PLL_gc );
}

We've also tried other start-up routines (3 others) from searching the forums here. Two of them worked for the 8MHz xtal. I can post them on request.

We ordered a bunch of different load caps today to try tomorrow, but I was going to ask if anyone had gotten any other crystals working on the xmega boards. If so, which xmega device, what what was the frequency (better yet, the model), what load caps and what other gotchas are there that we need to look out for?

We've also noted from the clksys application note (1003) that the oscillator that's implemented is of the "low-swing" variety. What affect does this have on the crystal specification?

-- Damien

Attachment(s): 

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

You did not mention anything about your layout which makes me think you may not be aware of its importance. As the speed of the crystal increases, PCB layout becomes more important. 16 MHz is slow enough to work in a wide variety of configurations but you would still have trouble getting it to work while inserted directly into a bread board, for example. 22pF is a much better choice than 6.8pF but I would expect them both to work in a noise-free condition, although the frequency may be off. Your crystal's load capacitance is specified as part of the part number, which you did not include. If you chose the default of 18pF, then I would recommend 30pf capacitors. The two capacitors would total to 15pf ((C1*C2)/ (C1+C2)). When you add an estimated 3pF parasitic capacitance, it should get you about in the right spot. I will warn you however, that if it is entirely non-functional with 22pF, you have other issues.
Have a look at the following Atmel app notes:
AVR186
AVR042

Also browse the various crystal manufacturers’ websites for app notes. They usually have good explanations. One other thing, you may want to save playing with the PLL until after you get the crystal working.

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

bobosoft wrote:
You did not mention anything about your layout which makes me think you may not be aware of its importance.

In some respects, this is correct - I am mostly a software person, but both hardware guys assure me it's OK :)

The crystal itself is located next to the xmega (slightly offset to the left of the actual xtal pins) and the traces to the pads are under an inch. IIRC, the signals are buried under a ground plane (it's a board with > 10 layers).

-- Damien

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

As for your other question, the low swing basically means low current through the oscillator. In the app note they are just telling you that you cannot "steal" the clock signal from the xtal pins and drive other circuits with it.

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

damien_d wrote:
bobosoft wrote:
You did not mention anything about your layout which makes me think you may not be aware of its importance.

In some respects, this is correct - I am mostly a software person, but both hardware guys assure me it's OK :)

The crystal itself is located next to the xmega (slightly offset to the left of the actual xtal pins) and the traces to the pads are under an inch. IIRC, the signals are buried under a ground plane (it's a board with > 10 layers).

-- Damien

That sounds reasonable. It should certainly at least function. What is the part number? Did you accidentally order a series crystal?

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

bobosoft wrote:
damien_d wrote:
bobosoft wrote:
You did not mention anything about your layout which makes me think you may not be aware of its importance.

In some respects, this is correct - I am mostly a software person, but both hardware guys assure me it's OK :)

The crystal itself is located next to the xmega (slightly offset to the left of the actual xtal pins) and the traces to the pads are under an inch. IIRC, the signals are buried under a ground plane (it's a board with > 10 layers).

-- Damien

That sounds reasonable. It should certainly at least function. What is the part number? Did you accidentally order a series crystal?

Not at work atm, so I can't check for certain, but I am reasonably confident that we ordered this part:
http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=535-9134-1-ND

The load caps are indeed 18pF, or at least that's what it says on the packet they arrived in.

EDIT: Small change in wording, added load cap info.

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

When you say the load caps are 18pf, does that mean you are using two 18pf capacitors? That would create a load capacitance of 9pf. I happen to have an xmega32a4 sitting in front of me. I will fire it up with your code and see if it works in a bit.

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

bobosoft wrote:
When you say the load caps are 18pf, does that mean you are using two 18pf capacitors? That would create a load capacitance of 9pf. I happen to have an xmega32a4 sitting in front of me. I will fire it up with your code and see if it works in a bit.

I was unclear on this myself.

Currently, as soldered on the board, we have C1 = C2 = 22pF, which, according the above formula is actually a load of 11pF + trace capacitance. Earlier, we tried C1 = C2 = 6.8pF, and then 2x 6.8pF in parallel on each pad through some soldering wizardry that hurts my eyes :)

If you're fitting the 32a4 in the STK600, there is an external oscillator circuit and therefore appears to the xmega as an external clock. Incidentally, this actually works quite well.

-- Damien

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

Oh no, I have my own ghetto rig with my own cheap Chinese crystals. I will take a picture.

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

Ok, I did not have a 16Mhz crystal handy. I do have some on order, if they happen to come today, I will repost. I did however have a 12Mhz Abracon 18pf crystal handy and it fired right up with no problem using your code. I verified the proper clock speed of 24Mhz with 1 second LED blink intervals. I know you can't make it out in the pic but that is an ATXMEGA32A4. I used 22pf capacitors to replicate your test.

On that note, I find it strange that you are producing 10 layer board but don't have a variety of prototype capacitors on hand. The capacitors I just used came out of this kit:
http://cgi.ebay.com/32-Value-0805-SMD-Ceramic-Capacitor-Assorted-Kit-in-Box_W0QQitemZ160377426903QQcmdZViewItemQQptZLH_DefaultDomain_0?hash=item25573d53d7
It comes in very handy all the time. I think you can get them in 0603 and 0402 as well.

I think at this point you can safely point the finger at your hardware guys.

Attachment(s): 

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

Exact code for verification:

#include 
#define F_CPU 24000000UL
#include 
#include "clksys_driver.h"

#define testPort PORTA

void SetupExternalCrystal()
{
    // Setup the crystal oscillator, wait 16K cycles to settle
   CLKSYS_XOSC_Config(OSC_FRQRANGE_12TO16_gc,
                     false,
                     OSC_XOSCSEL_XTAL_16KCLK_gc );
   
    // Enable the clock source
   CLKSYS_Enable( OSC_XOSCEN_bm );

    // Wait for the clock source to settle
   while ( CLKSYS_IsReady( OSC_XOSCRDY_bm ) == 0 )
    {
    }

    // Select the crystal oscillator as the main source
   CLKSYS_Main_ClockSource_Select( CLK_SCLKSEL_XOSC_gc );

	
    // Now, configure the PLL to use the XTAL, with a 2x multiplier
    // for a PLL clock of 32MHz
    CLKSYS_PLL_Config( OSC_PLLSRC_XOSC_gc, 2);
    CLKSYS_Enable(OSC_PLLEN_bm);

    // Prescalers config (Divider A, B, C by 1)
    CLKSYS_Prescalers_Config( CLK_PSADIV_1_gc, CLK_PSBCDIV_1_1_gc );

    // Wait for the PLL to be ready
    while ( CLKSYS_IsReady( OSC_PLLRDY_bm ) == 0 )
    {
    }

    // Select the main clock source to be the PLL
    CLKSYS_Main_ClockSource_Select( CLK_SCLKSEL_PLL_gc );
	
} 

int main(void)
{
	testPort.DIR = 0xFF;
	SetupExternalCrystal();

	while(1)
	{
		testPort.OUTTGL = 1;
		_delay_ms(1000);
	
	}
	return 0;
}

Pages