0
\$\begingroup\$

I am having an issue with 32.768khz crystal connected to an Atmega328P (which I am using as an external source to timer2 in asynchronous mode to wake up the Atmega from sleep every second).

On a breadboard everything works fine and as expected.

However upon assembling the circuit on a PCB, the AVR never comes out of sleep. For some reason the crystal is not oscillating

Can someone explain what is the right way to design the PCB as far the crystal is concerned to ensure correct operation (including selecting the capacitors). I have read about it here n there but never given much thought to it.

To remidy the issue, I tried the following but none of them worked:

  • Tried multiple crystals
  • Soldered the crystal directly to Atmega328P TOSC1/2 pins
  • Added 22pf/10pf caps connecting the crystal pins to GND

Here's a close up picture of the crystal attached to the PCB. I had to add some jumper wires because I broke off the traces trying out multiple crystals. enter image description here

\$\endgroup\$
  • \$\begingroup\$ Datasheet for the crystal? \$\endgroup\$ – brhans Jul 23 '15 at 21:14
  • 1
    \$\begingroup\$ I would check out blog entry on AdaFruit Choosing the Right Crystal and Caps for your Design \$\endgroup\$ – Boxxylols Jul 23 '15 at 21:15
  • \$\begingroup\$ Check the crystal's specified ESR and CL values against section 9.5 of the Atmel datasheet (atmel.com/images/…); also verify that the CKSEL bits are set appropriately. \$\endgroup\$ – devttys0 Jul 23 '15 at 21:16
  • 1
    \$\begingroup\$ How do you know it's not running? Have you looked at it with an oscilloscope? Also, crystals can sometimes be a bit sensitive. Instead of using jumper wires, I suggest scraping some of the solder mask off the edge of the traces to expose enough copper to directly solder the crystals leads to. \$\endgroup\$ – DigitalNinja Jul 23 '15 at 21:28
  • 1
    \$\begingroup\$ Which sleep mode are you using? Two of the sleep modes stop even the asynchronous timer. \$\endgroup\$ – Ignacio Vazquez-Abrams Jul 23 '15 at 21:36
2
\$\begingroup\$

The problem here is that you don't have the load capacitors on the crystal. These connect from each pin to ground, and their capacitance is specific to the crystal you are using.

A resistor in the oscillator input may also be needed (\$R_L\$). The ATMega's datasheet will tell you about that I would suspect.

schematic

simulate this circuit – Schematic created using CircuitLab

When you were on a breadboard the breadboard's inherent stray capacitance was providing the function, but now you are on the PCB there is considerably less stray capacitance.

The capacitors are usually in the range of 30pf or so, but read the datasheet for your crystal to get its load capacitance and use that to calculate the right capacitor values:

$$ C_{X1} = C_{X2} = 2(C_L - C_{stray}) $$

\$C_{stray}\$ is the stray capacitance of the PCB (it can probably be ignored as it will be tiny), \$C_L\$ is the load capacitance from the datasheet for the crystal.

\$\endgroup\$
  • 1
    \$\begingroup\$ The '328P datasheet recommends 18pF total on XTAL1 and 8pF on XTAL2 for a watch crystal. \$\endgroup\$ – Ignacio Vazquez-Abrams Jul 23 '15 at 21:39
  • \$\begingroup\$ Does the 328p have internal load caps that op can turn on? \$\endgroup\$ – DigitalNinja Jul 23 '15 at 21:47
  • \$\begingroup\$ If it does they will be in the datasheet. I am not in a position to look right now. \$\endgroup\$ – Majenko Jul 23 '15 at 21:54
  • \$\begingroup\$ @Majenko Yeah, I'm at work and too lazy to check. Op should ;) \$\endgroup\$ – DigitalNinja Jul 23 '15 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.