Skip to content

Commit e3b9326

Browse files
add issue files
1 parent 4610002 commit e3b9326

File tree

9 files changed

+293
-0
lines changed

9 files changed

+293
-0
lines changed

issues/issue-157-2.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
import PySpice.Logging.Logging as Logging
5+
logger = Logging.setup_logging()
6+
7+
from PySpice.Probe.Plot import plot
8+
from PySpice.Spice.Netlist import Circuit
9+
from PySpice.Unit import *
10+
11+
# Parameters
12+
frequency = 1e3
13+
period = 1 / frequency
14+
omega = 2 * np.pi * frequency
15+
16+
I_P1 = 100
17+
L_P1 = 1e-6
18+
L_S1 = 10e-6
19+
K_P1S1 = 0.1
20+
21+
circuit = Circuit("2CoupledInductors")
22+
23+
#Primary Side
24+
circuit.I("I2", circuit.gnd, "N1", "AC " + str(I_P1) + "")
25+
circuit.L("L_P1", circuit.gnd, "N1", str(L_P1))
26+
27+
# Secondary Side
28+
circuit.L("L_S1", circuit.gnd, "N2", str(L_S1) )
29+
circuit.K("K_P1S1", "LL_P1", "LL_S1", K_P1S1) # NB, it adds an L to the name of the inductor ...
30+
31+
# Do the simulation
32+
simulator = circuit.simulator(temperature=25, nominal_temperature=25)
33+
analysis = simulator.ac(variation="lin", number_of_points=1, start_frequency=frequency, stop_frequency=frequency)
34+
35+
# Print the results
36+
print("--- Results ---")
37+
for node in analysis.nodes.values():
38+
print('Node {}: {:5.2f} V'.format(str(node), float(abs(node))))

issues/issue-157.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
import PySpice.Logging.Logging as Logging
5+
logger = Logging.setup_logging()
6+
7+
from PySpice.Probe.Plot import plot
8+
from PySpice.Spice.Netlist import Circuit
9+
from PySpice.Unit import *
10+
11+
# Parameters
12+
frequency = 1e3
13+
period = 1 / frequency
14+
omega = 2 * np.pi * frequency
15+
16+
I_P1 = 100
17+
L_P1 = 1e-6
18+
L_S1 = 10e-6
19+
K_P1S1 = 0.1
20+
21+
circuit = Circuit("2CoupledInductors")
22+
23+
#Primary Side
24+
circuit.I("I2", circuit.gnd, "N1", "AC " + str(I_P1) + "")
25+
circuit.L("L_P1", circuit.gnd, "N1", str(L_P1))
26+
27+
# Secondary Side
28+
circuit.L("L_S1", circuit.gnd, "N2", str(L_S1) )
29+
circuit.K("K_P1S1", "L_P1", "L_S1", K_P1S1)
30+
31+
# Do the simulation
32+
simulator = circuit.simulator(temperature=25, nominal_temperature=25)
33+
analysis = simulator.ac(variation="lin", number_of_points=1, start_frequency=frequency, stop_frequency=frequency)
34+
35+
# Print the results
36+
print("--- Results ---")
37+
for node in analysis.nodes.values():
38+
print('Node {}: {:5.2f} V'.format(str(node), float(abs(node))))

