Come see Altium at Embedded World, Booth 4-305, and discover our industry-leading suite of solutions!

How Important is Your Microcontroller Clock Source?

Mark Harris
|  Created: October 26, 2021  |  Updated: November 29, 2023
How Important is your Microcontroller Clock Source

Microcontrollers are reliant on their clock source. The processor, the bus, and the peripherals all use the clock to synchronize their operations. The clock determines how fast the processor executes its instructions, so it is fundamental to performance. But how important is the clock source? What is clock frequency in microcontroller?Does it matter how accurate it is? The short answer is that it depends… it depends on what the microcontroller is doing and its interfaces.

Two considerations need to be taken into account: the clock’s speed, which determines how fast things happen, and the clock’s accuracy, which determines the consistency of the period between each clock tick and how the clock speed can change over time.

Why the Clock Source Matters

The microcontroller’s central processor can be thought of as a synchronized chain of logic blocks that perform a specific function. If thesystem microcontroller clock runs too slow, the processing takes longer. If the clock runs too fast, there may not be enough time to complete the required operations before the next set begins—the processor interfaces with a range of different component blocks, from dynamic memory to interface pins. Any significant error in clock speed will have unpredictable consequences for internal microcontroller operations.

Data Sampling

The microcontroller clock signal will govern the conversion rate of any analog-to-digital operations. The clock’s speed will determine the maximum rate at which the analog signal can be sampled; the clock’s accuracy will determine the sampling rate’s accuracy. Suppose you are recording a sample twice a second with a timestamp. In that case, it doesn’t take long before a one percent error in the clock’s frequency (not uncommon with internal oscillators) removes any correlation between your sample’s timestamp and the time shown on your wall clock. With a 1% constant offset of the clock source, your sample’s timestamp will be out by over 14 minutes every day.

Waveform Generation

As for data sampling, the microcontroller clock signal will govern the conversion rate of any digital-to-analog operations. The clock’s speed will determine the maximum frequencies that can be generated for the analog signal. The accuracy of the clock will determine the accuracy of the generated waveform.

Asynchronous Serial Communications

A critical application for the microcontroller clock signal will be to manage asynchronous communications where the clock signal determines when the incoming data stream is sampled; once the start bit is received and the waveform of the outgoing data stream in terms of when transitions between each bit of data occur.

With asynchronous communications, the transmitter and receiver are reliant on having the same clock speed for encoding and decoding data streams. However, these clocks do not need to be synchronized; they just need to have sufficiently equal clock rates. This is because the receiver starts processing the incoming data stream when detecting the first edge on the signal line. It then needs to maintain the correct clock speed for the data stream’s duration to sample the data bits at the correct times. The required accuracy will be dependent upon the window where the data has to be sampled. Each data bit will potentially have a rising edge and falling edge to its signal where the data’s value is indeterminate, leaving the period between the edges when the data is valid and can be sampled.

This sampling period will depend on the type and length of the communications link. Long transmission lengths and cables with a high capacitive will increase the rise and fall times. The presence of noise can also increase the time required for the signal to stabilize.

It will also depend on the clock speed and the message format. For short data streams, the accuracy requirements can be quite loose as the sampling clock resets every time a new data stream is received. However, for high-speed serial communications with long data streams, the required accuracy can become more precise. For example, the CAN bus protocol makes it very sensitive to system clock skew to the extent that the use of any non-crystal-based clock signal source may be problematic.

Taking the example of UART devices, we can see that the absolute clock rate is unimportant because the UART receiver synchronizes itself at the start of every frame. The issue simplifies what differences between the transmit and receive UART clocks can be tolerated.

Clock Source options

There are usually a few different options to choose from when selecting a clock source for any particular microcontroller. Specific options will depend on what make and model of microcontroller clock you will be using, so we’ll discuss all the standard options here.

The different options are principally differentiated by their accuracy, cost, and component count. Using an internal clock source that all good microcontrollers include will be the cheapest and least complicated option but will usually be the least accurate. Using an external clock source will improve accuracy but at the cost of requiring additional components to be added to the circuit board and increasing your design’s complexity.

Which option you select will be governed by what performance you require and what constraints you have in terms of board space and budget. As there are always several alternate options to generate a clock signal for any given microcontroller, study the datasheet for your particular device. This will generally provide some great information on what types of clock sources you can use and how best to implement them.

Internal oscillators

