ATxmega32A4:Crystal Oscillator : Trial and Error

Last post
30 posts / 0 new
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;
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Datasheet for the crystal I used:

http://www.abracon.com/Resonators/ab.pdf

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

I did receive my 16Mhz crystals today. They work fine in the same configuration. Here is the data sheet for the 16Mhz crystals (20pf load).

http://www.ramitechnology.com/products/spec/crystal/crystal-hc-49_short.pdf

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

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

We'll play with them a little today, but I will defend our hw guys - we **do** have a fair few caps around, just not many in the low pF range in 0402.

-- Damien

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

damien_d wrote:
bobosoft wrote:
I think at this point you can safely point the finger at your hardware guys.

We'll play with them a little today, but I will defend our hw guys - we **do** have a fair few caps around, just not many in the low pF range in 0402.

-- Damien

Today we fitted 33pF capacitors without success. We also tried a 12MHz xtal from the same series, also without success (after fiddling with cap values again).

One thing we noticed was that the ESR values of the xtals you used are 40 Ohm and 50 Ohm. The one we're using is rated at 100 Ohm. Do you think this may have a bearing on the outcome?

EDIT: We also attempted to rule out a footprint issue by soldering short wires from the pads of the xtal to the pads on the pcb. Unlikely anyway - we're using the same footprint elsewhere on another board.

-- Damien

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

ESR shouldn't have much effect on oscillator operation.

Leon Heller
G1HSM

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

I actually think that is a good question. Crystals with higher ESR require a higher drive level and as you pointed out the XMega oscillator is a “low-swing” type which means a low drive level. ESR can prevent an oscillator from starting so I thought it was worth investigating. I added series resistance to both legs of the crystal until it would not start. Here are my results:

Two 39 Ohm resistors, New ESR MAX, 108ohms: Successful Start
Two 56.2 Ohm, New ESR MAX, 142.4ohms: Successful Start

Two 75 Ohm, New ESR MAX, 180ohms: NO Start
Two 91 Ohm, New ESR MAX, 212ohms: No Start

So there you have it, drop off point for my crystal seems to be somewhere around 150ohms.
Some things you should note:
ESR is not the sole determinate of drive level. The crystal I used is 1mW max drive level and yours is 100uW max. That should allow higher ESR in your circuit before start failure. Thus, I doubt ESR is your problem but I simply don’t know enough to tell you that for sure.

Here are some things to try if you have not already:
-If possible, run the XMega at a higher voltage, which would overcome more ESR.
-Eliminate the XMega itself by trying a different one
-Eliminate a faulty PCB (design fault and manufacturing fault) with the following 3

-Check the resistance from the pin of the XMega to the pin of the crystal
-if you have the equipment check the inductance along the same path
-if possible, check the capacitance from each crystal trace to ground and in between them

-of course, test it without any extraneous code, as simple as possible.

I am sure Abracon wants you to continue to use their higher priced SM crystal. You may want to try to call them for design support. They might have people who are familiar with these issues. Personally, I have no experience with miniature SM crystals, maybe there are additional considerations?

Microchip (Am I allowed to say that) wrote a good paper detailing more than I want to know about crystals here:

http://ww1.microchip.com/downloads/en/AppNotes/00826a.pdf

I wasn’t meaning to say that your hardware guys sucked, only that I thought the software was not at fault. Even if this is the result of a stupid design decision, it happens to the best of us. Personally I do at least one stupid thing per project.

A side note, I don’t think you have to set the System clock to the crystal before using the crystal as the source for the PLL. That isn’t the problem, but once you get this figured out, you should be able to remove that step for efficiency.

XMega is currently my favorite chip and I have it planned for several projects. I love the analog features and I really like the new C Structs for everything. The flexibility with the individual pins in also ridiculous (pull-up, down, invert, bus-keeper). I am therefore interested in the outcome of this, so do post if you figure it out.
Matt

Attachment(s): 

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

damien_d wrote:

