20MHz crystal unreliable (ATMega324P)

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

I previously set up an ATTiny84 with a 20 MHz crystal and 2x 20pF caps. I could get it to run reliably without CKDIV8 enabled.

I'm now transplanting those caps and the crystal into my ATMega324P project, and while I can run with the external crystal, it doesn't want to play nice without CKDIV8. (i.e. it gets unpredictable, and I don't even care to try and analyze what the heck is going on)

The odd thing is, it has no problem running off the internal oscillator without CKDIV8. Therefore, with the internal osc I can get 8MHz, but with an external 20MHz crystal, I need CKDIV8 so I only get 2.5MHz.

My guess at the moment is that some electrical characteristic of this larger chip requires a different capacitance on the oscillator. I'm curious as to why this might be, and if anyone else has had a similar experience.

The 324P is a real powerhouse, so I'd love to get it running smooth with the 20MHz crystal. Thanks in advance!

EDIT: I have startup set to 258 CK + 64 ms

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

I have used a M324p at 18MHz. And what do you mean by "it gets unpredictable"?
I use 15pF or 18pF caps.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Is your crystal layout good (crystal and caps close to crystal pins, etc)? Is your power and ground layout good, with bypass caps near each power & gnd pin?

Have you tried both the low-power and the full-swing fuse settings? Are you running the most conservative crystal settings (slowest startup, etc)?

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

Have you looked at these application notes?

AVR042: AVR Hardware Design Considerations
http://www.atmel.com/dyn/resourc...

AVR186: Best practices for the PCB layout of Oscillators
http://www.atmel.com/dyn/resourc...

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

What about your operating voltage :)

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

Hi,

In AVR042 they show the crystal closer than the caps, but in AVR186 they show the caps closer than the crystal...

1. Which is better?

2. I've also seen many examples of the caps going directly to the ground plane, and many here have recommended not connecting them to the ground plane, but running them back to the uC ground pin. Which is better?

3. Should the top ground plane surround only the crystal, or the caps too?

4. Can the top ground plane BE the connection between the cap grounds and the uC GND?

5. Should the bottom ground plane be solid under the crystal/caps? Or should it be isolated from the rest of the ground plane, only connected to the top plane, which may in turn only be connected to the cap grounds and the uC ground pin (which is connected to the main board ground plane).

Thanks,

Alan

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

Do you have an O'Scope?

The Mega324 has a Clock Output Buffer. Set the fuses to enable the Clock Output Buffer and look at the clock signal on the scope. This allows you to see the actual clock signal without loading the oscillator by attaching a scope probe to the Xtal itself.

If you have erratic clock operation with the Ext Xtal, turning on the divide by 8 should STILL give you erratic operation, just 8 times slower... turning on the divide by 8 justs routes the clock signal through a divider, it doesn't chance the oscillator itself.

JC

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

js wrote:
I have used a M324p at 18MHz. And what do you mean by "it gets unpredictable"?
I use 15pF or 18pF caps.

I have 4 seven segment displays. At lower clock settings the thousands digit works properly. At 20MHz, the thousands digit is flickering rapidly between 6 and 7 (which might be better described as unexpected)

kk6gm wrote:
Is your crystal layout good (crystal and caps close to crystal pins, etc)? Is your power and ground layout good, with bypass caps near each power & gnd pin?

Have you tried both the low-power and the full-swing fuse settings? Are you running the most conservative crystal settings (slowest startup, etc)?

I'm running this on a breadboard, so I'd say the crystal is as close to the caps as it's going to get.

As far as bypass caps, I haven't done this. I'm assuming you're referring to de-coupling. I'll try some 0.1uF caps by power and ground.

I could also try a more conservative clock setting. I just used the ext. crystal osc setting. I didn't know if I could use full swing and low-power.

EDIT: IT WORKS! I switched to full swing and added some decoupling caps. Thanks for the advice.

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

DocJC wrote:
Do you have an O'Scope?

