12
\$\begingroup\$

I have a basic implementation with a crystal feeding XTAL1 and XTAL2 on a processor (similar to below). When I look at the signal on XTAL1 and XTAL2 they are sine waves.

Shouldn't they be square waves?

enter image description here

\$\endgroup\$
12
  • 4
    \$\begingroup\$ Why do you think they should be square waves? \$\endgroup\$
    – Hearth
    Commented Apr 27, 2018 at 21:14
  • 1
    \$\begingroup\$ Because it is a digital circuit, I didn't think the processor could deal with non-square (rectangular, etc) waves. How does it recognize this as a pulse? \$\endgroup\$
    – ToddB
    Commented Apr 27, 2018 at 21:15
  • 2
    \$\begingroup\$ Well, you probably should know that a perfect square wave is impossible in a physical circuit. \$\endgroup\$
    – Eugene Sh.
    Commented Apr 27, 2018 at 21:17
  • 6
    \$\begingroup\$ @EugeneSh., I don't think the term 'square wave' should be interpreted quite so literally \$\endgroup\$
    – TonyM
    Commented Apr 27, 2018 at 22:57
  • 1
    \$\begingroup\$ The MCU may be mostly digital, but the crystal part of the oscillator circuit is an analog circuit, not a digital one. Also beware that loading an oscillator circuit with a scope probe can make it fail to function; things are a little better if you use a 10x probe. \$\endgroup\$ Commented Apr 28, 2018 at 21:57

6 Answers 6

23
\$\begingroup\$

This circuit is not a digital circuit. In fact, it is a fairly mathematically complicated non-linear analog circuit with automatic gain control with self-sustainable oscillation mode. It is called a "Pierce oscillator".

Enter image description here

The frequency of oscillations is defined by a sharp slope of the electromechanical resonator (crystal), while the gain control is based on dependence of the input on the DC bias voltage - if the DC bias (at C1) is too low to ground or too close to Vcc, the gain is low. The linear gain is highest somewhere in between the ground and power rail.

The (usually internal) bias resistor R1 plays a crucially important role in the oscillator. Typical value of it in CMOS implementations is about 1 MOhm. Together with C1 it forms a low-pass filter, which integrates the output and provides a variable DC offset depending on slight asymmetry of the output signal, even if the output gets to saturation (rail limiting).

As result, there could be a variety of signal shapes with more or less non-linear distortion on Xout and Xin, depending on the inverter's raw gain and parameters of the crystal resonator and loading capacitors. With a very low gain and at the verge of self-oscillations, the signals will be nearly sinusoidal, while at higher gain the output will hit the voltage rail and can be nearly rectangular. The art of making Pierce oscillators is to provide some golden trade-off between rectangular output and sinusoidal one, with good stability of the entire circuit to temperature and voltage variations.

This article deals with a MEMS resonator, not quartz crystal, but the ideas are the same. This is an example of how the circuit starts and drifts to steady state:

Enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ I know, I know, many people may not believe in naked blurb, so everything must be supported by independent evidence. So is the addition. If I find any more straight articles, I will post later. \$\endgroup\$ Commented Apr 27, 2018 at 22:32
  • \$\begingroup\$ See also /services.eng.uts.edu.au/pmcl/de/Downloads/Lecture04.pdf , final section 4-48 \$\endgroup\$ Commented Apr 28, 2018 at 0:10
9
\$\begingroup\$

The crystal (+C1/C2) is a very narrow bandwidth resonator/filter. Only the fundamental frequency can fit through it.

Sine waves are a single pure frequncy, So it is a sine wave.

Square waves are made square, by all the odd harmonics filling out the hump until the sine becomes square. No Harmonics = Not Square

[Note crystals do in fact have "harmonics" called overtones, but they are slightly off frquency from each other, so the harmonics of the fundamental do not quite hit the 3rd overtone etc]

Another view is that the crystal is like the wheels of a bicycle rolling down the road. The CMOS invertor driving it, is like your feet and legs. Now you could "stab" at the pedals, and try to make the movement a square wave if you wanted. But the pedals are just going to go round and round smoothly regardless, because the flywheel effect is so large. The crystal is like an enormous flywheel smoothly and sinusoidally rolling around.

The crystal really is like a heavy flywheel. If you suddenly disconnect the drive, the signal will take thousands of cycles to die away. When you turn the oscillator on, it takes thousands of cycles to start, slowly building up amplitude. This is why your processor has an "oscillator startup timer"

\$\endgroup\$
6
\$\begingroup\$

