Why do microcontrollerS have two oscillator pins? - Page 1
Forum section: electronics / beginners

author: charlespax
author_rank: Regular Contributor
timestamp: May 19, 2016, 09:51:43 pm
content: Over inanother threadwe are working with an STM32F103 ARM microcontroller. To save PCB space I would like to use a MEMS oscillator chip (ASDM1 16 MHz), which is super tiny.On the STM32F103 there is OSC_IN and OSC_OUT. I believe that OSC_IN is where the microcontroller reads the clock source, but I'm not entirely certain what OSC_OUT does. My best guess is that it goes HIGH to enable the external oscillator and LOW to disable it. Is this true? I could not find detailed information in the datasheet.The ASDM1 has connections for power, ground, output (OUT), and tristate input (TRI). Connecting TRI to a logic high voltage or leaving it disconnected will enable OUT. Connecting TRI to GND disables output.If what I believe about OSC_OUT is true, I should be able to connect OSC_OUT to TRI to allow the MCU to enable/disable the MEMS oscillator. Am I understanding this right?If you'd like to see the full schematic, checkout thefiles on Github, see theother thread, or click the image below.

author: Monkeh
author_rank: Super Contributor
timestamp: May 19, 2016, 09:58:32 pm
content: It is used to drive a crystal into oscillation.

author: janoc
author_rank: Super Contributor
timestamp: May 19, 2016, 10:05:45 pm
content: Quote from: charlespax on May 19, 2016, 09:51:43 pmYou have it in the reference manual, p. 125If using external clock (aka not crystal/resonator):"The external clock signal (square, sinus or triangle) with ~50% duty cycle has to drive the OSC_IN pin while the OSC_OUT pin should be left hi-Z."If using HSE crystal/resonator then the crystal goes between the two OSC pins.Not sure why is it called like that, I think it has to do with the topology of the oscillator, perhaps it is possible to measure the oscillator signal on the OSC_OUT pin or it is the pin used to drive the crystal.

author: charlespax
author_rank: Regular Contributor
timestamp: May 19, 2016, 10:18:01 pm
content: Quote from: janoc on May 19, 2016, 10:05:45 pmThank youI've been using the summary datasheet when I should have been using the fullreference manual. The document I link to has this diagram:This really clears things up. I owe you one

author: T3sl4co1l
author_rank: Super Contributor
timestamp: May 19, 2016, 11:05:23 pm
content: Usually, OSC_OUT is a CMOS pin like any other, but unlike any other, it has an unusually weak (and programmable) output drive strength, and analog feedback to bias it near VDD/2.This allows it to drive a minimal AC voltage into the crystal, which typically has an impedance on the order of ~100 ohms, or ~1.5kohms, or ~100kohms (depending on series vs. parallel vs. tuning fork crystal styles).By the way, the loading capacitors' reactance is always on the order of the crystal's ESR. For example, a 20MHz, 100 ohm crystal might specify 18pF loading, which means you need two 36pF capacitors, one to ground on either side (as seen by the crystal, they act in series, hence 36/2 = 18pF loading). 18pF is 442 ohms at 20MHz, within a factor of 4.4. (Note that actual loading capacitor *components* are smaller still, because the pins have capacitance too, which act in parallel with them. This should be documented somewhere in the IC datasheet. Just subtract it out from each capacitor, then use the result for the physical components, give or take maybe 10 or 20%.)If it were a full-strength CMOS output, notice the capacitor wouldn't matter, because it would always be pushed around by the much stronger pin. This is almost never done. In fact, though it's rarely documented as such -- this is strongly hinted at by the ICs that require an external series resistor (usually around, guess what, 1.5kohms!) from OSC_OUT to the crystal.That is, if the IC does not indicate an external resistor, then it has a controlled (weak) pin drive output. If it does require an external resistor, then it is probably a regular CMOS output pin, and can be used and shared as any CMOS clock output pin. (But test it, first. It's probably not documented as such.)In any case, the other side of the crystal (OSC_IN) couples to an analog biased Schmitt trigger, which drives the OSC_OUT pin (at whatever drive strength it's designed/configured for). The sensitivity is usually quite good (~0.1V?), so little power is required to drive the crystal, keeping efficiency good.Tim

