MCU HSE Crystal - choosing the right capacitor - Page 1
Forum section: electronics / beginners

author: Saimoun
author_rank: Frequent Contributor
timestamp: August 16, 2020, 01:52:31 pm
content: Hi 😃I am doing a project where I need a (relatively) accurate crystal. I have never used special precision crystals but my guess is a normal crystal would do. I would like though to have the best accuracy possible by laying out the PCB and choosing the capacitors accordingly.My MCU is a STM8L151G6U6 from ST, and the datasheet shows an input capacitance of 2.6pF.My crystal has a load capacitance of 9pF.My crystal traces are 10mil thick and about 300mil each - see the picture below. If I assume a stray+pin capacitance of 5pF total, that means I should choose (2*9) - 5 = 13pF, so I would choose a 12pF cap.My questions:1) Is this all wrong and the capacitance has nothing to do with precision? (I am sure I read that somewhere but I cannot find it anymore :/ )2) Is my way of calculating the cap value correct?3) Is there a way to guestimate a bit better the stray capacitance based on the length and thickness of the traces?4) In the picture you can see I route the pin to the crystal, and then the crystal to the cap. Would it be better the other way around (first pin -> cap, then cap > crystal)?Thank you!Simon

author: fmzambon
author_rank: Contributor
timestamp: August 16, 2020, 02:24:41 pm
content: Hello,I don't know the answers, but I was about to open a thread for an almost identical question (except that it would be about a CD4060 with a 32768Hz crystal).Therefore I'm very interested in the answers tooAndrea

author: voltsandjolts
author_rank: Unknown
timestamp: August 16, 2020, 03:56:48 pm
content: In your case, crystal load capacitance is calculated as:(C20 * C21) / (C20 + C21)So, you could choose C20=C21= 18pF to get a load capacitance of 9pFBUT as you say, there is pin capacitance and stray capacitance, so bit of guess work involved.To be honest, just using 18pF caps will work, maybe pulling the crstal frequency a tiny amount from nominal, but I bet you wouldn't notice.15pF might be better.And maybe 12pF at the input pin which has some 2.6pF capcitanceSo, maybe C20 = 15pF and C21 = 12pF (or otherway around?)Just use 2 x 15pF and it'll be fine.

author: Benta
author_rank: Super Contributor
timestamp: August 16, 2020, 04:20:12 pm
content: 1: inexact load capacitance will shift the resonant frequency a teeny bit.2: your calculation is correct for equal cap values.3: your guestimation of stray capacitance is a bit high. traces are normally inductive, not capacitive. I'd say 3 pF total is about right.4: routing is not critical with such short traces.

author: Benta
author_rank: Super Contributor
timestamp: August 16, 2020, 04:50:21 pm
content: Quote from: fmzambon on August 16, 2020, 02:24:41 pm32.768 kHz crystals are a completely different animal and need to be designed differently.Here's a recent thread on the subject:https://www.eevblog.com/forum/beginners/crystal-tips-(no-alistair)/

author: Saimoun
author_rank: Frequent Contributor
timestamp: August 16, 2020, 06:13:26 pm
content: Thank you all for the answers. I have been reading this Application Note from ST which is super helpful:https://www.st.com/resource/en/application_note/cd00221665-oscillator-design-guide-for-stm8af-al-s-stm32-mcus-and-mpus-stmicroelectronics.pdfIt turns out my calculations were wrong, it should be:(C1*C2)/(C1+C2) = CL - Cs with CL load capacitance of the crystal and Cs the stray capacitanceor if we choose identical capacitors C1=C2=C thenC = (CL - Cs) / 2So in my case C = (9 - 3) / 2 = 14pF(taking the 3pF stray capacitance from Benta)I am a bit confused about the pin capacitance though, reading your answer voltsandjolts it seems to be only on the OSC_IN pin? i.e. there is none on the OSC_OUT pin?And in either case, how does it get "combined" with the traces capacitance? I.e. @Benta why would you say 3pF and not 5pF (value which seems to be the "easy guess" everywhere)?EDIT: ha ha no idea how I got to this math, but the above is clearly wrongIt should beC = (CL - Cs) * 2So C = (9 - 3) * 2 = 12pF

author: Benta
author_rank: Super Contributor
timestamp: August 16, 2020, 06:55:08 pm
content: Quote from: simonlasnier on August 16, 2020, 06:13:26 pmWhy do you insist that PCB traces are capacitive? Unless they're really thick, they're more likely a bit inductive. The 3 pF are from the 2.6 pF plus a bit. Rule of thumb for stray capacitance in this type of oscillator is 2...5 pF depending on the IC.IMO, you're overthinking this. Crystal tolerance and ambient temperature will have a far higher impact than being 1...2 pF off on the load caps.

author: fmzambon
author_rank: Contributor
timestamp: August 16, 2020, 08:18:20 pm
content: Quote from: Benta on August 16, 2020, 04:50:21 pmHello,thank you for the pointerIf by "32.768 kHz crystals are a completely different animal" you mean that they need MUCH higher resistances (like you indicate in one of your posts in that thread), then I already know that. In fact I already have a (sort of) working oscillator on a breadboard.Only thing is that it runs a little slow. It loses 2.5 to 3 seconds per day, which computes to about 29 to 35ppm for a crystal which should be +-20ppm according to the datasheet.I know that the breadboard adds significant parasitic capacitance (see EEVblog #568), so I'm planning to redo the oscillator on a small separate PCB to remove the breadboard from the equation. And while I'm at it I'd like to use the proper value caps: the breadboard version uses 2x25pF caps for a 12.5pF crystal, which is only correct if one ignores the parasitics.That's why I'm interested in the proper way to take these parasitics (pin capacitances + other stray capacitances) into account.Quote from: simonlasnier on August 16, 2020, 06:13:26 pmThat is precisely one of the questions I have too. Does one ignore output pins as far as parasitic capacitances are concerned?

author: Benta
author_rank: Super Contributor
timestamp: August 16, 2020, 08:31:49 pm
content: My experience with 32.768 kHz crystals is that they run well with 10...12 pF depending on the IC. The main issue is keeping drive powerunder 1 mW.2 x 25 pF seem excessive to me.EDIT: correct is:under 1 uW (microwatt).Sorry, typo.

author: Saimoun
author_rank: Frequent Contributor
timestamp: August 17, 2020, 08:54:09 am
content: Ok thanks for the explanation.

author: AndyC_772
author_rank: Super Contributor
timestamp: August 17, 2020, 08:58:12 am
content: Unless the cost is critical, don't overlook the simple option of using an integrated oscillator module instead of a bare crystal. There's no shame in letting someone else solve the problem of building the oscillator circuit and ensuring it's operating fully within specification under all conditions!

author: perieanuo
author_rank: Frequent Contributor
timestamp: August 17, 2020, 03:58:32 pm
content: hi,you overthink.just take the crystal from the table, download his datasheet,put the capacities found there.short traces from uC to crystal and correct ground path, plus pads for parallel resistor.it may be necessary or not.and then just prototype and test with vcc spike/disruption etc and all specific method for stability regarding supply stability, in order to see if it starts the oscillation in any situation.with this method we worked with PIC's, msp and others uC, never failed, in fact just once when we omitted some 680k parallel resistor and we had osc starting failure from time to time.boss forgot to put the damn resistor in BOM...trace capacitance, forget this, mabe sensitive radio stuff is different but for some megas doesn't count.I always put crystal/resonator parallel with the chip.regards,pierre