Open rowhit opened 3 years ago
Operating System: Ubuntu 20.04 PySpice Version: 1.4.3 Simulator: Xyce (7.2 Opensource Version)
.title Astable Multivibrator Vcc vcc 0 15V R1 output comparator 1kOhm C1 comparator 0 100nF R2 output reference 100kOhm R3 vcc reference 100kOhm R4 reference 0 100kOhm E1 output 0 TABLE {V(reference, comparator)} = (-1u, 0) (1u, 15V) .options TEMP = 25 .options TNOM = 25 .ic V(comparator)=0 .tran 1us 500us 0s .end
####################################################################################################
import matplotlib.pyplot as plt import matplotlib as mpl mpl.use('Qt5Agg')
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 *
circuit = Circuit('Astable Multivibrator')
source = circuit.V('cc', 'vcc', circuit.gnd, 15@u_V)
circuit.R(1, 'output', 'comparator', 1@u_kΩ) circuit.C(1, 'comparator', circuit.gnd, 100@u_nF)
circuit.R(2, 'output', 'reference', 100@u_kΩ) circuit.R(3, 'vcc', 'reference', 100@u_kΩ) circuit.R(4, 'reference', circuit.gnd, 100@u_kΩ)
circuit.NonLinearVoltageSource(1, 'output', circuit.gnd, expression='V(reference, comparator)', table=((-micro(1), 0), (micro(1), source.dc_value)) )
simulator = circuit.simulator(simulator="xyce-parallel", temperature=25, nominal_temperature=25) simulator.initial_condition(comparator=0) # Fixme: simulator.nodes.comparator == 0 analysis = simulator.transient(step_time=1@u_us, end_time=500@u_us)
figure, ax = plt.subplots(figsize=(20, 10)) ax.grid() ax.plot(analysis.reference) ax.plot(analysis.comparator) ax.plot(analysis.output)
plt.tight_layout() plt.show()
see also #40
Environment (OS, Python version, PySpice version, simulator)
Operating System: Ubuntu 20.04 PySpice Version: 1.4.3 Simulator: Xyce (7.2 Opensource Version)
Expected Vs Actual Behaviour
Steps to reproduce the behavior
import matplotlib.pyplot as plt import matplotlib as mpl mpl.use('Qt5Agg')
####################################################################################################
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 *
from OperationalAmplifier import basic_comparator
####################################################################################################
circuit = Circuit('Astable Multivibrator')
source = circuit.V('cc', 'vcc', circuit.gnd, 15@u_V)
Time constant
circuit.R(1, 'output', 'comparator', 1@u_kΩ) circuit.C(1, 'comparator', circuit.gnd, 100@u_nF)
Reference
circuit.R(2, 'output', 'reference', 100@u_kΩ) circuit.R(3, 'vcc', 'reference', 100@u_kΩ) circuit.R(4, 'reference', circuit.gnd, 100@u_kΩ)
Comparator
Fixme: ngspice is buggy with such subcircuit
circuit.subcircuit(basic_comparator)
circuit.X('comparator', 'BasicComparator', 'reference', 'comparator', 'vcc', circuit.gnd, 'output')
circuit.NonLinearVoltageSource(1, 'output', circuit.gnd, expression='V(reference, comparator)', table=((-micro(1), 0), (micro(1), source.dc_value)) )
simulator = circuit.simulator(simulator="xyce-parallel", temperature=25, nominal_temperature=25) simulator.initial_condition(comparator=0) # Fixme: simulator.nodes.comparator == 0 analysis = simulator.transient(step_time=1@u_us, end_time=500@u_us)
Fixme: Xyce fails with Time step too small
figure, ax = plt.subplots(figsize=(20, 10)) ax.grid() ax.plot(analysis.reference) ax.plot(analysis.comparator) ax.plot(analysis.output)
plt.tight_layout() plt.show()
f# save_figure('figure', 'astable.png')