SPICE MOSFET level 1 CMOS inverter

load "spice/mos1.osdi"
load "resistor.osdi"
load "capacitor.osdi"

model v vsource
model r resistor
model c capacitor

model nm sp_mos1 ( type=1 
  rsh=8 tox=50e-10 ld=0.21e-6 lambda=0.05
  gamma=0.4 
  nsub=35e14 uo=700 vto=1 
  cgso=2.8e-10 cgdo=2.8e-10 cj=5.75e-5 cjsw=2.48e-10 
  pb=0.7 mj=0.5
  mjsw=0.3 kf=0.032f af=1
)

model pm sp_mos1 ( type=-1 
  rsh=8 tox=50e-10 ld=0.21e-6 lambda=0.05
  gamma=0.4 
  nsub=35e14 uo=700 vto=-1 
  cgso=2.8e-10 cgdo=2.8e-10 cj=5.75e-5 cjsw=2.48e-10 
  pb=0.7 mj=0.5
  mjsw=0.3 kf=0.032f af=1
)

vdd (1 0) v dc=5
m1 (out in 0 0) nm w=200u l=50u $mfactor=2 nrs=1 nrd=1
m2 (out in 1 1) pm w=200u l=50u $mfactor=2 nrs=1 nrd=1
r1 (out 0) r r=100k
vin (in 0) v dc=0 type="pulse" val0=0 val1=5 delay=1u rise=100n fall=100n width=1u period=2u

control
  analysis tran1 tran step=1n stop=5u maxstep=1n
 
  postprocess(PYTHON, "runme.py")
endc

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

raw = rawread('tran1.raw')
plot = raw.get()

fig1 = plt.figure(figsize=(8,8), dpi=100)
fig1.suptitle('Level 1 CMOS inverter')
ax_dict = fig1.subplot_mosaic("""
A
B
C
""")

ax_dict["A"].set_title('Input')
ax_dict["A"].set_ylabel('Vin [V]')
ax_dict["A"].set_xlabel('time [us]')
ax_dict["A"].plot(plot['time']*1e6, plot['in'])

ax_dict["B"].set_title('Output')
ax_dict["B"].set_ylabel('Vout [V]')
ax_dict["B"].set_xlabel('time [us]')
ax_dict["B"].plot(plot['time']*1e6, plot['out'])

ax_dict["C"].set_title('Supply current')
ax_dict["C"].set_ylabel('Idd [A]')
ax_dict["C"].set_xlabel('time [us]')
ax_dict["C"].plot(plot['time']*1e6, plot['vdd:flow(br)'])

fig1.tight_layout()

plt.show()
>>>FILE


