Capacitors for a crystal

Should the two capacitors between the crystal legs and ground always be the same capacitance? Or does it depend?

Always the same per the data sheet. I use 22pF for all designs.

22pF (or 18pF) is okay for 4MHz to 20MHz. I think that one can be 22pF and the other can be 18pF.
I don't know what it depends on, the crystal itself feels happy with those capacitors.

I think the keyword is "Pi-network"
The two capacitors are in series, across the crystal.
Too much imbalance, and the oscillator won't start.

Leo..

The reason I ask is because the Atmega328 datasheet specifies different "pin capacitances" for TOSC1 and TOSC2 when using a low frequency oscillator. I've been using matched capacitors and have wondered if I'm not really doing it right.

Here's the relevant table in the datasheet:

32Khz low frequency section.
"Crystals specifying load capacitance (CL) higher than 6 pF, require external capacitors..."

That translates to me as: Because of the internal caps, no external caps are needed if you use a 6pf crystal.
You could add a small external tuning cap (twisted wire) across the crystal if you want to finetune the clock for e.g. timekeeping.
Leo..

You might find this link useful !!

In the attached PDF it is explained why the caps are required for crystal oscillator.

And it says -
The optimum load capacitance (CL) for a given
crystal is specified by the crystal manufacturer.
The equation to calculate the values of C1 and C2 is

CL = Cs+( ( C1*C2 ) / ( C1+C2 ))

Usually C1 and C2 are selected such that they are approximately equal

Hope this helps ! :slight_smile:

Crystal Oscillator Circuit Design 2001SEP06_AMD_AN.PDF (51.9 KB)

Wawa:
That translates to me as: Because of the internal caps, no external caps are needed if you use a 6pf crystal.
You could add a small external tuning cap (twisted wire) across the crystal if you want to finetune the clock for e.g. timekeeping.

I think that only works if the stray capacitance is zero. The problem is you can only fine tune in one direction -- slower. So if the crystal is running slow to begin with there's nothing one can do. I tried a 6pF crystal soldered directly to the pins as Atmel suggests for prototyping, in order to minimize stray capacitance. It ran 48ppm slow which is unacceptable. I went back to the 12.5pF crystal I had been using along with external capacitors. Without caps that one ran fast by 52ppm. I tuned it by selecting capacitors to within 3ppm at it's turning temperature. Good enough. But I haven't been sure if I should be using asymmetric capacitors or, even if that's the case, if I should worry about it.

rp14:
And it says -
The optimum load capacitance (CL) for a given
crystal is specified by the crystal manufacturer.
The equation to calculate the values of C1 and C2 is

CL = Cs+( ( C1*C2 ) / ( C1+C2 ))

Usually C1 and C2 are selected such that they are approximately equal

Thanks for that. Atmel has a detailed app note about selecting 32.768kHz crystals for their AVR chips. It has the same equation, with stray capacitance added in as well. But is total load capacitance all that matters? If that were true then a crystal that worked well with 12pf & 12pF capacitors would work equally well with 7pF & 42pF capacitors. That seems unlikely.

Maybe it doesn't matter, but I thought it was worth asking as I'd like to have as accurate a time base as I can get. I wish I'd studied more electronics in school.

jboyton:
...I'd like to have as accurate a time base as I can get.

Then use a DS3231. Not only is it deadly accurate out of the box, but it is temperature compensated and has a software settable capacitor trim circuit. I just bought 5 ZS-042 modules for about $5.
...and I don't work for Dallas... :slight_smile:

aarg:
Then use a DS3231.

That was my original plan. But it's too big an IC for my application. I should be able to obtain similar accuracy using an AVR as an RTC. I just don't want to overlook anything simple.

Obtain similar accuracy using an AVR ? Okay, the accuracy of the ATmega chip is not even close to the DS3231, but you might get half-way. The ATmega328P has in internal temperature sensor, but you need the temperature of the crystal, so you have to add a temperature sensor. The ATmega328P can measure its own VCC, perhaps you need that as well. You have to encapsulate the crystal to prevent moisture or dust near the wires. Then you need some super fancy compensation curve in software. Maybe I have forgotten something.

I don't know, pressure? Vibration? Radiation?

I'm probably getting a little ahead of myself. I'm working under the assumption that temperature will be the primary source of drift and voltage a secondary one. Although the AVR internal temperature tracks the crystal F/T curve relatively well, at 1°C per step it is a little coarse. But I have a precise temperature sensor already as part of the project and it will be in close proximity to the crystal. Adjusting for temperature alone it has proven easy to stay within 1ppm over a fairly wide temperature range. I have only experimented with the effect of voltage variation enough to see that it does have a small effect. I have plenty of flash for calibration tables. It will be fun to see how it turns out.

