12
\$\begingroup\$

So before this I only worked with simple 8 bit Atmel MCUs and I realized on my development board schematics it has only a 12Mhz crystal, yet the MCU operates at up to 100MHz. (I think the default is 80MHz. I only made it higher once for fun. It's just a simple line in the code.)

How does it do that? Why does an Atmega328, for example, run at the used crystal speed?

\$\endgroup\$
  • 5
    \$\begingroup\$ 1) mHz means milli Hertz so 1/1000th of a Hertz, use MHz (capital M) when you mean Mega Hertz. 2) what 8 Bit MCU? 3) What development board? 4) The ATMega 328 doesn't have to run at the crystal's speed, read the section of clocking in the datasheet to see what is possible. 5) Some ICs have a PLL which can be used to multiply the external clock frequency. \$\endgroup\$ – Bimpelrekkie May 26 at 12:03
  • 1
    \$\begingroup\$ @Bimpelrekkie: Most of that comment is the answer. Would you like to make an answer of it? \$\endgroup\$ – JRE May 26 at 12:12
  • \$\begingroup\$ VCO divider to compare with 12 MHz ends up multiplying f. Thats what a PLL freq synth does. \$\endgroup\$ – Tony Stewart Sunnyskyguy EE75 May 26 at 12:43
  • \$\begingroup\$ @Bimpelrekkie looks like someone already fixed it for me. I already mentioned Atmel and atmega328. but it doesn't matter as that's an example. afaik atmega328p doesn't have a PPL? I was mostly curious about how you can just simply multiply it. thankfully Marcus Muller already explained it very well. \$\endgroup\$ – user3033693 May 26 at 14:14
  • \$\begingroup\$ the processor in the computer you are reading this on is likely using a 100Mhz reference clock or slower yet the core runs in the ghz. \$\endgroup\$ – old_timer May 26 at 18:43
28
\$\begingroup\$

This doesn't have anything to do with the core being an ARM processor; it's about how the clocking circuitry works:

In many systems like microcontrollers, RF chips, audio chips, … you need to generate a faster clock that is an exact multiple of some reference clock (for example, an external crystal).

You do that by having a voltage-controlled oscillator (VCO) that you can adjust in frequency by in- or decreasing a control voltage.

Now, by just setting any control voltage, you can bring that to oscillate at a frequency roughly in the right "ballpark", but not at an exact multiple of the input frequency. Especially, VCOs can be a bit drifty, so that frequency will also continously "wander" all over the place. You need to control that oscillator by comparing it to the reference oscillator.

The way to do that is by employing a Phase-Locked Loop. The idea is simple:

  1. Divide the frequency that comes out of the VCO by a factor \$N\$; that's the factor that we want the VCO to be faster than the reference. Doing that is easy: You can, for example, simply use a digital counter that counts to N and only then changes the output.
  2. Compare that \$f_\text{VCO}/N\$ clock with the reference clock at \$f_\text{ref}\$. If one is faster than the other, adjust the frequency accordingly. You can do that in a digital way by just XOR'ing both clocks – ideally, if they are identical, the result is a constant 0, but if one is faster than the other, then there will be a growing amount of times when the XOR of both clocks is 1; slow down or speed up the VCO accordingly.

The above is a control loop, locked to the phase of – hence the name.

For "rich" microcontrollers, which have a lot of peripherals and hence benefit from having multiple clocks internally, it's usual to have at least 1 PLL. The ATMega328 is a bit strange in that respect: It's a relatively power-hungry, relatively peripheral-rich microcontroller that still doesn't have a PLL.

\$\endgroup\$
  • 1
    \$\begingroup\$ Thanks you :) this explains it very well! Instead of poking fun or focusing on my silly mistakes you just told me what I'm obviously asking. Some things are VERY hard for me to pay attention to with my Dyslexia. Even if I read trough my post 2-3 times I miss a lot of makes or accidentally put capitalization where I don't need to. Not to mention English isn't my first language. \$\endgroup\$ – user3033693 May 26 at 14:07
  • 7
    \$\begingroup\$ @AmyGamble your English is very good, however! I think the first comment you got under your post was because very many young engineers simply forget about capitalization of units – which can become very problematic later on :) I hope you never feel discouraged! \$\endgroup\$ – Marcus Müller May 26 at 20:03
9
\$\begingroup\$

Some devices have a PLL in them that can multiply the crystal frequency to higher frequencies. The ATMega328 does not have a PLL, it uses the crystal directly.

\$\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.