The Heart of An Embedded System, And Its Espresso Shot: Clocks and PLL

Kshitij Vaze
5 min readFeb 2, 2024

--

Hello everyone! Welcome to my blog. If you are new around here, let me introduce myself. I am Kshitij Vaze, a 20-year-old based in Pune, India. I am in the third year of my Bachelor’s degree in electronics and telecommunication Engineering. I am also a part of my college’s robotics team, Team Automatons, where I work as an Embedded systems engineer.

The objective of today’s blog is to deliver an overview of the Clocks and PLL of a Microcontroller, its types, sources, functions, and a few other niche, but pretty cool concepts. I hope you’ll stick around for an informative and interesting read!

I am sure most of you are familiar with a march past. Think about the marching band, the group of instrumentalists who march at the very front. To be specific, think of the marching drums. Upon a closer look, you’ll notice that the entire parade matches its pace to the tempo of the big fella beating the drums. The faster the big man plays, the faster the band walks; and vice-versa. In simpler terms, the beats of the drum synchronize every member and their role in the march.

In the computational parade of data, bits, and voltage, the role of the drum is played by a tiny little component called the Clock. Technically speaking, it generates a signal (usually a square wave) at a very precise and accurately tuned frequency. Analogous to the blood flowing in our body being responsible for the transfer of numerous things like oxygen, and nutrients (idk what else, I ain’t a biology student am I), etc, the Clock signal (Clock Pulse as it is called) is responsible for powering and synchronizing all peripheral operations and functioning. The Clock, in this sense, acts as the heart of the processor.

Now, how exactly does this clock produce the pulse? Well, we have 2 groups of clocks based on the answer to this question.

The first group would be the Mechanical resonators; which generate the Clock pulse due to something called the Reverse Piezo-Electric effect. Lemme get you up to speed. Certain materials produce a voltage difference between the ends of their physical boundary when subjected to mechanical stress. This is called the Piezo-Electric effect (Basically, you squeeze a small rock to get a small shock). Now, the inverse of this phenomenon is true as well, where you apply an alternating voltage to the material to make it vibrate, which proves to be incredibly useful when we wish to generate a pulse. We place a piece of crystal between 2 live metal electrodes. Upon applying an alternating current to the crystal, it vibrates and produces a near-perfect pulse on one of the electrodes. This is further filtered and processed and finally transferred to the rest of the peripherals for their functioning

The second group would be the RC phase shift Oscillators, which deploy a resistor-capacitor network along with an op-amp in a feedback loop configuration to produce a signal of a specific frequency. To generate a clock signal, the phase of the generated signal is supposed to be exactly 360 degrees (or a multiple of 2π), throughout the feedback loop, and the closed-loop gain should be exactly 1 (Barkhausen’s Criteria). However, this method is known to be highly inaccurate due to its sensitivity to external factors, like humidity, temperature, etc. The sensitivity arises due to its dependance on the values of the physical components (resistance and capacitance of the tank circuit).

In the context of the microcontroller that I have worked with the most:- the STMF407-DISCOVERY; the clock distribution and architecture are, well, fascinating to say the least. For, well simplicity, I shall restrict the scope of this blog to the system and bus clock, as I haven’t explored specific application clocks like the I2S or Ethernet clock. The root of the clock tree is the SYSCLK — The system Clock. This is the main processor clock that drives read and write operations to/from the processor to the rest of the peripherals. 5 possible clock sources can be used to drive the SYSCLK, 3 high speed and 2 low speed options. Let’s take a look.

The first source is a HIGH SPEED EXTERNAL oscillator (HSE), which is provided by an external ceramic/crystal resonator. The HSE Clock source has the advantage of producing a very accurate clock signal, but it also consumes more power. The frequency of the HSE Clock source can range from 4 to 26 MHz, depending on the external oscillator or resonator used. The HSE Clock source can also be fine-tuned to achieve the highest clock accuracy for RF applications.

The next is called the HIGH SPEED INTERNAL (HSI), which is supplied by an RC Phase shift oscillator. The maximum that this source can provide is a modest 16MHz. Although it has a blazingly fast start-up time and consumes way less power than the HSE, it is highly temperature-sensitive.

Then comes the LOW SPEED EXTERNAL CLOCK (LSE), generated from a 32.768 kHz low-speed external crystal or ceramic resonator. It has the advantage of providing a low-power but highly accurate clock source to the real-time clock peripheral (RTC) for clock/calendar or other timing functions. The LSE Clock can remain enabled in all low-power modes and in VBAT mode because it belongs to the RTC power domain.

Then, the LOW SPEED INTERNAL (LSI), is a low-speed internal RC oscillator that can be used as a low-power clock source for some peripherals, such as the independent watchdog (IWDG) and the auto-wakeup unit (AWU). The LSI Clock frequency is 32.78 kHz. The LSI Clock can be kept running when the system is in stop or standby mode, but it is not functional in shutdown or VBAT mode. It is not very accurate and cannot be calibrated.

Finally, the Espresso shot of the SYSCLK, the PHASE LOCKED LOOP (PLL). Just like a dark, strong shot of dark roasted Espresso drives me at my maximum energy, this is a circuit that is driven by either the HSE or the HSI and is used to drive the SYSCLK at the highest value possible. It uses a divider, a multiplier, and an output divider to scale the input clock signal to the desired output frequency at the highest possible value, a whopping 168 MHz in my microcontroller.

This would be a good point to conclude today’s blog. If you’ve made it till here, thank you so much for reading through. Do let me know your thoughts, and as always, my DMs, comments, and inbox are always open for doubts, discussion, and criticism. See y’all in the next one!

--

--

Kshitij Vaze

Engineering Student, upcoming embedded solutions architect