SKiDL generated transient analysis fails in PSPICE compatability mode with ngspice example of TLC555.LIB
Environment (OS, Python version, PySpice version, simulator)
OS: Ubuntu 20.04 Python: 3.8 PySpice version: 1.5 (from github repo, pulled 13 May 2021) simulator: ngspice (32)
Expected Behaviour
transient simulation runs to completion after single round of gmin stepping:
ngspice 1 -> set ngbehavior=psa ngspice 2 -> source 555testfromskidl_edit2.cir
Circuit:
Warning: Model issue on line 97 : .model tlc55x_nmosd_hv nmos level=3 l=10u w=100u kp= 6.00000000000000 ... unrecognized parameter (lambda) - ignored Warning: Model issue on line 119 : .model tlc55x_pmosd_hv pmos level=3 l=10u w=100u kp= 3.00000000000000 ... unrecognized parameter (lambda) - ignored ngspice 3 -> run Reducing trtol to 1 for xspice 'A' devices Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
Note: Starting true gmin stepping Trying gmin = 1.0000E-03 Note: One successful gmin step Trying gmin = 1.0000E-04 Note: One successful gmin step Trying gmin = 1.0000E-05 Note: One successful gmin step Trying gmin = 1.0000E-06 Note: One successful gmin step Trying gmin = 1.0000E-07 Warning: Further gmin increment Trying gmin = 5.6234E-07 Note: One successful gmin step Trying gmin = 2.3714E-07 Note: One successful gmin step Trying gmin = 6.4938E-08 Note: One successful gmin step Trying gmin = 9.3057E-09 Note: One successful gmin step Trying gmin = 9.3057E-10 Note: One successful gmin step Trying gmin = 9.3057E-11 Note: One successful gmin step Trying gmin = 9.3057E-12 Note: One successful gmin step Trying gmin = 1.0000E-12 Note: One successful gmin step Note: True gmin stepping completed
Initial Transient Solution
Node Voltage
n_1 5 n_4 0 n_2 0.0488951 n_3 0.048895 n_6 3.33333 n_5 0.0973977 x1.resi 0 x1.trgi 0.048895 x1.thri 0.048895 x1.conti 3.33333 x1.qff 0 x1.gout 5 x1.trgo 2.00023e-15 x1.xmn3.10 0.14 x1.23 0.14 x1.thrs 2.78252 x1.xmn5.10 0.14 x1.25 0.140003 x1.reso 4.46159 x1.15 5e-06 x1.xmp9.10 4.15 x1.xmp6.10 4.15 x1.trgs 0.649699 x1.xmp5.10 4.15 x1.thro 4.91329 x1.xmp1.10 4.86 x1.29 4.85999 x1.xib.gb_int1 0 x1.xrsff.xu1.out_vmeas_0 1 x1.xrsff.xu1.eout_int1 1 x1.30 1 x1.xrsff.xu2.out_vmeas_2 0 x1.xrsff.xu2.eout_int1 0 x1.xrsff.xu2.1 0.240964 x1.xrsff.xu2.e1_int1 0.240964 x1.trgc 1.66667 x1.32 0.833333 x1.33 2.5 x1.34 4.16667 b.x1.xrsff.xu2.be1#branch 0 b.x1.xrsff.xu2.beout#branch 0 v.x1.xrsff.xu2.v_eout#branch 0 b.x1.xrsff.xu1.beout#branch 0 v.x1.xrsff.xu1.v_eout#branch 0 b.x1.xib.bgb#branch 0 v.x1.xmp1.v1#branch 1.96223e-10 v.x1.xmn5.v1#branch 2.31055e-11 v.x1.xmn3.v1#branch -9.99994e-07 e.x1.xrsff.xu2.e1#branch 0 e.x1.xrsff.xu2.eout#branch 0 e.x1.xrsff.xu1.eout#branch 0 v.x1.xmp5.v1#branch 4.50029e-12 v.x1.xmp6.v1#branch 5.00999e-12 v.x1.xmp9.v1#branch -2.03397e-10 vreset#branch 0 v2#branch -0.00986481
Reference value : 7.41510e-02 No. of Data Rows : 12002 ngspice 4 -> plot v(N_3) v(N_5) v(N_2) ngspice 5 -> exit ngspice-32 done
Actual Behaviour
transient simulation fails after 2 rounds gmin stepping (uncertain why 2 rounds are running)
Note: Starting true gmin stepping Trying gmin = 1.0000E-03 Note: One successful gmin step Trying gmin = 1.0000E-04 Note: One successful gmin step Trying gmin = 1.0000E-05 Note: One successful gmin step Trying gmin = 1.0000E-06 Note: One successful gmin step Trying gmin = 1.0000E-07 Warning: Further gmin increment Trying gmin = 5.6234E-07 Note: One successful gmin step Trying gmin = 2.3714E-07 Note: One successful gmin step Trying gmin = 6.4938E-08 Note: One successful gmin step Trying gmin = 9.3057E-09 Note: One successful gmin step Trying gmin = 9.3057E-10 Note: One successful gmin step Trying gmin = 9.3057E-11 Note: One successful gmin step Trying gmin = 9.3057E-12 Note: One successful gmin step Trying gmin = 1.0000E-12 Note: One successful gmin step Note: True gmin stepping completed Note: Starting true gmin stepping Trying gmin = 1.0000E-03 Note: One successful gmin step Trying gmin = 1.0000E-04 Note: One successful gmin step Trying gmin = 1.0000E-05 Note: One successful gmin step Trying gmin = 1.0000E-06 Note: One successful gmin step Trying gmin = 1.0000E-07 Warning: Further gmin increment Trying gmin = 5.6234E-07 Note: One successful gmin step Trying gmin = 2.3714E-07 Note: One successful gmin step Trying gmin = 6.4938E-08 Note: One successful gmin step Trying gmin = 9.3057E-09 Note: One successful gmin step Trying gmin = 9.3057E-10 Note: One successful gmin step Trying gmin = 9.3057E-11 Note: One successful gmin step Trying gmin = 9.3057E-12 Note: One successful gmin step Trying gmin = 1.0000E-12 Note: One successful gmin step Note: True gmin stepping completed
NgSpiceCommandError Traceback (most recent call last)
in 1 #sim = circ.simulator() # Get a simulator for the Circuit object. ----> 2 waveforms = sim.transient(step_time=0.01@u_ms, end_time=100@u_ms) # Run a transient simulation from 0 to 100 msec. 3 # Get the simulation data. 4 time = waveforms.time # Time values for each point on the waveforms. 5 # TLC 555 pin names below ~/miniconda3/envs/circuitsimpipupd/lib/python3.8/site-packages/PySpice/Spice/Simulation.py in transient(self, *args, **kwargs) 1212 1213 def transient(self, *args, **kwargs): -> 1214 return self._run('transient', *args, **kwargs) 1215 1216 ##############################################
~/miniconda3/envs/circuitsimpipupd/lib/python3.8/site-packages/PySpice/Spice/NgSpice/Simulation.py in _run(self, analysis_method, *args, **kwargs) 117 # Fixme: Error: circuit not parsed. 118 self._ngspice_shared.load_circuit(str(self)) --> 119 self._ngspice_shared.run() 120 self._logger.debug(str(self._ngspice_shared.plot_names)) 121 self.reset_analysis()
~/miniconda3/envs/circuitsimpipupd/lib/python3.8/site-packages/PySpice/Spice/NgSpice/Shared.py in run(self, background) 1190 1191 command = 'bg_run' if background else 'run' -> 1192 self.exec_command(command) 1193 1194 if background:
~/miniconda3/envs/circuitsimpipupd/lib/python3.8/site-packages/PySpice/Spice/NgSpice/Shared.py in exec_command(self, command, join_lines) 849 850 if self._error_in_stdout or self._error_in_stderr: --> 851 raise NgSpiceCommandError("Command '{}' failed".format(command)) 852 853 if join_lines:
NgSpiceCommandError: Command 'run' failed
Steps to reproduce the behaviour
- Install Pyspice 1.5/SKiDL 1.0.0
- copy/rename TLC555.LIB to TLC555.lib (another PySpice bug or feature?, it only uses lowercase extensions) in the ngspice/examples/p-to-n-example directory (assumed to be located below current directory)
- run the following code in python (I ran in a Jupyter notebook):
import skidl
lib_search_paths[SPICE].append('ngspice/examples/p-to-n-examples')
reset() # Clear out the existing circuitry from the previous example.
# Create a pulsed voltage source, a resistor, and a capacitor.
v2 = V(ref='V2', dc_value=5@u_V)
vreset = PULSEV(ref='VRESET',initial_value=0,pulsed_value=5@u_V,delay_time=1@u_us,rise_time=1@u_us,fall_time=1@u_us,pulse_width=30@u_ms,period=50@u_ms)
ra=R(ref='RA',value=1@u_kOhm)
rb=R(ref='RB',value=5@u_kOhm)
c=C(ref='C',value=0.5@u_uF)
ccont=C(ref='Ccont',value=0.5@u_uF)
rl=R(ref='RL',value=1@u_kOhm)
ra['+','-']+=v2['p'],rb['+']
rl['+']+=v2['p']
c['+']+=rb['-']
x1 = Part('TLC555','TLC555')
c['+']+=x1['THRES'],x1['TRIG']
x1['RESET']+=vreset['p']
x1['OUT']+=rl['-']
x1['DISC']+=rb['+']
x1['VCC']+=v2['p']
x1['CONT']+=ccont['+']
x1['GND']+=gnd
gnd +=v2['n'],c['-'],vreset['n'],ccont['-']
# Simulate the circuit.
circ = generate_netlist() # Create the PySpice Circuit object from the SKiDL code.
# add files to match working example from ngspice directory
circ.raw_spice+='''
.TRAN 10u 100MS
.OPTIONS RELTOL=.0001
.SAVE v(N_3) v(N_5) v(N_2)
'''
print(circ)
sim = circ.simulator() # Get a simulator for the Circuit object.
sim.ngspice.exec_command('set ngbehavior=psa') # make pspice compatability mode to use the TLC555.lib
waveforms = sim.transient(step_time=0.01@u_ms, end_time=100@u_ms) # Run a transient simulation from 0 to 100 msec.
# Get the simulation data.
time = waveforms.time # Time values for each point on the waveforms.
# TLC 555 pin names below
thres = waveforms[node(x1['THRES'])] # Voltage on the positive terminal of the pulsed voltage source.
out = waveforms[node(x1['OUT'])]
disc = waveforms[node(x1['DISC'])]
figure = plt.figure(1)
plt.title('555 Timer output vs threshold vs. discharge')
plt.xlabel('Time (ms)')
plt.ylabel('Voltage (V)')
plt.plot(time*1000, thres)
plt.plot(time*1000, out)
plt.plot(time*1000, disc)
plt.legend(('Threshold', 'Output Voltage','Discharge'), loc=(1.1, 0.5))
plt.show()
Note: Circuit simulates in ngspice-32 after using "set ngbehavior=psa" from command line and then sourcing the following file (generated from the code above)
.title .include /home/user/simulation/ngspice/examples/p-to-n-examples/TLC555.lib V2 N_1 0 5V VRESET N_4 0 DC 0V PULSE(0V 5V 1us 1us 1us 30ms 50ms) RA N_1 N_2 1kOhm RB N_2 N_3 5kOhm C N_3 0 0.5uF Ccont N_6 0 0.5uF RL N_1 N_5 1kOhm X1 N_3 N_6 N_3 N_4 N_5 N_2 N_1 0 tlc555