Oscillator and clock source for microcontroller

Thread Starter

MTech1

Joined Feb 15, 2023
147
I'm looking to gain a better understanding of oscillators and clocks in microcontrollers. I know that microcontrollers rely on clock signals generated by oscillator circuits, which produce a periodic square waveform. In many cases, a single quartz crystal is commonly used along with two capacitors to generate these clock signals, especially in microcontrollers like PIC and 8051.

What term is commonly used to describe this combination of a crystal and capacitors in this context?

I'm experiencing some confusion regarding the terminology used, specifically when the terms 'crystal' and 'crystal resonator' are mentioned in relation to microcontroller clock generation.

Can you clarify the distinction between these two terms and their respective roles in microcontroller
 

Ya’akov

Joined Jan 27, 2019
8,540
A resonator is the name for the piezoelectric element in a particular type of oscillator circuit. A crystal oscillator (XO) is a circuit that uses a quartz crystal for this purpose. So, the crystal alone is crystal resonator. You will also see ceramic resonators from time to time, and in specialized applications acoustic resonators made from thin film technology are used.

The stability and precision are relative to other resonant circuits that rely on LC (Inductive Capacitive) or RC (Resistive Capacitive) tank circuits. In the case of a μP or a μC the external component (the crystal and caps) are not the only things needed to create an XO but processor has the rest internally.

XO's are certainly more stable than LC or RC circuits but the do have the same problem of drift cause by changes in ambient temperature. To eliminate this, an OCXO (Oven Controlled XO) or TCXO (Temperature Compensated XO) can be used. This is almost never a concern for processor clocking, but could be for an RTC (Real Time Clock) application related to a processor.
 

BobTPH

Joined Jun 5, 2013
8,108
The quartz crystal is a device with two leads that does not oscillate by itself, it is used in a circuit with an inverter, resistor, and two capacitors to make crystal oscillator. The inverter and resistor are inside the micro, the crystal and capacitors are external.

There are also crystal oscillators that have four leads. These have all the components in the package and oscillate in their own when given power. The can also be used to clock a microcontroller when it is configured for external oscillator.
 

dl324

Joined Mar 30, 2015
16,156
I'm experiencing some confusion regarding the terminology used, specifically when the terms 'crystal' and 'crystal resonator' are mentioned in relation to microcontroller clock generation.

Can you clarify the distinction between these two terms and their respective roles in microcontroller
A resonator is something that resonates at some frequency.

For further information, you can research resonance, series/parallel crystals, and, since you mentioned a specific capacitor configuration, the effect on series/parallel capacitance on them.
 

nsaspook

Joined Aug 27, 2009
12,309
The quartz crystal is a device with two leads that does not oscillate by itself, it is used in a circuit with an inverter, resistor, and two capacitors to make crystal oscillator. The inverter and resistor are inside the micro, the crystal and capacitors are external.

There are also crystal oscillators that have four leads. These have all the components in the package and oscillate in their own when given power. The can also be used to clock a microcontroller when it is configured for external oscillator.
Exactly. I've designed boards with the option for both like this one for the MCP2210. Personally I much prefer complete four lead clocks modules over 'resonators' because of PCB layout issues and frequency drift.
https://forum.allaboutcircuits.com/...2210-on-linux-with-libusb.179080/post-1693734
https://github.com/nsaspook/mcp2210/blob/main/mcp2210_sch.pdf
 

Thread Starter

MTech1

Joined Feb 15, 2023
147
Thank you very much! One more doubt

If a PIC microcontroller is running with a 20 MHz crystal oscillator, how many instructions can the microcontroller execute in one clock cycle?

Given that the period (T) is calculated as T = 1 / Frequency (f), how does this relate to the microcontroller's instruction execution?
 

nsaspook

Joined Aug 27, 2009
12,309
Thank you very much! One more doubt

If a PIC microcontroller is running with a 20 MHz crystal oscillator, how many instructions can the microcontroller execute in one clock cycle?

Given that the period (T) is calculated as T = 1 / Frequency (f), how does this relate to the microcontroller's instruction execution?
Which PIC product family?
PIC18: https://onlinedocs.microchip.com/ox...UID-53364752-A363-481D-8221-6F818CF0FFAB.html
https://onlinedocs.microchip.com/ox...UID-D4CF9DB8-0959-4477-A150-3F8B34FD3D30.html
10.2.2 Instruction Flow/Pipelining
An “Instruction Cycle” consists of four Q cycles: Q1 through Q4. The instruction fetch and execute are pipelined in such a manner that a fetch takes one instruction cycle, while the decode and execute take another instruction cycle. However, due to the pipelining, each instruction effectively executes in one cycle. If an instruction causes the Program Counter to change (e.g., GOTO), then two cycles are required to complete the instruction as shown in the figure below.

A fetch cycle begins with the Program Counter (PC) incrementing in Q1.

In the execution cycle, the fetched instruction is latched onto the Instruction Register (IR) in cycle Q1. This instruction is then decoded and executed during the Q2, Q3 and Q4 cycles. Data memory is read during Q2 (operand read) and written during Q4 (destination write).
 

BobTPH

Joined Jun 5, 2013
8,108
In other words, 20MHz clock = 5MHz instruction cycle frequency, = 200 nsec per instruction except 400 for branches that are taken.
 

John P

Joined Oct 14, 2008
2,013
As people have said, the PIC processors have an execution rate which is one fourth of the oscillator frequency. The ATmega processors used in the Arduino are different--for most instructions, their processing rate is the same as the oscillator cycle.
 

Ian Rogers

Joined Dec 12, 2012
1,134
Just for completeness... You also mentioned the ol' 8051. These have a 12:1 Fosc~Tosc. In other words a 12MHz crystal yields only a 1Mhz tick cycle.
 

cmartinez

Joined Jan 17, 2007
8,123
Just for completeness... You also mentioned the ol' 8051. These have a 12:1 Fosc~Tosc. In other words a 12MHz crystal yields only a 1Mhz tick cycle.
And the newest generation of some brands of the 8051 architecture have a 1:1 relationship between its system clock and the oscillator being used.
 
Top