Skip to main content
Part 1 · Simple: schematic circuits

5 · Parameter sweeps

Status: 🟡 Partly works. The file renders, but tsci simulate prints only the nominal run (R1 = 1k) today. The sweep runs aren't printed yet.

Goal: run one experiment for several component values.

Build​

05-rc-sweep.circuit.tsx
import { analog } from "tscircuit"

export default () => (
<board routingDisabled>
<voltagesource name="V1" voltage="3.3V" />
<resistor name="R1" resistance="1k" footprint="0402" />
<capacitor name="C1" capacitance="1uF" footprint="0402" />
<trace from=".V1 > .pin1" to=".R1 > .pin1" />
<trace from=".R1 > .pin2" to=".C1 > .pin1" />
<trace from=".C1 > .pin2" to=".V1 > .pin2" />
<voltageprobe name="VOUT" connectsTo=".C1 > .pin1" referenceTo=".V1 > .pin2" />
<analog.transientsimulation name="RC_FAMILY" spiceEngine="ngspice"
duration="5ms" timePerStep="50us">
<analog.sweepparameter parameterType="resistance" resistorRef=".R1"
values={["500", "1k", "2k"]} />
</analog.transientsimulation>
</board>
)

analog.sweepparameter goes directly inside an analysis and repeats it for each value. The component's own value doesn't change. You can sweep resistance, capacitance, inductance, voltage (a net) or current.

What you should see​

Three charging curves, one per R:

R1τV at 1 ms
500 Ω0.5 ms3.3 × (1 − e⁻²) = 2.85 V
1 kΩ1 ms2.09 V
2 kΩ2 ms3.3 × (1 − e⁻⁰·⁵) = 1.30 V

Until the CLI prints the sweep, you can run each value as its own file. Or export a component that takes resistance as a prop, the way lesson 9 does.

Check by hand​

τ scales linearly with R, so doubling R halves how fast the capacitor charges.