PySpice-org / PySpice

Simulate electronic circuit using Python and the Ngspice / Xyce simulators
https://pyspice.fabrice-salvaire.fr
GNU General Public License v3.0
660 stars 173 forks source link

Basic switch not working #167

Open marlowequart opened 5 years ago

marlowequart commented 5 years ago

I have a basic question here with a simplified circuit. I do not understand why the switch is working in one test circuit but not in the other and I would appreciate any help that anyone might be able to offer for why this is. I don't know if this is a problem with PySpice or NgSpice, but when I put this circuit into LT spice it works exactly like it should with both switches turning on any time the gate drive crosses the Vth. Thank you for any insights.

Here is my python code: #################################################################################################### import matplotlib.pyplot as plt #################################################################################################### import PySpice.Logging.Logging as Logging logger = Logging.setup_logging() #################################################################################################### from PySpice.Doc.ExampleTools import find_libraries from PySpice.Probe.Plot import plot from PySpice.Spice.Library import SpiceLibrary from PySpice.Spice.Netlist import Circuit from PySpice.Unit import * #################################################################################################### from PySpice.Spice.NgSpice.Shared import NgSpiceShared #################################################################################################### libraries_path = find_libraries() spice_library = SpiceLibrary(libraries_path) #################################################################################################### circuit = Circuit('Stator Drive')

circuit.include(spice_library['test_netlist'])

Top level circuit annotated as "x1"

circuit.X(1,'test_netlist', 'gate_drive1', 'sw_node_hs1', 'gate_drive2', 'sw_node_hs2')

simulator = circuit.simulator(temperature=25, nominal_temperature=25) analysis = simulator.transient(step_time=.005E-6, start_time=1E-3, end_time=3.5E-3, use_initial_condition=False)

NUMBER_PLOTS = '4'

plots of circuit components

figure = plt.figure(1, (10, 5)) plot1 = plt.subplot(int(NUMBER_PLOTS+'11')) plot(analysis.gate_drive1) plt.legend(('gate drive 1 [V]', '',''), loc=(.8,.8)) plt.grid() plt.xlabel('t [s]') plt.ylabel('[V]') plot2 = plt.subplot(int(NUMBER_PLOTS+'12')) plot(analysis.sw_node_hs1) plt.legend(('Switch Node 1',''), loc=(.05,.1)) plt.grid() plt.xlabel('t [s]') plt.ylabel('[V]') plot3 = plt.subplot(int(NUMBER_PLOTS+'13')) plot(analysis.gate_drive2) plt.grid() plt.xlabel('t [s]') plt.ylabel('[V]') plt.legend(('gate drive 2',''), loc=(.05,.1)) plot4 = plt.subplot(int(NUMBER_PLOTS+'14')) plot(analysis.sw_node_hs2) plt.grid() plt.xlabel('t [s]') plt.ylabel('[V]') plt.legend(('sw node 2',''), loc=(.05,.1)) plt.tight_layout() plt.show()

And here is the netlist:

.subckt test_netlist gate_drive1 sw_node_hs1 gate_drive2 sw_node_hs2 XX1 gate_drive1 sw_node_hs1 gate_drive2 sw_node_hs2 .ends test_netlist

.subckt test_netlist gate_drive1 sw_node_hs1 gate_drive2 sw_node_hs2

marlowequart commented 5 years ago

I was able to verify that this circuit does operate correctly in ngspice. I am not sure why it is not working in pyspice however.