12
\$\begingroup\$

I am looking at this MCU and was wondering if it makes sense to use an external crystal.

Extracted from the datasheet pg1,

*Clock management
4 to 32 MHz crystal oscillator
– 32 kHz oscillator for RTC with calibration – Internal 8 MHz RC with x6 PLL option – Internal 40 kHz RC oscillator

Internal 48 MHz oscillator with automatic trimming based on ext. synchronization*

The internal oscillator can be up to 48Mhz. The external crystal is between 4 - 32 Mhz. Why would one use an external crystal when the internal one is faster than 48Mhz given that external crystal costs money and occupies space? When should one use an external crystal?

\$\endgroup\$
  • 4
    \$\begingroup\$ the only advantage of mcu's internal oscillator is saving cost when do not need extra accuracy of external ones. \$\endgroup\$ – Mahmoud Hosseinipour Jul 11 '16 at 12:03
23
\$\begingroup\$

The internal oscillator is much less stable than an external crystal oscillator.

If I'm reading the datasheet correctly, the internal 48 MHz oscillator is only factory calibrated to within 2.9% of the specified frequency - not even good enough for RS-232. There are ways to synchronize it to an external clock, I think it's designed to be used in a USB device situation where you can lock the PLL to the USB bitstream.

An external crystal is typically accurate to around 20 ppm, parts-per-million. That's 0.002% from the specified frequency. If you need even better, there are even temperature compensated, ovenized crystal oscillators.

Additionally, you may want an exact clock speed at a different frequency, typically for communication with a device or master over an asynchronous communications channel. For this you might need an oscillator at for example 29491200 Hz (115200*256).

\$\endgroup\$
  • 2
    \$\begingroup\$ frankly, 2.9% is usually good enough for UART/RS-232 (I've used 115200 UART with at least 3.5% tolerance [due to internal 8 MHz RC's both baud rate mismatch and internal inaccuracies] for a couple of weeks without any noticeable errors); AFAIR, UART/RS-232 is fairly useable below 5% total clock mismatch and borderline useable even a percent or two higher - also, you missed the fact (noted by others) that you can use PLL to multiply the crystal clock to get speeds as high as the internal clocking. \$\endgroup\$ – vaxquis Jul 11 '16 at 11:17
  • 2
    \$\begingroup\$ @vaxquis you were lucky. 5% is the absolute maximum acceptable baud rate mismatch, and if sender and receiver are 2.5% out in different directions then you are right on the limit. \$\endgroup\$ – Bruce Abbott Jul 11 '16 at 11:45
  • 6
    \$\begingroup\$ RS232 is a voltage and pin standard not a protocol standard. \$\endgroup\$ – old_timer Jul 11 '16 at 12:29
  • 2
    \$\begingroup\$ If you use 4x oversampling you can most likely be between 25 and 50% off. With 8x can probably be worse than than and 16x even better. You only have to be accurate enough to get through one character then the receiver re-syncs on the start bit. Some may even re-sync on every edge allowing for even greater error. So uart decoding depends on the design of the receiver. Some/sane designs could very easily run forever with a 2.9% clock error and never slip a bit. \$\endgroup\$ – old_timer Jul 11 '16 at 12:39
  • 3
    \$\begingroup\$ @pipe, that is the entire point of 8 and 16x oversampling to get a better resolution of where the edges are relative to where you are sampling. Maybe the parts you are talking about are using internal oscillators. Or maybe the used junior engineers since it is a fairly trivial thing to design. You can easily sync on every edge and stay synced forever even with clock drift. Since we dont know unless we work there and are in the right department, how a receiver is designed, it is best to try to get to that few percent and or do enough testing to generate statistics on the bit error rate. \$\endgroup\$ – old_timer Jul 11 '16 at 13:26
10
\$\begingroup\$

The internal is an oscillator, usually an RC oscillator. These oscillators are far less accurate than crystals. Also these oscillators tend to drift with temperature changes.

Crystals on the other hand can be as accurate as the money you want to spend. The accuracy is needed when, for example, high speed communication is used such as USB. USB has very tight tolerances.

\$\endgroup\$
8
\$\begingroup\$

See this diagram on page 16:

ST clock tree

It looks like you can also use the crystal as an input to the PLL, allowing you to achieve internal clock speeds of 48MHz from a slower crystal.

\$\endgroup\$
7
\$\begingroup\$

The crystal oscillator feeds into an on-chip Phased Locked Loop (PLL) which can multiply and divide the crystal frequency by values between 1 and 16. So with a 8MHz crystal you can generate a 48MHz main clock for the processor. As others have said, an external crystal is more accurate and stable than the on-chip high speed oscillator.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.