A crystal will convert electrical energy to mechanical energy and vice versa. It is able to do this efficiently when driven with a sinusoidal waveform of a particular frequency. Driving it with anything else will result in it converting a larger fraction of the applied energy into heat or mechanical degradation.

While it would be possible for a processor to output a square wave to the crystal, this would result in the crystal generating more heat and being subject to more stress than driving it with something closer to a sinusoidal waveform. Further, if the purpose of a pin is to serve as the output of a crystal oscillator, a small transistor which isn't strong enough to force the voltage on the pin to change instantly may be quite cheap compared with a transistor that's powerful enough to forcibly drive a square wave.

Note, incidentally, that in most cases the processor won't be putting much power into the crystal, and the sinusoidal shape isn't dominated by the energy that's flowing from the processor into the crystal, but rather by the energy that's repeatedly flowing from the crystal into the attached caps and back again.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Not only that: Overdriving a crystal with a powerful squarewave is sometimes opined as being detrimental to long term crystal life/stability, and also is an EMI source... \$\endgroup\$ Commented Apr 27, 2018 at 22:59
  • \$\begingroup\$ @rackandboneman: That's part of what I meant by converting applied energy into mechanical degradation. EMI is another consideration as well, but may key point is that using a small transistor to drive the crystal weakly is both better and cheaper than trying to use a big one to force a square wave. \$\endgroup\$
    – supercat
    Commented Apr 27, 2018 at 23:01
3
\$\begingroup\$

Even though the signal is a sine wave, the pin has an threshold voltage. Below this threshold it will be a 0, and above it will read a 1. This is usually a consequence of internal circuitry.

Above threshold, the pin will register a 1. The pin has a range of voltages which it can function regularly in, so even if the voltage of a '1' changes, say from 3.31 to 3.35 volts, during the peak of the sine wave, it will operate in the desired way.

So, the pin goes from functioning as a 0 to functioning as a 1, even though the actual voltage varies slightly. Of course, too much voltage and it will begin operating in unexpected ways, usually damaging the chip.

\$\endgroup\$
1
  • 4
    \$\begingroup\$ This could be improved a bit, Alex. Your terminology is a little odd and your user profile doesn't give location or first language. For 'activation voltage' use 'threshold voltage'. The diodes reference will probably cause more confusion than help. Instead of 'before' and 'after' threshold use 'above' and 'below' since you are discussing level and not time. The pins do function at 0 logic level. Finally, you need to address the actual question: "Why is signal on XTAL1 and XTAL2 a sine wave (not square)?" You didn't cover that. Please accept this as encouragement. \$\endgroup\$
    – Transistor
    Commented Apr 27, 2018 at 22:40
1
\$\begingroup\$

The crystal is used as a very high Q narrow band pass filter with an 180 deg phase shift the inverter will force it to oscillate to saturation of a logic level square wave.

So the inverter input is a sine wave as a result of filtering out all the harmonics of the square wave.

enter image description here

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

That sine wave, having a finite and easily computed slope, along with some noise floor in the internal circuitry that DOES square up the resonator signal, cause a predictable phase noise or time jitter.

Use the formula

Tjitter = Vnoise / SlewRate

to predict the timing wander of this clock source.

Beware that any other circuits will only further add jitter. Use the same formula.

Assume your sine-to-square circuit has 10 kohm Rnoise. This is 12 nanovolts/rtHz thermal random/Johnson/Boltsmann noise density. If bandwidth is 100 MHz, the total input noise voltage is 12 nV * sqrt(100 MHz) = 12 nV * 10^4 = 120 microvolts RMS.

Assume the crystal frequency is 10 MHz, with +-1 volt peak sine amplitude. The slew rate is 1 V * 6.28 * 10 MHz = 63 volts/µs.

What is the edge jitter? Tj = Vnoise / SlewRate

Tj = 120 microvolts / (63 volts/µs) = 2 picoseconds.

\$\endgroup\$
3
  • \$\begingroup\$ I can't see how you can believe this will help OP in any way. \$\endgroup\$
    – pipe
    Commented Apr 29, 2018 at 11:02
  • \$\begingroup\$ As the first paragraph explains, the XTAL produces sins. To assume that becomes a perfect square wave, with totally clean edge, is very misleading. Thus I provided the equation, and a quite appropriate example, to illustrate how the edge jitter will never be zero. Thus this is helpful to pipe? \$\endgroup\$ Commented Apr 29, 2018 at 16:06
  • \$\begingroup\$ Who's asking about jitter? \$\endgroup\$
    – pipe
    Commented Apr 29, 2018 at 19:10

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