1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#!/usr/bin/env python3
import matplotlib.pyplot as plt
import PySpice.Logging.Logging as Logging
logger = Logging.setup_logging()
from PySpice.Probe.Plot import plot
from PySpice.Spice.Netlist import Circuit
from PySpice.Unit import *
class RC_Circuit(Circuit):
def __init__(self, R, C, **kwargs):
super().__init__(title="RC", **kwargs)
self.R(1, "vsrc", "out", R)
self.C(1, "out", self.gnd, C)
if __name__ == "__main__":
cir = RC_Circuit(R=8@u_kOhm, C=22@u_nF)
if 1:
cir.PulseVoltageSource(1, "vsrc", cir.gnd,
initial_value=0.0, pulsed_value=5.0,
delay_time=1e-3, pulse_width=1.0, period=1.0)
if 0:
cir.SinusoidalVoltageSource(1, "vsrc", cir.gnd,
offset=2.5, amplitude=2.5, frequency=100)
print(cir)
sim = cir.simulator()
analysis = sim.transient(step_time=1e-7, end_time=2e-2)
figure = plt.figure(figsize=(12, 4))
plot(analysis["vsrc"], label="vsrc")
plot(analysis["out"], label="out")
plt.xlabel("Time / s")
plt.ylabel("Voltage / V")
plt.grid()
plt.legend(loc="upper right")
plt.show()
# vim: ts=4 sw=4 expandtab
|