EDIT: We also attempted to rule out a footprint issue by soldering short wires from the pads of the xtal to the pads on the pcb. Unlikely anyway - we're using the same footprint elsewhere on another board.

-- Damien

May I suggest soldering short wires directly from the xmega xtal pads to the crystal pads.

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

bobosoft wrote:

May I suggest soldering short wires directly from the xmega
xtal pads to the crystal pads.

We're using the QFN package, so the leads aren't anywhere nearly as accessible. We may yet give it a shot.

Thank you for the long post! We've launched support cased both with Atmel and with Abracom, documenting the information from this thread.

We also tried this on an early prototype when the xmegas were as rare as hen's teeth (in this case, it was a 16A4), which also had a slightly different layout. Unfortunately, it didn't work then either (same xtal, 22pF caps), but we never investigated it properly - there were quite a few assembly issues from those very early hand-placed boards and the same cap/xtal combo worked for the 128a1 in another project.

As it turns out, our next revision is dropping the need for a clock elsewhere in the system and as therefore we have a spare clock from our main PLL that we can use as as straight external oscillator. Saves a bit of BOM as an added bonus.

I have to agree that I like the xmega design. Here we're using it as a sensor interface, sampling over SPI and timestamping the data before sending back to the host processor. Probably wouldn't be feasible with the classic mega series.

-- Damien

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

You got me thinking about the ESR thing and I was considering how higher frequencies would result in increased sensitivity to ESR. So I decided to give the 16Mhz crystal the same test. I was surprised to find that even adding only 2x 22 Ohms of resistance (84 Ohm ESR Max) resulted in a no start. 2X10ohm did work but I found this so surprising that I shorted the 22 Ohm resistors and verified functionality just to make sure it wasn't failing because of the way I had the leads set up.

So you might be on to something with the ESR thing. I remain skeptical because the higher ESR is not something that would be related to your model specifically but rather all miniature SMD crystals. I find it hard to believe that Atmel would engineer an oscillator circuit inside an IC marketed at mobile devices that would be incompatible with the majority of those type of crystals.

It's also worth noting that although I used 1% resistors, their resistance is likely to shift at 16mhz.

Attachment(s): 

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

...

Very interesting indeed. Thank you very much for your help. I'm going to see what Atmel knows about it...

-- Damien

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

damien_d wrote:
...

Very interesting indeed. Thank you very much for your help. I'm going to see what Atmel knows about it...

-- Damien

I have posted what Atmel said about it in another thread, which you can find at:
* http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=89787

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

Matt...

thanks for that, that is excellent information on ESR. I bet that is the issue too... it's come up before apparently. So, I am looking for an 8.192MHz crystal low ESR preferrably surface mount. Or I am open to suggestions... anything available ya think? Maybe 16MHz, or 12MHz... something SMD.
XC1022CT or NX3225SA-16.000000 look fine on digi-key perhaps

Jeffy

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

malemanguy wrote:
Matt...

thanks for that, that is excellent information on ESR. I bet that is the issue too... it's come up before apparently. So, I am looking for an 8.192MHz crystal low ESR preferrably surface mount. Or I am open to suggestions... anything available ya think? Maybe 16MHz, or 12MHz... something SMD.
XC1022CT or NX3225SA-16.000000 look fine on digi-key perhaps

Jeffy

If you want to be on the safe side, I would avoid any small surface mount crystals. Even if it worked in my prototype, I would be nervous about different untested usage scenarios and production tolerances. That XC1022CT is only 40ohms and should would work fine.

