13
\$\begingroup\$

Let's look at STM32L4 microcontrollers, for example. I can use Low Speed External oscillator (LSE), or High Speed External oscillator (HSE). LSE can run all the time consuming very little power. It can run not only the RTC, but, thanks to PLLs, also can be used as main clock source of the processor core up to tens or hundreds of MHz. On the other hand, HSE cannot be used for RTC, and also it consumes more power.

My question is then: do we ever really need the HSE? Do we ever need quartz crystals running at a dozen or so MHz? Isn't LSE good for everything and can we maybe forget that high speed crystals exist at all? Or are there maybe situations when high frequency crystals do something better and it's necessary to use them?

I'm mostly interested if there are any hard parameters that can be shown and compared, that would show that high frequency quartz is better at something.

\$\endgroup\$
0

6 Answers 6

26
\$\begingroup\$

STM32L4 cannot directly use the LSE as a PLL source. The reason for this is also the reason why you'd prefer a higher frequency crystal: phase noise.

The 32768 Hz crystal oscillator generates a sine wave, typically with about 2 Vp-p amplitude. This gives a ramp rate of about 1V/5µs. Now if there is 1 mV of noise from any source, it will cause the clock edge to move by +- 5 ns.

That's not much of an issue if each of your clock cycles is 30 µs, as it is with the 32768 Hz frequency. But if you use a PLL to multiply this to 80 MHz CPU clock, each clock cycle is only 12 ns. A well designed PLL can filter out some of this jitter, but this depends on the characteristics of the VCO used. The higher the frequency multiplication ratio, the more demands this places on PLL implementation. STM32 integrated PLLs only support up to 100x clock multiplication.

The alternative for higher ratios is to use Clock Recovery System (CRS) to control the internal HSI48 oscillator based on the LSE frequency. This is not a phase-locked-loop but just automatic trimming of the internal oscillator. The frequency trimming step is 0.11 %, so you will on average be +- 550 ppm away from the LSE frequency. Typical 48 MHz crystal oscillator would have error less than +- 50 ppm.

For highest timekeeping accuracy, you might actually want to do the opposite: trim the 32768 Hz LSE oscillator based on a high-speed oscillator. This way you can use a power hungy temperature compensated oscillator (TCXO) when running, and trim the RTC frequency so that it stays more accurate when in low power state.

Summary: Using LSE + clock recovery is a fine solution if your application demands a 32768 Hz crystal for low power timekeeping and can tolerate error in the high speed clock. If you need accurate high speed clock, or have no use for the 32768 Hz crystal, using a high speed crystal directly gives better accuracy.

\$\endgroup\$
24
\$\begingroup\$

You simply cannot derive any arbitrary clock from 32768 Hz. Your PLLs can typically only do integer multiples, and with the dividers in typical MCU clock trees, you could do but a very limited set of rationally related clock frequencies.

That won't help you when you need a specific clock for a bus (say, USB, Ethernet), or need to drive an adc at a specific rate that is not covered by these very limited abilities to generate clocks from a very low speed reference.

Also note that there might be significant difference in jitter and long term clock stability and accuracy between whether crystal you use to generate your 32768 Hz for RTC purposes, and what you need for the rest of your system. Generally, the PLLs within a microcontroller will be optimized for things like locking quickly and being low power, whereas your application might need a better high frequency clock than you'd be able to generate with these.

