I need capacitor selection help for a 32.768 KHz crystal and ATtiny84. - Page 1
Forum section: electronics / beginners

author: MarkS
author_rank: Unknown
timestamp: January 18, 2016, 05:18:30 am
content: I've used AVR microcontrollers in the past with no issues, but I've always used a 16 MHz crystal with the recommended 22pf capacitors. Yesterday I saw a project on Instructables for a watch that used two LEDs for binary output. It used an AVR as well, but relied on the internal oscillator and that is just too inaccurate.I thought it would be a fun project to design a similar watch, but with a 12 LED binary display. I wanted to use the 32.768 crystal, but I'm having trouble with the capacitor selection. It would appear to not be as straight forward as with the faster crystals. The datasheet for theATtiny84, on page 28, shows two different capacitance values for the two crystal input pins. The SMD crystal I was looking at has a load capacitance of 9 pF. The formula I found via Google is: C = (C1 * C2) / (C1 + C2) + Cstray, with Cstray being between 3 and 6 pF. However, that doesn't take into account the different capacitance of the MCU's crystal pins. Also, from what I could gather, the crystal's ESR is important to take into consideration, however I could not find any information as to how to add this to a circuit. The crystal I'm looking at,here, has a 90K Ohm ESR.While I don't need atomic clock precision, I would like to make this as accurate as possible. Unfortunately, I don't have any tools to measure the frequency, so no matter what I do will be a guesstimate.

author: matseng
author_rank: Frequent Contributor
timestamp: January 18, 2016, 05:41:44 am
content: And whatever you calculate will still just be a guesstimate about what frequency you'll end up with due to unknowns as the real stray capacitances and the usually extremely bad tolerances of caps. I guess that a reasonable option would be to either have a trimmer cap, or leave some populated caps to allow you to adjust the frequency by adding more caps , or make provisions in the firmware to adjust for a slightly too high crystal frequency by skipping a cycle every now and then.Measuring the frequency can be done manually over a longer period (days?) with just a stopwatch. If you can measure with a precision of one second over 10 days you're down to 1ppm.

author: MarkS
author_rank: Unknown
timestamp: January 18, 2016, 05:47:27 am
content: I figure that no matter what I do, I will not know the exact frequency. I just don't know where to start. How do I factor in the different pin capacitances on the MCU? I don't want someone to make the circuit for me, but I do need some guidance.

author: ade
author_rank: Unknown
timestamp: January 18, 2016, 07:03:43 am
content: For 32.768 I would start without any capacitors...

author: MarkS
author_rank: Unknown
timestamp: January 18, 2016, 04:58:59 pm
content: Quote from: ade on January 18, 2016, 07:03:43 amI don't want to be one of those irritating members that asks a question, expecting a certain answer, but that goes against everything I've read so far. Most sources I could find go so far as to say that the crystal will not even oscillate without the proper capacitors.

author: ade
author_rank: Unknown
timestamp: January 18, 2016, 05:12:57 pm
content: But your MCU already has internal capacitors when fused to low-frequency mode, and you are using a smaller CL crystal (9 pF).We're estimating anyway, but to take account the internal MCU capacitance, we can add them into your Googled formula above. E.g., instead of just C1, you will add (C1 + the mcu's internal capacitance at that pin).So if CM1 and CM2 are the MCU's internal cap values, the estimate formula becomes:CL = ((C1 + CM1) * (C2 + CM2)) / ( C1 + CM1 + C2 + CM2) + CstrayFrom the datasheet it looks like your MCU has CM1 = 16 pF and CM2 = 6 pF. Assuming no external caps (C1=C2=0) and Cstray of 5 pF, you get (16*6)/(16+6) + 5 = 9.4 pF which is close to your crystal's CL.Or if you buy the standard part (CL=12.5 pF), then the formula suggests that small external caps might be of benefit.But anyway it's common for MCUs to not require any external caps when used with 32 kHz crystals. They are designed that way to reduce part count. See this doc from Atmel:http://www.atmel.com/images/doc8333.pdf(You can see for prototyping they've directly soldered a 32 kHz crystal directly to the XTAL pins with no caps!!)

author: MarkS
author_rank: Unknown
timestamp: January 18, 2016, 05:16:49 pm
content: Thank you! That helps tremendously!

author: ade
author_rank: Unknown
timestamp: January 18, 2016, 05:35:50 pm
content: Chapter 4 of that Atmel note is a good read.By the way in Table 6-2 they tested and approved the ABS06 crystal at the standard 12.5 pF, 90 kOhm ESR. I think the ABS06 is pretty much the same as an ABS05 aside from being slightly larger. As a bonus it's half the price.

author: MarkS
author_rank: Unknown
timestamp: January 18, 2016, 05:46:02 pm
content: Quote from: ade on January 18, 2016, 05:35:50 pmYes it was.