Microcontrollers usually come with an internal resistor-capacitor oscillator to generate a basic clock signal and a phase-locked loop to provide a frequency multiplication function. The issue with using an internal oscillator is they are significantly less accurate than external oscillators with poor frequency stability. This inside of a microcontroller chip is, by definition, a less-than-ideal place to locate any RC circuit. This comes from the high-temperature dependency of RC circuits and inherently wide component tolerances. Typically, a microcontroller with good thermal management can deliver a clock signal with an accuracy in the range of 1% to 5%. This may be good enough for some of the slower asynchronous communications buses and for managing low-frequency analog signal processing. Still, in most typical applications, this will be too inaccurate.

It’s probably worth briefly mentioning that the internal oscillator’s performance can be improved by using a phase-locked loop to allow a more accurate external clock signal to correct the internal clock signal. However, if an external clock signal is available, then it makes sense to use this instead of the internal clock unless the microcontroller has any specific constraints that would prevent this.

External oscillators

Clock sources for microcontrollers come in two main types: mechanical resonant devices, including crystals and ceramic resonators, and passive RC oscillators.

The most basic form of the oscillator is the RC circuit, emulating the internal oscillator circuit but using components with higher precision values and using thermal management techniques to isolate the components from the heat generated by the microcontroller clock and any other hot elements of the circuit. While this can improve accuracy by at least an order of magnitude, it is by far the least accurate option for an external oscillator, and better solutions are available for a comparatively similar cost and footprint size. The clock generated by the RC circuit will also be affected by fluctuations in power supply levels and susceptible to electrical interference, limiting their usefulness in most typical applications.

Crystal oscillators are the most common form of external oscillators where a precision clock signal is required. A quartz crystal and supporting circuitry provide excellent stability and precision. A typical low-cost crystal oscillator can have an accuracy better than a millionth of a percent—more than enough for all but the most time-sensitive applications. However, the quartz crystal can be affected by environmental factors that may require additional protection. The supporting circuit for the quartz crystal can also result in a high impedance output requiring additional impedance matching to integrate with the rest of the circuit. Using an off-the-shelf crystal oscillator module rather than discrete components can reduce susceptibility to environmental effects and make the board design more straightforward if your budget allows it. They generally provide a low impedance square wave output that makes integration with the rest of the circuit design simpler with very similar accuracy to using a discrete crystal.

An alternative option is a silicon oscillator based on an IC resonator circuit that is simple to implement with around 0.05% accuracy. Slightly better than an external RC circuit but nowhere near as good as a crystal oscillator. However, silicon oscillators are more rugged and reliable than crystal oscillators, ideal for operating environments where the device could be subject to severe mechanical vibrations.

Finally, ceramic resonators are available that are not quite as accurate as a crystal oscillator but more accurate than a silicon oscillator. Based on a piezoelectric ceramic material, they use resonant mechanical vibrations to generate a clock signal. Their main advantage is that they come in a simple integrated package with a smaller footprint than a crystal oscillator and its supporting components. However, like crystal oscillators, they are sensitive to environmental factors, including temperature, humidity, vibrations, and electrical interference.

When choosing an external oscillator, the power consumption of the options may be a factor in your decision. The power consumption of discrete oscillator circuits is primarily determined by the feedback amplifier’s supply current and its capacitance values. A typical crystal oscillator circuit will draw tens of mA. Ceramic resonator circuits typically require larger load capacitance values than needed for crystal oscillators, requiring more power. The power consumption of silicon oscillators is mainly proportional to the operating frequency. Still, they come in a range of options, from low-power devices that draw a few mA to standard devices that draw tens of mA.

Conclusion

To sum up, what type of clock signal you need to use for your microcontroller will depend mainly on the nature of the device it’s embedded in and its operating environment. Interfaces with high-speed asynchronous communications buses and high-frequency analog signals will drive the need for an accurate clock signal. Suppose the device needs to operate in a harsh environment, whether that is over a wide temperature range, in high levels of electromagnetic interference, or subject to mechanical vibrations. In that case, it can limit the choices available. A microcontroller clock that doesn’t have such time-sensitive or environmentally challenging requirements can get away with a cheaper solution.

If you want to know more, why not browse our product page for a more in-depth feature description or call an expert at Altium?

About Author

About Author

Mark Harris is an engineer's engineer, with over 16 years of diverse experience within the electronics industry, varying from aerospace and defense contracts to small product startups, hobbies and everything in between. Before moving to the United Kingdom, Mark was employed by one of the largest research organizations in Canada; every day brought a different project or challenge involving electronics, mechanics, and software. He also publishes the most extensive open source database library of components for Altium Designer called the Celestial Database Library. Mark has an affinity for open-source hardware and software and the innovative problem-solving required for the day-to-day challenges such projects offer. Electronics are passion; watching a product go from an idea to reality and start interacting with the world is a never-ending source of enjoyment. 

You can contact Mark directly at: mark@originalcircuit.com

Related Resources

Back to Home
Thank you, you are now subscribed to updates.