The Mega324 has a Clock Output Buffer. Set the fuses to enable the Clock Output Buffer and look at the clock signal on the scope. This allows you to see the actual clock signal without loading the oscillator by attaching a scope probe to the Xtal itself.

If you have erratic clock operation with the Ext Xtal, turning on the divide by 8 should STILL give you erratic operation, just 8 times slower... turning on the divide by 8 justs routes the clock signal through a divider, it doesn't chance the oscillator itself.

JC

I wish I had an oscope... one day. one day.

Have yet to find a decent one for a decent price. It will likely be my next big piece of equipment (looking into building homebrew VCOs, I'll definitely need one).

I didn't know about the clock output buffer, that'll be good to keep in mind when I finally do get a scope.

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

StkMtd wrote:

I have 4 seven segment displays. At lower clock settings the thousands digit works properly. At 20MHz, the thousands digit is flickering rapidly between 6 and 7 (which might be better described as unexpected)

Your problem begins to make more sense. You are switching a fair amount of current in the displays, and without decoupling caps, on a breadboard, and with the low-power oscillator settings, you've got noise running amok. :)

Quote:
I'm running this on a breadboard, so I'd say the crystal is as close to the caps as it's going to get.

As far as bypass caps, I haven't done this. I'm assuming you're referring to de-coupling. I'll try some 0.1uF caps by power and ground.

I could also try a more conservative clock setting. I just used the ext. crystal osc setting. I didn't know if I could use full swing and low-power.

EDIT: IT WORKS! I switched to full swing and added some decoupling caps. Thanks for the advice.


Decoupling caps are a necessity for any digital circuit. Meet the device half-way with basic good practice and you'll avoid a lot of grief. Congrats on getting it working.

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

I think your breadboard is the issue. They are normally good for up to 10MHz and then cross talk and stray capasitance start to kick in and give you problems. I have experimented once with e phillips 8051 and ran that at 10MHz I did not need any capasitance to ground in fact it would only work without capasitors to ground.

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

meslomp wrote:
I think your breadboard is the issue. They are normally good for up to 10MHz and then cross talk and stray capasitance start to kick in and give you problems. I have experimented once with e phillips 8051 and ran that at 10MHz I did not need any capasitance to ground in fact it would only work without capasitors to ground.

I knew stray capacitance could be an issue, and surprisingly I also noticed that it seemed to momentarily work better without the caps to ground.

However, when I switch to full-swing mode, and put 0.1uF caps across the chip's supply, and a 47uF electrolytic across the main rails, I ended up with a very happy circuit.

The lowest cap I have is a 20pF, but I was noticing that higher values gave me less desirable results, so on my next order to digikey, I'll be picking up more caps in the FULL range recommended by the Atmel datasheets.

Someone here recommended 18pF.

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

The value depends on the load capacitance of the crystal.

Leon Heller G1HSM

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

StkMtd wrote:

Someone here recommended 18pF.

Actual capacitor values depend on what the crystal needs and parasitic stray capacitance. There is no way to say 18pF is the best if other conditions are unknown (crystal frequency, crystal load capacitance requirement, wiring board type (PCB/protoboard), wiring board trace length etc). So you have to read that as "18pF was good value for me, but you might need different value". You have to keep both the crystal AND microcontroller happy regarding the total capacitance.

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

Good call. I read the guide under the article section of this site on matching capacitors with crystals.

With the equations provided, I grabbed all the caps I could between 20pF, and about 28pF. As I mentioned before, I noticed lower capacitance values resulted in a smoother display refresh. I suppose what I meant was that I wish I had an 18pF cap, just so I could see if there was any noticeable difference from the 20pF (although with tolerances being what they are, that could be splitting hairs).

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

Something I might ask is, what programmer are you using? When I first started with AVRs, I was using a homemade parallel port programmer and got very unpredictable results above 14.7 MHz. Changing to a Dragon and/or a JTAGICE II cleared up all my problems.