\$\endgroup\$
8
  • 1
    \$\begingroup\$ I can get basically any clock I need. At least I've never had a problem with that. Also, STM32 have a Medium Speed Internal resonator (MSI) that is "auto-trimmed" with LSE. That's the way one can get high frequencies. Maybe jitter is the thing? But that's the point of my question. I'm wondering if there are any real hard parameters that can be shown and compared, that would show that high frequency quartz is better at something. \$\endgroup\$
    – Manx
    Dec 6, 2023 at 3:02
  • 5
    \$\begingroup\$ you might not need a different clock, but that wasn't the question, was it? I pointed out these parameters, namely jitter, stability and accuracy, intentionally! \$\endgroup\$ Dec 6, 2023 at 3:13
  • 14
    \$\begingroup\$ No, that's not hand waving! These are quantifiable qualities that you'll find in oscillator and microcontroller data sheets! I can't tell you what is better than the other without actually referring to concrete parts! You generally pick parts to fit your purpose, not the other way around, so you'd typically start with a requirement from which you can infer needs for example about frequency accuracy and jitter (these are sometimes conflicting interests!), then you look at whether your microcontroller together with an appropriate low frequency oscillator could achieve these, and whether it's \$\endgroup\$ Dec 6, 2023 at 3:26
  • 14
    \$\begingroup\$ @Manx "does everything you personally need" and "does everything any engineer anywhere needs" are two very different things. Just because you've never needed one doesn't mean no one ever needs one. \$\endgroup\$
    – Hearth
    Dec 6, 2023 at 5:44
  • 4
    \$\begingroup\$ Indeed the high frequencies are not easy to synthesize with a PLL from 32kHz, but they actually aren't made directly. An multi-MHz RC oscillator is just auto-calibrated to some value with the 32768 Hz crystal to within 0.25% and the that clock is used for PLL input (with appropriate prescalers, multipliers/feedback dividers, and postscalers, as usual). \$\endgroup\$
    – Justme
    Dec 6, 2023 at 18:34
12
\$\begingroup\$

If you require to do some things related to frequency or time done with better than the datasheet mentioned 0.25% precision for LSE trimmed operation at the system clock frequency, then you can't use LSE trimmed RC for timebase and that's really it then and must use a HSE crystal.

So yes, if you anyway need a LSE crystal, maybe for actual timekeeping, and don't have much requirements for MCU core speed precision or tolerance, then you can use LSE crystal.

You are only considering the usage of clock sources on one specific family of MCUs, but still asking in general if standard high frequency crystals like 8 MHz are better in some regard than 32768 Hz RTC crystals.

And yes they are in many regard.

32768 Hz RTC crystals are large tuning fork crystals and they are very sensitive mechanically and electrically as they are so low power. They generally do not provide high accuracy over a wide temperature range. As the startup time depends on frequency these start up slowly until they oscillate stably.

A typical crystal of say 8 MHz is much smaller, easier to design and get oscillating. They have better temperature stability over a wide range and start up faster.

Generally, for LSE crystal, the basic option is only a 32768 Hz watch crystal because it's so widely available. From that it may be difficult to synthesize any frequency you want with enough precision unless fractional PLLs are used. The PLL also needs to work with very low input frequency if you want multiple tens or hundreds of MHz out.

Which is why in STM32s you name use the RTC crystal to just calibrating an internal RC oscillator to be near the nominal and you use the RC oscillator output for PLL - not the RTC crystal directly.

And not all STM32 can do that.

Sometimes, for stable short term (i.e. jitter free) and stable long term operation (drift free) you simply use a normal crystal.

Of course if your application can work with RTC trimmed RC oscillator then that's fine, but don't expect other applications to be able to work like that. For example Ethernet and USB are buses that require very strict frequency and tolerance.

And since the LSE can be used to calibrate the MSI only up to +/- 0.25%, it simply is out of range for USB and Ethernet.

But the STM32L4 does not have Ethernet so that's not a problem, and the USB it has goes only up to 12 Mbps and already uses other tricks to keep itself syncronized by using the USB packet SOF symbols which even allows for crystal-less USB operation.

\$\endgroup\$
2
  • \$\begingroup\$ Interesting point about temperature stability - the 32768 crystal was invented for watches, which are meant to be worn on your wrist. That's going to be pretty close to body temperature all the time. \$\endgroup\$ Dec 6, 2023 at 21:57
  • 1
    \$\begingroup\$ @MarkRansom I originally did not mean that, but might as well explain. The crystal could be rated for -10 to +60 C operation only, and it could have -50 ppm temperature stability at extremes. So they rarely are available at industrial range. And the frequency curve is highest at nominally 25C, and in real world that's between 20C and 30C. It quite rapidly falls out of -100ppm range. Standard crystals have +/- curve. \$\endgroup\$
    – Justme
    Dec 7, 2023 at 7:04
