AVR crystal problems - Page 1
Forum section: electronics / general

author: owlhawk
author_rank: Newbie
timestamp: December 24, 2013, 10:12:24 pm
content: I have a simple board with an ATmega16M1 microcontroller. It is working fine when running on the internal oscillator, but I'm having trouble getting it to work with a crystal.It is just a standard crystal + two load caps setup. A 12mhz smd crystal and two 8pF caps. I've done several STM32 boards with the same parts and not had any trouble. But on this one it does not seem to oscillate. Running some really simple "led blink" code, it doesn't start at all. When I connect a scope probe across the crystal it sometimes runs, but much slower than it should be. And all I'm seeing on the scope is a few mV of noise.I tried swapping out the crystal, removing the caps, and doubling them for 16pF per side with no luck. Atmel gives the formula C = 2*CL- CS. With CLbeing 8pF for my crystal and their estimate of 5-10pF for CSso I think my values are reasonable.I also attached a screenshot of my layout in case that has something to do with it. Not much to it though.Running out of ideas here... anyone have advice on what might be wrong?

author: Jon86
author_rank: Frequent Contributor
timestamp: December 24, 2013, 10:22:06 pm
content: Have you tried swapping out the microcontroller?I can't see it being anything else, unless there's something wrong with the soldering or board.

author: Rerouter
author_rank: Super Contributor
timestamp: December 24, 2013, 10:30:34 pm
content: lift off your crystal and probe the 2 pins, with something like a 10K pulldown on xtal 2, this should drive xtal 1 high as a function test of the micro

author: c4757p
author_rank: Super Contributor
timestamp: December 24, 2013, 10:33:02 pm
content: Quote from: owlhawk on December 24, 2013, 10:12:24 pmI suspect microcontroller as well, but if you're going to attach it I'll bite! The layout could be fixed - the capacitors' grounding is not good. They need to be grounded close together (nottoobad here), but they should also be grounded close to the oscillator's (microcontroller's, in this case) ground. You haven't shown the entire layout, but I'm having trouble seeing a ground path from crystal capacitor -> MCU that is not long and curvy.The problem could be solved by putting a few (at least twoeach) ground vias near the capacitors to that nice ground plane underneath, and doing the same thing near the MCU ground pins.

author: filip_cro
author_rank: Regular Contributor
timestamp: December 24, 2013, 11:10:22 pm
content: Check fuse bits once more. Programer works? If not try giving square wave signals to XTAL input.

author: danellis
author_rank: Newbie
timestamp: December 25, 2013, 08:04:02 am
content: Did you set the right fuse values? I don't the AVRs output a voltage to drive the crystal unless an external oscillator is selected (the pins can be used for other things).

author: hans
author_rank: Super Contributor
timestamp: December 25, 2013, 09:39:30 am
content: Some of those square oscillators are 4-pin parts. The oscillator can, and the remaining 2 pins should sometimes be connected to GND.You may try adding 2 patch wires to the GND of the capacitors and see if it helps. I have had this issue with a FT4232HL and the required oscillator.Other times it didn't need it, so it depends a bit on the chip, PCB possibly, more importantly the crystal itself.

author: dannyf
author_rank: Super Contributor
timestamp: December 25, 2013, 01:07:13 pm
content: QuoteNo idea what might have caused it but certainly it is not your code.

author: Jeroen3
author_rank: Super Contributor
timestamp: December 25, 2013, 01:40:32 pm
content: Only pin 1 and 3 are the oscillator, the other two are gnd or float depening on the oscillator.Make sure you've soldered your crystal properly with hot-air and paste.

author: owlhawk
author_rank: Newbie
timestamp: December 28, 2013, 06:53:00 am
content: Finally got a chance to look at this again. Figured it out and now I just feel like an idiot.I had one spare AVR chip so I assembled a second board, which worked fine right away. So I knew it had to be a problem with the something on the first board rather than the design. Turned out to be a bad solder joint on one of the crystal pins on the AVR. I had checked them under a magnifying glass and they looked perfect, but once I reflowed them it started working.I guess my lesson here is that even if a joint looks good, go back over it with the iron anyway if you are having problems.Thanks for the help!

author: Jon86
author_rank: Frequent Contributor
timestamp: December 28, 2013, 11:39:06 am
content: Very easy mistake to make, at least you know now

author: Zbig
author_rank: Frequent Contributor
timestamp: December 28, 2013, 02:56:47 pm
content: When I'm done manually soldering a TQFP or similar package, what I usually do besides the visual inspection is, I'm taking a mini-screwdriver equipped with a pointy metal spike bit and gently (not to bend the pin in case it wasn't soldered properly) poke each and every leg from the side at its flush (parallel to the pad) part. I can instantly hear and/or feel when there is no usual mechanical resistance which is to be expected from the properly soldered pin. I do that because I myself was more than once deceived by a "perfectly good looking" joint.