Multiplier

load "psp103v4.osdi"
load "spice/resistor.osdi"

include "models.inc"
// include "mul8.inc"
// include "mul16.inc"
// include "mul32.inc"
// include "mul64.inc"
// include "mul128.inc"
 include "mul256.inc"

model v vsource
model r sp_resistor

parameters vdd=1.2

vdd (vdd 0) v dc=vdd
vss (vss 0) v dc=0

control
  options nr_convtol=1 nr_bypasstol=1 nr_bypass=0 nr_contbypass=1 
  options tran_lteratio=1.5
  // options nr_residualcheck=0
  // options tran_debug=0
  // options tran_redofactor=2.5 tran_lteratio=3.5 tran_spicelte=1 
  
  elaborate circuit("mul_test")
  print counts
  analysis tranmul tran stop=2n step=2p icmode="uic"
  // analysis tranmul tran stop=10p step=2p icmode="uic"
  
  print stats
  
  // postprocess(PYTHON, "runme.py")
endc

embed "runme.py" <<<FILE
from rawfile import rawread
import numpy as np
import sys

scaling = 0.8/1.2

import matplotlib.pyplot as plt 

def plot_signals(axes, plot, signals, scaling):
  for ii, name in enumerate(signals):
    axes.axhline(0-ii, color="black")
    axes.plot(tm['time']*1e9, tm[name]*scaling-ii, color="blue", label=name)

fig1, ax1 = plt.subplots(1, 2, figsize=(8, 12), dpi=100, tight_layout=True)
fig1.axes[0].set_title('Multiplier inputs')
fig1.axes[0].set_xlabel('time [ns]')
fig1.axes[1].set_title('Multiplier outputs')
fig1.axes[1].set_xlabel('time [ns]')

tm = rawread('tranmul.raw').get()
n = len([name for name in tm.names if name[0]=="a"])
print(f"Multiplier size: {n}x{n}")
plot_signals(fig1.axes[0], tm, [f"a{ii}" for ii in range(n)]+[f"b{ii}" for ii in range(n)], scaling)
plot_signals(fig1.axes[1], tm, [f"p{ii}" for ii in range(2*n)], scaling)

plt.show()
>>>FILE
