Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
damien_d
PostPosted: Nov 18, 2009 - 07:53 AM
Resident


Joined: Dec 15, 2008
Posts: 923
Location: Brisbane, Australia

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
Code:

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):

Code:

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
 
 View user's profile Send private message  
Reply with quote Back to top
bobosoft
PostPosted: Nov 18, 2009 - 12:46 PM
Rookie


Joined: May 23, 2009
Posts: 30


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.
 
 View user's profile Send private message  
Reply with quote Back to top
damien_d
PostPosted: Nov 18, 2009 - 12:59 PM
Resident


Joined: Dec 15, 2008
Posts: 923
Location: Brisbane, Australia

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 Smile

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
 
 View user's profile Send private message  
Reply with quote Back to top
bobosoft
PostPosted: Nov 18, 2009 - 01:01 PM
Rookie


Joined: May 23, 2009
Posts: 30


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.
 
 View user's profile Send private message  
Reply with quote Back to top
bobosoft
PostPosted: Nov 18, 2009 - 01:05 PM
Rookie


Joined: May 23, 2009
Posts: 30


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 Smile

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?
 
 View user's profile Send private message  
Reply with quote Back to top
damien_d
PostPosted: Nov 18, 2009 - 01:11 PM
Resident


Joined: Dec 15, 2008
Posts: 923
Location: Brisbane, Australia

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 Smile

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/DkSea ... -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.
 
 View user's profile Send private message  
Reply with quote Back to top
bobosoft
PostPosted: Nov 18, 2009 - 01:28 PM
Rookie


Joined: May 23, 2009
Posts: 30


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.
 
 View user's profile Send private message  
Reply with quote Back to top
damien_d
PostPosted: Nov 18, 2009 - 01:34 PM
Resident


Joined: Dec 15, 2008
Posts: 923
Location: Brisbane, Australia

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 Smile

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
 
 View user's profile Send private message  
Reply with quote Back to top
bobosoft
PostPosted: Nov 18, 2009 - 01:47 PM
Rookie


Joined: May 23, 2009
Posts: 30


Oh no, I have my own ghetto rig with my own cheap Chinese crystals. I will take a picture.
 
 View user's profile Send private message  
Reply with quote Back to top
bobosoft
PostPosted: Nov 18, 2009 - 02:22 PM
Rookie


Joined: May 23, 2009
Posts: 30


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.
 
 View user's profile Send private message  
Reply with quote Back to top
bobosoft
PostPosted: Nov 18, 2009 - 02:23 PM
Rookie


Joined: May 23, 2009
Posts: 30


Exact code for verification:

Code:

#include <avr/io.h>
#define F_CPU 24000000UL
#include <util/delay.h>
#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;
}
 
 View user's profile Send private message  
Reply with quote Back to top
bobosoft
PostPosted: Nov 18, 2009 - 02:30 PM
Rookie


Joined: May 23, 2009
Posts: 30


Datasheet for the crystal I used:

http://www.abracon.com/Resonators/ab.pdf
 
 View user's profile Send private message  
Reply with quote Back to top
bobosoft
PostPosted: Nov 18, 2009 - 06:50 PM
Rookie


Joined: May 23, 2009
Posts: 30


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
 
 View user's profile Send private message  
Reply with quote Back to top
damien_d
PostPosted: Nov 18, 2009 - 10:35 PM
Resident


Joined: Dec 15, 2008
Posts: 923
Location: Brisbane, Australia

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
 
 View user's profile Send private message  
Reply with quote Back to top
damien_d
PostPosted: Nov 19, 2009 - 03:42 AM
Resident


Joined: Dec 15, 2008
Posts: 923
Location: Brisbane, Australia

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


Last edited by damien_d on Nov 19, 2009 - 11:58 AM; edited 1 time in total
 
 View user's profile Send private message  
Reply with quote Back to top
leon_heller
PostPosted: Nov 19, 2009 - 07:52 AM
Raving lunatic


Joined: Jul 27, 2001
Posts: 7570
Location: St. Leonards-on-Sea (UK)

ESR shouldn't have much effect on oscillator operation.

_________________
Leon Heller
G1HSM
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
bobosoft
PostPosted: Nov 19, 2009 - 12:09 PM
Rookie


Joined: May 23, 2009
Posts: 30


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
 
 View user's profile Send private message  
Reply with quote Back to top
bobosoft
PostPosted: Nov 19, 2009 - 12:51 PM
Rookie


Joined: May 23, 2009
Posts: 30


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.
 
 View user's profile Send private message  
Reply with quote Back to top
damien_d
PostPosted: Nov 19, 2009 - 01:11 PM
Resident


Joined: Dec 15, 2008
Posts: 923
Location: Brisbane, Australia

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
 
 View user's profile Send private message  
Reply with quote Back to top
bobosoft
PostPosted: Nov 19, 2009 - 01:55 PM
Rookie


Joined: May 23, 2009
Posts: 30


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.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits