Xmega crystal not stable?

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

Hi fellow freaks,

Trying to get a external 16 MHz crystal to work with the ATxmega128A1. Been looking at the AVR1003 note and this code seems to be working. The only problem is that the AVR restarts after 5-15 seconds. Is it a code problem or is my crystal not stable? The crystal is grounded via with two 22pF caps.

#include "clksys_driver.h"

//Clock configuration
CLKSYS_XOSC_Config( OSC_FRQRANGE_12TO16_gc, false, OSC_XOSCSEL_XTAL_16KCLK_gc );

CLKSYS_Enable( OSC_XOSCEN_bm );

do {} while ( CLKSYS_IsReady( OSC_XOSCRDY_bm ) == 0 ); 	

CLKSYS_Main_ClockSource_Select( CLK_SCLKSEL_XOSC_gc ); 

What could be the problem?

Kind regards
Bjorn

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

Hi again... solved it with this code:
32 MHz PLL driven by a 16 MHz crystal

See attached file. I get Error 400 from AVR forum when trying to post the code.

Would still be interesting though to know why my first code restarted the AVR.

/Björn

Attachment(s): 

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

Hi Bjorn,
Check Table 2-1 in AVR1003 Appnote, for 16MHz crystal 10pF caps are recommended.

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

The capacitor values are defined by the crystal! The important number is "load capacitance", It is usually in the range of 10pf to 15pf.

To figure the capacitors to use, double the load capacitance (because you have two equal value caps in series to make the "load"). Then, subtract out 5-7pf (7 for plain DIP, 5 for small pin sizes) from each value that you got from the first step. THIS is the proper capacitor value to use.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net