From abe94972619bcd48fa928ccefdff9a814971a5a5 Mon Sep 17 00:00:00 2001 From: Vaino Kauppila Date: Sun, 11 Oct 2026 15:21:53 +0300 Subject: examples: runnable RC low-pass demo on a plain netlist (no KiCad) rc_lp.cir + rc_lp.py: 5 V step into 1k + 100n, prints V(out) at one time constant and writes a plot. README updated for netlist support; results/ output dir ignored. --- examples/rc_lp.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/rc_lp.py (limited to 'examples/rc_lp.py') diff --git a/examples/rc_lp.py b/examples/rc_lp.py new file mode 100644 index 0000000..0a79b60 --- /dev/null +++ b/examples/rc_lp.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +"""Example: run a plain ngspice netlist with kisim -- no KiCad involved. + + micromamba run -n kicad_work python examples/rc_lp.py +""" +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parents[1])) + +import numpy as np + +from kisim import KiSim + +sim = KiSim("rc_lp.cir", tran="1u 2m") # .cir input: used as-is, no kicad-cli +r = sim.run() # -> results/run.cir + run.raw (cached) + +tau = 1e3 * 100e-9 # R1 * C1 +vout = r.v("vout") +print(f"5 V step into 1 kohm + 100 nF: tau = {tau * 1e6:.0f} us") +print(f"V(vout) at 1 tau: {np.interp(tau, r.t, vout):.3f} V (1 - 1/e of 5 V)") +print(f"V(vout) settled: {vout[-1]:.3f} V") + +r.plot(["vin", "vout"], title="RC low-pass: 5 V step", file=sim.workdir / "rc_lp.png") +print("plot:", sim.workdir / "rc_lp.png") -- cgit v1.3