The right capacitors for the (wrong) crystal..

I found this blog post where the formula is: CL=(C1C2)/(C1+C2)+Cs. If the crystal has a load capacitance of 20pF the capacitors would be just about 35pF if the stray capacitance is guesstimated to 2.5pF, because 20=(3535)/(35+35)+2.5.

But when I look into the spec sheet for an ATmega328P (section 13.3), the capacitors is to be calculated with the formula: Ce+Ci=2Cl-Cs where Ci is the internal capacitance of 18pF on XTAL1 and 8pF on XTAL2. With the same crystal and stray capacitance as before that would result in two different caps of each ~20pF (XTAL1: 20+18~=20+20-2.5) and 30pF (XTAL2: 30+8~=20+20-2.5).

The difference between the two formulas is not insignificant and I'm assuming that I should trust the manual. But would the first method yield better accuracy? And how would a "too large" or "too small" capacitor influence the crystal?

And finally: I'm using a 32kHz (20pF Cl) crystal with Timer2 on an ATmega328P and it is not 100% accurate but the frequency is consistent compared to the WDT which is definately not reliable. If I remove the 22pF caps the crystal (or rather the entire code execution) becomes defunct (spec sheet dictates that Cl>6pF requires external caps).

Thanks in advance! :slight_smile:

Check the crystal data sheet. The required capacitors are part of the crystal specification, which differs from crystal to crystal.

Note that board/trace capacitance contributes to the overall requirement.

While the spec sheet has some information, AN2519 will provide more information about not only the crystal selection and capacitor selection, but also layout and other design principles.

AVR4100 is specific to 32 kHz crystals.

The older datasheet says the two load capacitors should always be equal for both crystals and resonators...

Its not critical, getting the loading a bit wrong just pulls the frequency a bit. Getting it wildly
wrong will risk failure to start up. I've always just used 18pF or 22pF caps with a 16MHz crystal.

I've been fiddeling a bit with it today. No caps = no go. 22pF on XTAL1 only = no go. 22pF on XTAL2 only = inconsistent frequency. 22pF on both legs gives me a consistent frequency but it is not "watch perfect" - but as long as I can expect it to be consistent, it is good enough for me! :slight_smile:

Thanks for the answers, karma scattered!