# Capacitor (`capacitor`)

> Stores energy in its voltage. Can add series resistance, series inductance and leakage.

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

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

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

## When to use it

Use it for DC links, outputs, snubbers and filters. To store energy in a current, use Inductor.

## Pins

| Pin | Domain | Meaning |
|---|---|---|
| `p` | electrical | One end; positive voltage and current run p to n |
| `n` | electrical | The other end |

## Common parameters

- `c`: Capacitance (Default: required)
- `esr`: ESR: small resistance in series with it (Default: 0)
- `v0`: Initial voltage; the voltage across it at the start (Default: 0)

## Parameters

| Key | Unit | Default | Typical range | Description |
|---|---|---|---|---|
| `c` | F | required |  | Capacitance |
| `v0` | V | 0 |  | Initial voltage; the voltage across it at the start |
| `esr` | Ω | 0 | 1m – 1 Ω | ESR: small resistance in series with it |
| `esl` | H | 0 | 1n – 50n H | ESL: small inductance in series with it |
| `rleak` | Ω | optional (off) | 100k – 1g Ω | Resistance that lets charge leak away |
| `temp` | °C | 25 |  | Part temperature the temperature tables are read at |
| `esrTemp` | — | optional (off) |  | Temperature (°C) and factor pairs that scale esr, from the datasheet's curve |
| `cTemp` | — | optional (off) |  | Temperature (°C) and factor pairs that scale the capacitance, from the datasheet's curve |
| `part` | — | optional (off) |  | Part number; the catalogue part number, such as XAL8080-123MEC or 2 × XAL8080-123MEC for two in series; information only, not simulated |

_Parameter descriptions are in English in both languages._

**Use for:** DC links · Output capacitors · Snubbers · Decoupling

**Not for:** Bulk energy storage in farads → [`supercap`](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/passive/supercap/)

## Formulas

| Formula | Equation | Source |
|---|---|---|
| Output ripple from the ripple current | Δv = Δi / (8·fsw·c) | Erickson & Maksimović, Fundamentals of Power Electronics, 3rd ed. (2020), §2.5 |
| Output ripple with the series resistance (an upper bound: the two parts peak a quarter period apart) | Δv ≤ Δi·esr + Δi / (8·fsw·c) | Texas Instruments SLVA477B, Basic Calculation of a Buck Converter's Power Stage (2015), Output Capacitor Selection |
| Stored energy | E = ½·c·v² | Hayt, Kemmerly & Durbin, Engineering Circuit Analysis, 8th ed. (2012), ch. 7 |
| Self-resonant frequency | f = 1 / (2π·√(esl·c)) | Hayt, Kemmerly & Durbin, Engineering Circuit Analysis, 8th ed. (2012), ch. 16 (series resonance) |

## Quick check

Inputs:

- `c`: Capacitance = 100u F, `c`
- `v`: Voltage = 48 V, `v0`
- `di`: Ripple current (peak to peak) = 1 A
- `fsw`: Switching frequency = 100k Hz
- `esl`: Series inductance = 10n H, `esl`
- `esr`: Series resistance = 0 Ω, `esr`

Outputs:

- `dv`: Output ripple (peak to peak, at most) = `di*esr + di/(8*fsw*c)` V
- `energy`: Stored energy = `0.5*c*v^2` J
- `srf`: Self-resonant frequency = `1/(2*pi*sqrt(esl*c))` Hz

## Model logic

- Each step it is a conductance with a current source (trapezoidal rule, backward Euler after a switching event), and the first solve holds v0 across it.
- esr and esl are chained in series from p, and rleak sits across the capacitance only; the esl starts with no current.
- cTemp and esrTemp scale c and esr once at temp before the run; the capacitance does not change with voltage (no DC bias drop).
- Dielectric absorption, ageing, rated voltage and ripple-current rating are not modelled.

## Model

The current is i = C * dv/dt, starting from the voltage v0 = v(p) - v(n). Seen from the pins, the parts run in this order: p, esr, esl, then c in parallel with rleak, then n. Each extra parameter is optional, and zero or unset means the ideal part.

## Common mistakes

- A capacitor placed straight across an ideal voltage source charges instantly and draws a current spike at the start. Add a small series resistance, or start the capacitor at the source voltage with v0.
- esr of 10 means 10 ohm, not 10 milliohm, and values outside 1m to 1 ohm are flagged. Write 10m for ten milliohm.

Problems rules: `param.non_positive`, `loop.source_capacitor`, `param.out_of_range`

## Datasheet and sources

c is the capacitance at your working voltage and temperature, which can be well below the nominal value for ceramics. esr is the datasheet value at the switching frequency, and esl is worked out from the self-resonant frequency.

## Example

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

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