issues/issue-164.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
####################################################################################################
2+
3+
import matplotlib.pyplot as plt
4+
5+
####################################################################################################
6+
7+
import PySpice.Logging.Logging as Logging
8+
logger = Logging.setup_logging()
9+
10+
####################################################################################################
11+
12+
from PySpice.Doc.ExampleTools import find_libraries
13+
from PySpice.Probe.Plot import plot
14+
from PySpice.Spice.Library import SpiceLibrary
15+
from PySpice.Spice.Netlist import Circuit
16+
from PySpice.Unit import *
17+
18+
####################################################################################################
19+
20+
from PySpice.Spice.NgSpice.Shared import NgSpiceShared
21+
22+
####################################################################################################
23+
24+
libraries_path = find_libraries()
25+
spice_library = SpiceLibrary(libraries_path)
26+
27+
####################################################################################################
28+
29+
circuit = Circuit('Basic Switch')
30+
31+
circuit.PulseVoltageSource('pulse', 'sw_drive', circuit.gnd, 0@u_V, 10@u_V, 1@u_ms, 2@u_ms,)
32+
33+
circuit.V('input', 'input', circuit.gnd, 20@u_V)
34+
circuit.R('load', circuit.gnd, 'sw_node', 5@u_Ohm)
35+
circuit.VoltageControlledSwitch('input', 'sw_node', 'sw_drive', circuit.gnd, 'sw1', model=None)
36+
37+
simulator = circuit.simulator(temperature=25, nominal_temperature=25)
38+
analysis = simulator.transient(step_time=0.1E-6, end_time=50E-3)
39+
40+
NUMBER_PLOTS = '2'
41+
42+
#plots of circuit components
43+
figure = plt.figure(1, (10, 5))
44+
plot1 = plt.subplot(int(NUMBER_PLOTS+'11'))
45+
46+
plot(analysis.sw_drive, color='r')
47+
48+
plt.grid()
49+
plt.xlabel('t [s]')
50+
plt.ylabel('[V]')
51+
plt.legend(('Switch Drive',''), loc=(.05,.1))
52+
53+
plot2 = plt.subplot(int(NUMBER_PLOTS+'12'))
54+
55+
plot(analysis.sw_node, color='r')
56+
plot((analysis.sw_node)/circuit['Rload'].resistance,color='b')
57+
plt.grid()
58+
plt.xlabel('t [s]')
59+
plt.ylabel('[V]')
60+
plt.legend(('Switch Output','Load Current'), loc=(.05,.1))
61+
62+
plt.tight_layout()
63+
plt.show()

issues/issue-167.lib

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.subckt test_netlist gate_drive1 sw_node_hs1 gate_drive2 sw_node_hs2
2+
3+
* Test circuit 1
4+
V1 N200 0 100
5+
R1 N200 sw_node_hs1 1
6+
S1 sw_node_hs1 0 gate_drive1 0 myswitch
7+
V2 N102 0 PULSE(0 10 0 1n 1n 50u 100u 200)
8+
B2 gate_drive1 0 V=V(N102)
9+
*output load
10+
R23 0 sw_node_hs1 1
11+
12+
* Test circuit 2
13+
V3 N201 0 100
14+
R3 N201 sw_node_hs2 1
15+
S5 sw_node_hs2 0 gate_drive2 0 myswitch
16+
V4 N101 0 PULSE(0 10 0 50u 50u 1n 100u 200)
17+
B1 gate_drive2 0 V=V(N101)
18+
*output load
19+
R26 0 sw_node_hs2 1
20+
.model myswitch SW(Ron=0.002 Roff=1000000 Vt=3.0)
21+
22+
.ends test_netlist

issues/issue-167.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
####################################################################################################
2+
3+
import matplotlib.pyplot as plt
4+
5+
####################################################################################################
6+
7+
import PySpice.Logging.Logging as Logging
8+
logger = Logging.setup_logging()
9+
10+
####################################################################################################
11+
12+
from PySpice.Doc.ExampleTools import find_libraries
13+
from PySpice.Probe.Plot import plot
14+
from PySpice.Spice.Library import SpiceLibrary
15+
from PySpice.Spice.Netlist import Circuit
16+
from PySpice.Unit import *
17+
18+
####################################################################################################
19+
20+
from PySpice.Spice.NgSpice.Shared import NgSpiceShared
21+
22+
####################################################################################################
23+
24+
from pathlib import Path
25+
26+
# libraries_path = find_libraries()
27+
spice_library = SpiceLibrary(Path(__file__).parent) # libraries_path
28+
29+
####################################################################################################
30+
31+
circuit = Circuit('Stator Drive')
32+
33+
circuit.include(spice_library['issue-167'])
34+
35+
circuit.X(1, 'test_netlist', 'gate_drive1', 'sw_node_hs1', 'gate_drive2', 'sw_node_hs2')
36+
37+
print(circuit)
38+
39+
# simulator = circuit.simulator(temperature=25, nominal_temperature=25)
40+
# analysis = simulator.transient(step_time=.005E-6, start_time=1E-3, end_time=3.5E-3, use_initial_condition=False)
41+
42+
# NUMBER_PLOTS = '4'
43+
# #plots of circuit components
44+
# figure = plt.figure(1, (10, 5))
45+
# plot1 = plt.subplot(int(NUMBER_PLOTS+'11'))
46+
# plot(analysis.gate_drive1)
47+
# plt.legend(('gate drive 1 [V]', '',''), loc=(.8,.8))
48+
# plt.grid()
49+
# plt.xlabel('t [s]')
50+
# plt.ylabel('[V]')
51+
# plot2 = plt.subplot(int(NUMBER_PLOTS+'12'))
52+
# plot(analysis.sw_node_hs1)
53+
# plt.legend(('Switch Node 1',''), loc=(.05,.1))
54+
# plt.grid()
55+
# plt.xlabel('t [s]')
56+
# plt.ylabel('[V]')
57+
# plot3 = plt.subplot(int(NUMBER_PLOTS+'13'))
58+
# plot(analysis.gate_drive2)
59+
# plt.grid()
60+
# plt.xlabel('t [s]')
61+
# plt.ylabel('[V]')
62+
# plt.legend(('gate drive 2',''), loc=(.05,.1))
63+
# plot4 = plt.subplot(int(NUMBER_PLOTS+'14'))
64+
# plot(analysis.sw_node_hs2)
65+
# plt.grid()
66+
# plt.xlabel('t [s]')
67+
# plt.ylabel('[V]')
68+
# plt.legend(('sw node 2',''), loc=(.05,.1))
69+
# plt.tight_layout()
70+
plt.show()