So here's how it has turned out so far, still only in breadboard form:

The breadboarded prototype with an Atmega328 and a 32.768kHz watch crystal coupled with a precise temperature sensor (BMP280) has proven to be quite accurate. More accurate than a DS3231 straight out of the box and just as accurate as a DS3231 that has had its aging register tuned. I tested the two at room temperature, refrigerator temperature (5°C) and at freezer temperature (-20°C). Technically the freezer was below the operating temperature range of the DS3231 (commercial version), but it worked just fine.

The basic idea I followed was to determine the F/T curve for the watch crystal by varying the temperature and measuring the frequency. These crystals have a parabolic F/T curve, so three parameters define the shape of it. The one I've been testing with has this shape:

ppm_error = -3.15ppm -0.0360 * (T-24.00°C)^2

In addition there is a dependence on Vcc that is small but roughly linear:

ppm_error = 1.7 * (Vcc - 3.30V)

I check Vcc and also do a temperature conversion once per minute and adjust the total ppm_error at that time. Also, once each minute the error is accumulated. When the error reaches a threshold value (currently 125ms) the clock compare time is pushed or pulled by that amount. I find that I have to stare and concentrate carefully at the display to see when a second is really 7/8 or 9/8 seconds instead of 1 second.

Average current draw is around 1uA when the display is off.

It seems like a reasonable way to make an accurate clock, except that the process of determining the calibration values is tedious. At room temperature the clock was drifting at a rate of about 1 second per year. At freezer temperature it was about 1 second per 11 days. These values were the same or slightly better than the DS3231 I tested.

jboyton:
That was my original plan. But it's too big an IC for my application. I should be able to obtain similar accuracy using an AVR as an RTC. I just don't want to overlook anything simple.

There is an 8 pin version of the DS3231. It's barely bigger than a crystal.

aarg:
There is an 8 pin version of the DS3231. It's barely bigger than a crystal.

The DS3231 doesn't come in an 8-pin package. You are probably confusing it with the DS3231M, a completely different chip that unfortunately has a very similar part number. The DS3231M uses a counter based compensation technique instead of a capacitor array. It is less accurate than the DS3231.

I did consider using it. It's about the same length as the crystals I've been using but around three times as wide. And the traces to the pins increase its effective size. Unfortunately the really tiny SMC crystals have too high an internal resistance to work with the AVR low frequency oscillator. I still don't really know how much space I need (learning Eagle is my next project). It could turn out that the DS3231M would be a better (albeit less accurate) solution.

On the other hand this appears to be simple and elegant -- once calibrated. I am jealous of the Teensy and Zero since those processors have RTCs built in. But I couldn't justify an ARM processor for what I'm doing. I really wanted to use an ATtiny. But it just wouldn't quite work.

DS3231M,

Timekeeping Accuracy ±5ppm (±0.432 Second/Day) from -45°C to +85°C

DS3231,

Accuracy ±3.5ppm from -40°C to +85°C
So maybe a little less than ±0.432 Second/Day? 0.3Second/Day?
Maybe a second different after 7.7 days?
1s/(.432 - 0.3) sec/day = 7.7 days
~4 seconds/month, 48 seconds/year.

Think it'd be that noticeable?

@jboyton, don't get the impression that I'm disinterested in your custom circuit. In fact, I wanted to build something like that - the only difference is that I also want to enclose it in an RF shield and at the same time use a heater to maintain a stable temperature, slightly above room temperature.

I'm not confusing the DS3231 with anything. I am indeed referring to the DS3231M but I was not aware that the compensation is different. I've never used it, so I never looked up the specs.

I guess "confuse" was the wrong word. They are different parts, although as CrossRoads points out the specifications are not hugely different. The DS3231M also draws a little more current in time keeping mode, probably because it performs more frequent temperature conversions. I have spent a lot of time reading RTC datasheets lately. :-)

The basic idea isn't custom. It's straight out of an app note from Atmel.

I'm trying to make something very small (~1" square), very light (~1oz) and have it last for at least one year with a coin battery. I'm not experienced enough to know what I can do.

How about DS1307 with a good crystal then? 500nA, 0.5uA, current draw, vs at least 110uA for DS3231 and 130uA for DS3231M.
Use a 5PPM crystal, should have comparable drift over a year, but using less power.
http://www.digikey.com/product-search/en?pv537=15&FV=fff4000d%2Cfff8016d%2C22c0060&k=32.768&mnonly=0&newproducts=0&ColumnSort=0&page=1&stock=1&quantity=0&ptm=0&fid=0&pageSize=25