Howto: Transient analysis

I want to do a transient analysis of a square wave.

  1. How do I do a transient analysis and plot the output?
  2. How do I implement a square wave?

I found nothing in the examples. Thanks for your help,
Michael

Okay, now I have the following code


#r# This example shows the computation of the DC biases in a resistor bridge.

####################################################################################################

import matplotlib.pyplot as plt
##
import PySpice.Logging.Logging as Logging
logger = Logging.setup_logging()

####################################################################################################

from PySpice.Spice.Netlist import Circuit
from PySpice.Unit import *

####################################################################################################

#f# circuit_macros('resistor-bridge.m4')

circuit = Circuit('Resistor Divider')
#circuit.PulseMixin(0@u_V, 20@u_V, 5@u_us, 10@u_us, delay_time=0) #doesn't work
circuit.V('i', 'inp', circuit.gnd, 10@u_V) #works
circuit.R(1, 'inp', 'out', 5@u_kΩ)
circuit.R(2, 'out', circuit.gnd, 5@u_kΩ)


simulator = circuit.simulator(temperature=25, nominal_temperature=25)
analysis = simulator.transient(step_time=1@u_us, end_time=500@u_us)

####################################################################################################

figure1, ax = plt.subplots(figsize=(20, 10))
ax.set_title('Voltage Divider')
ax.set_xlabel('Time [s]')
ax.set_ylabel('Voltage [V]')
ax.grid()
ax.plot(analysis.inp)
ax.plot(analysis.out)
ax.legend(('input', 'output'), loc=(.05,.1))
#ax.set_ylim(float(-amplitude*1.1), float(amplitude*1.1))

#plt.tight_layout()
plt.show()

Can somebody help me please with the pulsed source?

You can use circuit.PulseVoltageSource() command.

See example code posted in the comments here: Introduction to PySpice (Python) for Simulating Natural and Step Response of RC Circuits - YouTube