issues/issue-169.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import PySpice.Logging.Logging as Logging
2+
logger = Logging.setup_logging()
3+
4+
from PySpice.Spice.Netlist import Circuit
5+
from PySpice.Unit import *
6+
from PySpice.Spice.BasicElement import BehavioralSource
7+
8+
circuit = Circuit('test')
9+
circuit.LosslessTransmissionLine('line', 'output', circuit.gnd, 'input', circuit.gnd, Z0=50, TD=40e-9)
10+
11+
print(circuit)

issues/issue-172.cir

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.title Pulse
2+
Bsource in 0 v=time^4*exp(-1000*time)
3+
R1 in out 9kOhm
4+
R2 out 0 1kOhm

issues/issue-172.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# from pylab import *
2+
import matplotlib.pyplot as plt
3+
4+
import PySpice.Logging.Logging as Logging
5+
logger = Logging.setup_logging()
6+
7+
from PySpice.Spice.Netlist import Circuit
8+
from PySpice.Unit import *
9+
from PySpice.Spice.BasicElement import BehavioralSource
10+
11+
circuit = Circuit("Pulse")
12+
13+
source = circuit.BehavioralSource('source', 'in', circuit.gnd, voltage_expression = "time^4*exp(-1000*time)")
14+
15+
circuit.R(1, 'in', 'out', u_kOhm(9))
16+
circuit.R(2, 'out', circuit.gnd, u_kOhm(1))
17+
18+
print(circuit)
19+
20+
simulator = circuit.simulator(simulator="ngspice-shared")
21+
# the commented out version next line works
22+
#simulator = circuit.simulator(simulator="ngspice-subprocess")
23+
transient = simulator.transient(step_time=u_ms(1e-3), end_time=u_ms(20))
24+
25+
# clf()
26+
plt.grid(True)
27+
plt.plot(transient['out'].abscissa, transient['out'])
28+
plt.show()

issues/two-stage-amp.cir

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
*Sheet Name:/OPA_SR
2+
V1 vp GND dc 1.65 ac 0.5
3+
V2 vn GND dc 1.65 ac -0.5
4+
C2 Vout GND 4p
5+
C1 /3 Vout 6.9p
6+
M7 Vout /6 VDD VDD p_33 W=25.9u L=0.9u
7+
M6 Vout /3 GND GND n_33 W=92.04u L=1.4u
8+
M2 /3 vp /1 VDD p_33 W=51.78u L=0.9u
9+
M1 /2 vn /1 VDD p_33 W=51.78u L=0.9u
10+
M4 /3 /2 GND GND n_33 W=46.02u L=1.4u
11+
M3 /2 /2 GND GND n_33 W=46.02u L=1.4u
12+
M5 /1 /6 VDD VDD p_33 W=12.95u L=0.9u
13+
V0 VDD GND 3.3
14+
M8 /6 /6 VDD VDD p_33 W=1.3u L=0.9u
15+
I1 /6 GND 10u
16+
17+
.lib CMOS_035_Spice_Model.lib tt
18+
19+
.end

0 commit comments

Comments
 (0)