7
\$\begingroup\$

Consider a STM32L412K8U6TR. The only direct use the 32.768kHz crystal has is for the RTC (it can optionally be fed to a GPIO as well). The watchdog is clocked off the internal low frequency RC oscillator.

Indirectly, in 'PLL mode' it can be used to trim the MSI oscillator to a claimed +/-0.25%, however there are only a few frequencies you can select (12 to be specific). If you select 100kHz from the drop-down list in the example I've shown, you'll actually get approximately 98.3kHz (+/- 0.25%). There are no other PLLs available if you're using the MSI oscillator, just dividers.

enter image description here

If you need a specific freqency (like 100.0kHz) or a more accurate clock than the internal RC oscillator or tuned MSI oscillator for anything else you need to add a high-speed crystal, resonator or external oscillator. It's also not certain how long it will take the external 32.768kHz crystal to start, and how long it will take the MSI self-calibration to work, the first because they won't guarantee something that depends on external components and the second, if they do I don't see it.

At temperature and voltage extremes the internal RC oscillators can vary quite a bit without firmware or hardware trimming. If I had such an application I would look very carefully at the datasheet numbers to ensure the trim range is guaranteed to bring it into even the 0.25%. On the other hand, for a benign situation (office environment, low cost product with no great expectations of reliability) you can likely do without a crystal for the USB and the user will not notice any degradation. A few pennies saved and a bit of board space (maybe power savings).

\$\endgroup\$
4
\$\begingroup\$

Are you aware of how a PLL does what it does? See here: What is the purpose of PLL in a general microcontroller

Therefore, a PLL running off a source clock closer to the output frequency is going to be more faithful to the source clock simply because the voltage controlled oscillator (VCO) in the PLL outputs fewer output clock cycles before being updated/constrained by a source clock cycle. Multiplying the frequency by a huge amount would be like you trying to count seconds while looking at a clock that only struck once per year. You're going to be way off compared to if the clock struck every few seconds.

That means every parameter I can think of is affected. After all, a free-running PLL, which is the extreme case of multiplying a very low frequency drifts into nonsense since it's just the VCO completely unconstrained by the crystal source. What parameters are different between the VCO in the PLL and the input crystal? All of them so those get more and more distorted when you try to multiply the frequency by ever increasing amounts. As you increase the multiplication, your output clock characteristics should approach those of the VCO in the PLL. Going the other way, they should approach the characteristics of the crystal source.

\$\endgroup\$
1
\$\begingroup\$

Using 2 different crystals (32KHz and a MHz part) is an optimization of the system's power consumption. The 32768Hz crystal allows the system to go into low power modes while maintaining an accurate clock signal, while The MHz crystal allows the system to have high performance modes, at the cost of higher power consumption.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ If the point is to start quickly from sleep into high speed running mode, or simply run at high speed, then it is better to not use a crystal at all. So this reason alone is not enough to warrant the use of high speed crystal. That's why the MCUs have internal oscillators. So this does not really explain why high speed crystals are better than low speed crystals. \$\endgroup\$
    – Justme
    Dec 6, 2023 at 13:41
  • 1
    \$\begingroup\$ The keyword is accurate. Crystals have ppm level accuracy, with relatively predictable temperature dependency. RC oscillator error is measured in %, with an unknown temperature drift. \$\endgroup\$
    – Lior Bilia
    Dec 6, 2023 at 15:40
  • 1
    \$\begingroup\$ Yes but your answer never said anything about high accuracy for high speed crystal. If you don't need accuracy but need just high speed then use internal oscillators. If you need high accuracy also for high speed operation then you need a high speed crystal. The reason why 32768 kHz is most often used is to keep accurate wall clock time. \$\endgroup\$
    – Justme
    Dec 6, 2023 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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