author: rs20
author_rank: Super Contributor
timestamp: May 20, 2016, 12:11:07 am
content: Quote from: T3sl4co1l on May 19, 2016, 11:05:23 pmWoah. I always wondered why the capacitor wasn't monstered by the XTAL out pin; and I always wondered why my silly attempt at getting a crystal to sing with a 1M resistor+NOT gate didn't work out (I was a lot younger at the time, didn't pursue the issue). I believe I have learned the answer to both these issues now...

author: coppice
author_rank: Super Contributor
timestamp: May 20, 2016, 05:19:09 am
content: Its interesting to see someone consider a MEMS oscillator for a basic MCU design. The idea of these things is very appealing, as crystals are now one of the major causes of failure in well designed electronics. However, people have really struggled to get the cost performance balance right, and there don't seem to be many people left trying right now.

author: Daniyal
author_rank: Contributor
timestamp: May 20, 2016, 06:03:43 am
content: Crystals will not oscillator on its own by simply connecting one pin to the OSC_IN pin, there is an inverter inside of the MCU and it acts like an amplifier in feedback loop which energise the crystal thus it can oscillate at the right frequency.whereas oscillators will have this inverter inside of the package, it just needs power and ground it will output the desired frequency.If you want to understand why this is the case read "AN2867 Oscillator design guide for ST microcontroller".

author: Yansi
author_rank: Super Contributor
timestamp: May 20, 2016, 05:10:03 pm
content: There we have a complete application note describing how to calculate the crystal oscillators properly:http://www.ic-contract.ru/images/stm_files/stm8s/AN2867_Application_note.pdf

author: janoc
author_rank: Super Contributor
timestamp: May 20, 2016, 07:13:55 pm
content: Quote from: charlespax on May 19, 2016, 10:18:01 pmYup, that's the diagram I was referring to.Quote from: charlespax on May 19, 2016, 10:18:01 pmWelcome.Quote from: coppice on May 20, 2016, 05:19:09 amHmm, crystals being a major cause of failure? Do you have some more info on that? I have seen a lot of failed electronics and it was pretty much always due to the usual suspects - dead/cheap capacitors and blown transistors (or anything semiconductor). The remaining component types rank pretty low on the list - occasional smoked resistor or a shorted winding in something (trafo, motor, etc.). Never seen a failure caused by a crystal in modern gear. Even ancient 30+ years old crystals in old equipment are most likely going to be fine and work like new.

author: helius
author_rank: Super Contributor
timestamp: May 20, 2016, 08:21:50 pm
content: Quote from: janoc on May 20, 2016, 07:13:55 pmCrystals are especially sensitive to vibration (as they are highly stressed, brittle objects), and the ones with greater vibration tolerance are expensive. N.B. "in well designed electronics": those other failures can be anticipated and higher safety margins specified, but it's harder to do for crystals.

author: langwadt
author_rank: Super Contributor
timestamp: May 20, 2016, 08:37:08 pm
content: Quote from: helius on May 20, 2016, 08:21:50 pmand most of the failures will probably never bee seen my anyone but the manufacturer, i.e. a failed xtal means the device fails final test and gets thrown in the naughty pile

author: danadak
author_rank: Super Contributor
timestamp: May 21, 2016, 12:30:57 am
content: Be careful about interfacing to osc pins. Some UPs have complex bias arrangementson input side that if not properly handled will create a noise margin problem when usedas a digital input. I have seen datasheets that do not discuss this, but the problem ispresent. Contact FAE at vendor for resolution of what the pins actually model like.Aslo in typical osc circuits there is an R that sets xtal drive, limits power applied, whilealso providing phase shift contribution to network. Not a simple tradeoff.This ap note pretty goodhttp://cache.freescale.com/files/microcontrollers/doc/app_note/AN1706.pdfhttp://electronicdesign.com/analog/fundamentals-crystal-oscillator-designRegards, Dana.

author: coppice
author_rank: Super Contributor
timestamp: May 21, 2016, 10:29:46 am
content: Quote from: janoc on May 20, 2016, 07:13:55 pmNotice I said well designed electronics. If you have capacitors failing in significant numbers within the expected life of the equipment its not well designed. If transistors are failing due to thermal or electrical stress the equipment is not well designed. In well designed equipment crystals are the cause of a substantial number of failures.

author: janoc
author_rank: Super Contributor
timestamp: May 21, 2016, 03:00:31 pm
content: Quote from: helius on May 20, 2016, 08:21:50 pmAnd how is that different for MEMS?These are explicitly mechanical - dropping something like a MEMS accelerometer on the floor can destroy it.

author: janoc
author_rank: Super Contributor
timestamp: May 21, 2016, 03:07:03 pm
content: Quote from: coppice on May 21, 2016, 10:29:46 amThen you should probably define what you mean by "well designed electronics". If it is obscure big buck lab gear assembled by naked virgins in single quantities, sure. I don't have experience with avionics and space rated stuff, so can't speak about that.Otherwise for "normal" electronics those capacitors or semiconductors are much more likely to give up the ghost than anything else, even in well designed equipment. Caps in switching power supplies are essentially a planned obsolescence element - they will fail, it is not a question of if but when. The semiconductors could blow up for tons of reasons too - e.g. a power surge, user stupidity, hidden manufacturing fault, whatever. Poor design is not the only reason why electronics fails. Sometimes it is just not economical or possible to protect the gear against all possible risks (and then idiots tend to be very creative and resourceful).

author: coppice
author_rank: Super Contributor
timestamp: May 22, 2016, 08:36:49 am
content: Quote from: janoc on May 21, 2016, 03:07:03 pmNormal electronics includes things like your water meter or electricity meter, made at low cost in a very competitive market. It is expected to run for 10 to 20 years (depending on the utility) with a low failure rate. Early failures due to inappropriately chosen capacitors can result in big penalties for the maker, so they generally avoid them. In these types of application crystals are now one of the major causes of early failure.

author: coppice
author_rank: Super Contributor
timestamp: May 22, 2016, 08:55:19 am
content: Quote from: janoc on May 21, 2016, 03:00:31 pmNot all mechanical devices are created equal. One of the key benefits promoted for MEMS resonator oscillators is their greater tolerance to mechanical abuse. It is far harder to disturb heir normal operation with vibration, and the level of mechanical stress needed to damage them is also far higher.The characteristics of MEMS resonators are very different from crystals. For example, they have horrible temperature coefficients compared to crystals, or even ceramic resonators. You will see some MEMS oscillators with a very good temperature coefficient, but that's because they have added an elaborate temperature measurement and correction scheme on the silicon.