crystal for mcu and capacity - Page 1
Forum section: electronics / beginners

author: Moriambar
author_rank: Unknown
timestamp: November 20, 2021, 10:32:40 am
content: Hi.I recently started a project featuring an stm32f103 chip (I bought a few some years ago, luckily) and I was wondering how to choose the 8MHz crystal to go with that.Designing the circuit I put in 2 20pF load caps for the osc, as well as a 1M resistor, as per the blue pill design.I was wondering: what load capacitance should my crystal have? Do I have to look out for other params?Cheers!

author: Renate
author_rank: Super Contributor
timestamp: November 20, 2021, 11:39:40 am
content: If you want to do this right, you should check the crystal spec, estimate the stray capacitance, build the circuit, measure the frequency, then adjust the capacitor value. (Obviously, you should never probe a crystal to check fequency, the probe capacitance will throw it far off.)Ok, any circuit that only has UARTs for timing considerations is not that critical. Something that is using WiFi or Bluetooth off a PLL is more critical.The Cypress PSoC 4 modules actually have digitally controlled trim capacitors on their crystal oscillators. Since I don't have a frequency meter I used the internal oscillator to feed an internal 16 bit counter. I gated that with a 1 Hz PPS signal from a GPS. Instant better than 1 ppm accuracy measurement from a cheesy $20 GPS hockey puck. 24 MHz for one second is 24e6 cycles, modulo 65536 is 13824. Capture the counter register, subtract the previous capture, subtract 13824 and you get how many Hertz off (+ or -) you are.

author: HB9EVI
author_rank: Frequent Contributor
timestamp: November 20, 2021, 11:51:40 am
content: if you cannot obtain specs about your crystal, you can either free-run it or you try a load between 15p-22p, most crystal's load is specified somewhere in that rangelike it has been said already, for most applications in those smaller mcus the frequency accuracy isn't that criticalon STM32 you have the possibility to output the HSE or PLL signal via the MCO pin, which is normally on PA8; you just have to switch the alternate function of the pin and set the necessary flag in the right RCC registerthis way you can precisely measure the frequency without influencing the oscillator

author: Moriambar
author_rank: Unknown
timestamp: November 20, 2021, 12:46:50 pm
content: Wait guys, I only use SPI and I2C, the frequency is not that critical at all. I'll restate my question:if I take a 20pF load capacitance crystal and throw in 2 20pF ceramic caps is that enough for me or chould I look for other load capacitance specs?Thanks

author: wraper
author_rank: Unknown
timestamp: November 20, 2021, 01:00:30 pm
content: Quote from: Moriambar on November 20, 2021, 12:46:50 pmDepends on MCU. Load capacitance is basically a capacitance of a single cap divided by 2 (total capacitance of 2 caps connected in series) + stray capacitance. So 20/2 + say 4pf = 14pF, which is too small for 20pF crystal but ok for some others. However some MCUs also have additional internal capacitance designed in, thus external capacitance should be lowered for those.https://www.compel.ru/wordpress/wp-content/uploads/2019/01/en.cd00221665.pdf

author: Moriambar
author_rank: Unknown
timestamp: November 20, 2021, 01:33:53 pm
content: Quote from: wraper on November 20, 2021, 01:00:30 pmOk I'm quite confused. I mean I understand what you say but I don't understand why, when using a crystal osc on my attiny/avr projects I was told "take a random 16MHz crystal, whack 2 22pF caps and you're done" and why the stm32 isn't as easy to use… I mean: my frequency is by no means crytical, as long as spi and i2c clocks are output at an acceptable level (don't need any high speed stuff).

author: wraper
author_rank: Unknown
timestamp: November 20, 2021, 01:53:11 pm
content: Quote from: Moriambar on November 20, 2021, 01:33:53 pmBecause it's a lazy answer which will work in a 95+% of cases, and the people who recommended this probably buy the crystals on ebay and don't know their spec. However it does not mean that circuit was made as it should, that oscillator frequency won't be out of the crystal tolerance, and that there is a decent margin for stable operation. AVR is not different from STM in the regard that you should actually calculate required capacitance for the crystal used. BTW I edited the previous post since I put the text in parentheses in a wrong place. should read: "capacitance of a single cap divided by 2 (total capacitance of 2 caps connected in series)"

author: Moriambar
author_rank: Unknown
timestamp: November 20, 2021, 02:16:03 pm
content: Quote from: wraper on November 20, 2021, 01:53:11 pmSo I looked into theST document about crystalsand found out my crystal is ok. They estimate 5pf stray capacitance for the pcb. So roughly for a 20pF load capacitance crystal I'm ok with 2 33pF caps.Is that correct?Thanks for the insight!ps: yes, I checked Gm and other stuff too.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: November 20, 2021, 02:19:01 pm
content: A simple search brings up complicated stuffhttps://html.duckduckgo.com/html?q=stm32+crystal+considerationsOne of the first results is AN2867, which is a 59 page application note from ST itself.https://www.st.com/resource/en/application_note/cd00221665-oscillator-design-guide-for-stm8afals-stm32-mcus-and-mpus-stmicroelectronics.pdfThe (old) advice of "just use some (1 to 30MHz) crystal and whack in some 15pf to 22pf crystals was from an era when most crystals were HC-49 sized. In the last 20+ years crystals have become smaller and variations in their load capacitance have become bigger. Microcontrollers also use much less current then 20 years ago, and this has gone so far that the crystal oscillator itself has become a sigificant part of the total power consumption, and thus the wish for crystals that need less power to drive them was born.

author: David Hess
author_rank: Super Contributor
timestamp: November 20, 2021, 07:16:46 pm
content: The crystal frequency is cut assuming a specific load capacitance, so if you can measure the frequency accurately, then you can estimate the load capacitance empirically, including parasitic capacitance, by adjusting the load capacitance until the frequency matches the specification. Trimmable oscillators replace one of the load capacitors with a trimmer.A more thorough design process would measure oscillator startup time under different conditions to ensure sufficient operating margin.None of this is really critical and load capacitors from 15 to 33 picofarads should all work fine.