You should think about if you actually need those high value crystals though. Faster crystals are harder to start and result in more power consumption (although I don't know how significant). It may be your best bet to use a 4MHZ crystal and then multiply it with the PLL to your desired frequency.

I haven't tried this yet but the XMega has a facility to synchronize the internal oscillator to a 32Khz watch crystal. That would give you timing accuracy with a super easy start. It would also allow for the device to function if the cyrstal oscillator did not start (although less accurately).

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

I maybe have a solluton to the problems with small crystals and high ESR. I have atiny board with a ATmega168PA. The pico power P-versions share the same low drive capability as the xmega series and this MCU failed to drive the FC-135 crystal (3.2x1.5 mm). But reading the data sheet of the AVR, page 32 I found out that the ESR can be higher for a lower capacitance crystal. So by chosing a 6-9 pF crystal instead of 12 pF you should get this up and running. Of course you have to have a good board that do not add 10 pF or so by itself! I use a crystal that have both lower ESR and capacitance, CC7V-T1A.

ESR is always specified in the 50-80 KILO ohms range. But you are talking about ohms. What is wrong?

My favorites:
1. My oscilloscope, Yokogawa DLM2024.
2. My soldering iron, Weller WD2M, WMRP+WMRT.
3. JTAGICE mkII emulator and debugWire.
4. ImageCraft ICCAVR C compiler.
5. ATmega168

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

bengtr wrote:

ESR is always specified in the 50-80 KILO ohms range. But you are talking about ohms. What is wrong?

The ESR must go down as the frequency goes up. The crystal you mentioned (FC-135) is a watch crystal (32.768K). That is why the ESR is in the KOhms range. Let's do a quick calculation with the RC constant. Say we want to get to about 80% voltage to produce a high value, so we will use 2 * RC. We will use 50Kohms and 9pF

2 * R * C = time
2 * 50E3 * 9E-12 = 9E-7 Seconds
1 / 9E-7 = 1.1Mhz

So you see there is no possible way you can get a crystal with 50KOhms ESR to run at 16Mhz. In reality, in order for the oscillator to start, you would also need much much better than that to run at 1.1Mhz.

Good suggestion on getting a crystal specified for lower capacitance. Even if you have a crap board with high capacitance, if you can measure it with some accuracy, you can just deduct it from your chosen load capacitors.

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

OK, I didn't thought about the frequency, of course it will be much lower at high frequencies. Anyway, I think the problem will be the same for 32 kHz and 16 MHz so a low capacitance crystal may be the solution to the problems of combining small size with XMega or mega P types. I hope I will have the opportunity to try soon. I design very compact boards (above is 15x25 mm) and I must use small crystals. Also see the detailed description for calculating the load capacitances at the same page as I mentioned above.

My favorites:
1. My oscilloscope, Yokogawa DLM2024.
2. My soldering iron, Weller WD2M, WMRP+WMRT.
3. JTAGICE mkII emulator and debugWire.
4. ImageCraft ICCAVR C compiler.
5. ATmega168

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

A misstake, the ESR wasn't smaller on the crystal I mentioned above. The manufacturer specifies max value and for all crystal in this size it is the same, 70 kohm. But the AVR accept only ESR = 30 kohm at 12.5 pF but 75 kohm at ESR = 6.5 pF. So choosing a crystal with low capacitance load caps should work, at least for 32 kHz.

My favorites:
1. My oscilloscope, Yokogawa DLM2024.
2. My soldering iron, Weller WD2M, WMRP+WMRT.
3. JTAGICE mkII emulator and debugWire.
4. ImageCraft ICCAVR C compiler.
5. ATmega168

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

This application note was updated today:
"AVR4100: Selecting and testing 32kHz crystal oscillators for AVR microcontrollers Application Note"
http://www.atmel.com/dyn/general/tech_doc.asp?doc_id=13055&family_id=607
XMEGA 32kHz is still forthcoming.

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

Amazing, Atmel is obviously reading this topic or was it just a coincidence? Great list with different oscillator driver version in that document. Someone who can try the X32K_XMEGA oscillator module and see if it works with a crystal with 7 pF load and 70 kohm ESR?

My favorites:
1. My oscilloscope, Yokogawa DLM2024.
2. My soldering iron, Weller WD2M, WMRP+WMRT.
3. JTAGICE mkII emulator and debugWire.
4. ImageCraft ICCAVR C compiler.
5. ATmega168