# Quartz Crystal (`crystal`)

> A quartz crystal for oscillators and filters, drawn as its equivalent circuit.

![crystal](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/img/crystal.svg)

[Component reference](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/) · [繁體中文](https://voltecx-web.nguyenvanqui291.workers.dev/zh/docs/reference/passive/crystal/)

**Group:** Passive · **Kind:** `{"kind":"crystal"}`

## When to use it

Use it for crystal oscillators and filters. Use Inductor and Capacitor for an ordinary resonant circuit.

## Pins

| Pin | Domain | Meaning |
|---|---|---|
| `p` | electrical | One electrode |
| `n` | electrical | The other electrode |

## Common parameters

- `fs`: Frequency where the crystal rings (Default: 10meg)
- `q`: How sharp the crystal resonance is (Default: 50k)
- `cm`: Capacitance of the vibrating part (Default: 20f)
- `c0`: Capacitance across the crystal pins (Default: 5p)

## Parameters

| Key | Unit | Default | Typical range | Description |
|---|---|---|---|---|
| `fs` | Hz | 10meg |  | Frequency where the crystal rings |
| `q` | — | 50k |  | How sharp the crystal resonance is |
| `cm` | F | 20f |  | Capacitance of the vibrating part |
| `c0` | F | 5p |  | Capacitance across the crystal pins |
| `lm` | H | optional (off) |  | Inductance of the vibrating part |
| `rm` | Ω | optional (off) |  | Resistance of the vibrating part |

_Parameter descriptions are in English in both languages._

**Use for:** Crystal oscillators · Crystal filters

**Not for:** Ordinary LC resonant circuits → [`inductor`](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/passive/inductor/)

## Formulas

| Formula | Equation | Source |
|---|---|---|
| Motional resistance | rm = 1 / (2π·fs·cm·q) | IEEE Std 177-1966, equivalent electrical circuit of a piezoelectric vibrator |
| Parallel resonance | fp = fs·√(1 + cm/c0) | IEEE Std 177-1966, equivalent electrical circuit of a piezoelectric vibrator |
| Load resonance with cl | fl = fs·(1 + cm / (2·(c0 + cl))) | IEC 60122-1:2002, load resonance frequency offset |

## Quick check

Inputs:

- `fs`: Series resonance = 10meg Hz, `fs`
- `q`: Quality factor = 50k —, `q`
- `cm`: Motional capacitance = 20f F, `cm`
- `c0`: Shunt capacitance = 5p F, `c0`
- `cl`: Load capacitance = 18p F

Outputs:

- `rm`: Motional resistance = `1/(2*pi*fs*cm*q)` Ω
- `fp`: Parallel resonance = `fs*sqrt(1 + cm/c0)` Hz
- `fl`: Load resonance = `fs*(1 + cm/(2*(c0 + cl)))` Hz

## Model logic

- Before the run the crystal is replaced by rm, lm and cm in series from p to n with c0 across the pins; c0 of 0 leaves it out.
- From fs, q and cm it sets lm = 1/((2π·fs)²·cm) and rm = 2π·fs·lm/q; giving lm, cm and rm instead works, but mixing the two sets is refused.
- The motional parts start with no current and no charge, so an oscillator builds up from the power-on transient over many Q cycles.
- Drive level, overtones, ageing and the temperature curve are not modelled, and the step-size check ignores the crystal.

## Model

Before the run, the crystal becomes the resistor rm, inductor lm and capacitor cm in series, with c0 from p to n. The series resonance is fs = 1 / (2 * pi * sqrt(lm * cm)), where the impedance is lowest at about rm. The quality factor is Q = 2 * pi * fs * lm / rm, and the parallel resonance is fp = fs * sqrt(1 + cm / c0), where the impedance peaks. Give fs and q with cm (then lm = 1 / ((2 * pi * fs)^2 * cm) and rm = 2 * pi * fs * lm / q), or give lm, cm and rm directly, but not both. The motional current is the current of the part named name.lm. A parallel-mode oscillator with load capacitance CL runs at f = fs * (1 + cm / (2 * (c0 + CL))). Drive level, aging, overtones and the temperature curve are not modelled.

## Common mistakes

- A crystal rings for about Q cycles, so start-up takes tens of thousands of cycles. Check the resonance with impedance analysis, and keep the maximum step under a hundredth of the period yourself, because the step check ignores the crystal.
- cm is in femtofarad and c0 in picofarad, so write 20f and 5p. Setting only one of lm and rm, or lm and rm together with fs or q, is refused before the run.

Problems rules: `step.too_large`, `param.out_of_range`

## Datasheet and sources

Take fs, c0 and cm from the datasheet, and take rm from the series resistance (use a typical value, not the maximum). Without cm, set lm from the motional inductance or set q from a typical value, 10k to 100k for AT-cut crystals and 20k to 100k for 32.768 kHz tuning forks.

## Example

Open the example with the command `file.openExample` and the name `demo:crystal`.

---
Generated by `cargo xtask reference` from the usage texts and parameter specs. Do not edit by hand.
