v {xschem version=3.4.6 file_version=1.2
*
* This file is part of XSCHEM,
* a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit
* simulation.
* Copyright (C) 1998-2024 Stefan Frederik Schippers
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
}
G {}
K {}
V {}
S {}
E {}
B 2 1690 -960 2250 -630 {flags=graph,unlocked

sim_type=dc
y1=-190
y2=0
divy=4
subdivy=1
x1=2.4
x2=2.6
divx=6
subdivx=1
node="\\"GAIN @ 2uA;diffout deriv() % 0\\"
\\"GAIN @ 10uA;diffout deriv() % 1\\"
\\"GAIN @ 100uA;diffout deriv() % 2\\""
color="8 7 6"
dataset=-1
autoload=1
xrawfile=$netlist_dir/cmos_example_ngspice.raw}
B 2 190 -760 327 -700 {flags=image
alpha=0.6
InvertOnExport=true
[encoded data, 50943 characters]}
B 2 20 -757.5 158 -695 {flags=image
alpha=0.6
InvertOnExport=true
image=/home/schippes/x/xyce.png
[encoded data, 61011 characters]}
B 2 1690 -620 2250 -300 {flags=graph,unlocked

sim_type=dc
y1=0.875402
y2=5.6754
divy=4
subdivy=1
x1=2.4088074
x2=2.6088074
divx=6
subdivx=1
node="diffout@2uA;v(diffout)%0
diffout@10uA;v(diffout)%1
diffout@100uA;v(diffout)%2"
color="8 7 6"
dataset=-1
autoload=1
xrawfile=$netlist_dir/cmos_example_ngspice.raw}
B 2 1050 -470 1680 -190 {flags=graph,unlocked

sim_type=tran
y1=1.4
y2=5
divy=5
subdivy=1
x1=0
x2=5e-06
divx=6
subdivx=1



dataset=-1
color="8 7 6"
node="\\"diffout 2uA; diffout%0\\"
\\"diffout 10uA; diffout%1\\"
\\"diffout 100uA; diffout%2\\""
hilight_wave=-1
xlabmag=1.4
autoload=1}
B 2 1050 -740 1680 -530 {flags=graph,unlocked

sim_type=ac
y1=-32
y2=46

subdivy=1
x1=0
x2=9
divx=6
subdivx=8



dataset=-1
color="8 7 6"
node="\\"gain 2uA; diffout db20()%0\\"
\\"gain 10uA; diffout db20()%1\\"
\\"gain 10uA; diffout db20()%2\\""
hilight_wave=-1
logx=1
xlabmag=1.4
divy=5
ylabmag=1.2
autoload=1
xrawfile=$netlist_dir/cmos_example_ngspice.raw}
B 2 1050 -960 1680 -750 {flags=graph,unlocked

sim_type=ac
y1=18
y2=180
divy=4
subdivy=1
x1=0
x2=9
divx=6
subdivx=8



dataset=-1
color="8 7 6"
node="\\"phase 2uA; ph(diffout)%0\\"
\\"phase 10uA; ph(diffout)%1\\"
\\"phase 100uA; ph(diffout)%2\\""
hilight_wave=-1
logx=1
xlabmag=1.4
autoload=1
xrawfile=$netlist_dir/cmos_example_ngspice.raw}
B 2 1690 -290 2250 -20 {flags=graph,unlocked

sim_type=dc
y1=2.3
y2=2.7
divy=4
subdivy=1
x1=2.4088074
x2=2.6088074
divx=6
subdivx=1
node="minus;minus%0
plus;plus%0"
color="7 8"
dataset=-1
autoload=1
xrawfile=$netlist_dir/cmos_example_ngspice.raw}
B 2 1050 -180 1680 -60 {flags=graph,unlocked

sim_type=tran
y1=2.4
y2=2.6
divy=2
subdivy=1
x1=0
x2=5e-06
divx=6
subdivx=1



dataset=-1
color="7 8"
node="minus;minus%0
plus;plus%0"
hilight_wave=-1
ylabmag=1.4
xlabmag=1.4
autoload=1}
T {CMOS DIFFERENTIAL AMPLIFIER
EXAMPLE. DC simulation} 30 -680 0 0 0.4 0.4 {}
T {tcleval([xschem raw info])} 20 -960 0 0 0.4 0.4 {floater=true layer=16}
T {AC Analysis} 1060 -1010 0 0 0.6 0.6 { layer=6}
T {Transient Analysis} 1060 -510 0 0 0.6 0.6 { layer=6}
T {DC Analysis} 1690 -1000 0 0 0.6 0.6 { layer=6}
T {Loaded Raw files:} 20 -1010 0 0 0.6 0.6 {}
T {tcleval(Power: [to_eng [xschem raw value power 0]]W)} 820 -570 0 0 0.4 0.4 {floater=-1 layer=15}
T {Example of fetching a user
parameter saved in raw file.} 730 -630 0 0 0.4 0.4 { layer=15}
T {Power: @spice_get_voltage(power)\\W} 820 -540 0 0 0.4 0.4 {floater=true layer=15}
N 30 -310 30 -280 {
lab=VCC}
N 30 -310 60 -310 {
lab=VCC}
N 260 -240 260 -190 {
lab=GN}
N 260 -190 300 -190 {
lab=GN}
N 300 -190 300 -160 {
lab=GN}
N 300 -160 530 -160 {
lab=GN}
N 500 -290 520 -290 {
lab=0}
N 670 -290 690 -290 {
lab=0}
N 500 -260 690 -260 {
lab=S}
N 440 -290 460 -290 {
lab=PLUS}
N 730 -290 750 -290 {
lab=MINUS}
N 690 -490 740 -490 {
lab=VCC}
N 450 -490 500 -490 {
lab=VCC}
N 540 -490 650 -490 {
lab=G}
N 540 -490 540 -460 {
lab=G}
N 500 -460 540 -460 {
lab=G}
N 690 -560 690 -520 {
lab=VCC}
N 500 -560 690 -560 {
lab=VCC}
N 500 -560 500 -520 {
lab=VCC}
N 570 -580 570 -560 {
lab=VCC}
N 690 -420 840 -420 {
lab=DIFFOUT}
N 30 -440 30 -410 {
lab=MINUS}
N 30 -440 60 -440 {
lab=MINUS}
N 30 -590 30 -560 {
lab=PLUS}
N 30 -590 60 -590 {
lab=PLUS}
N 570 -130 570 -100 {
lab=0}
N 570 -130 590 -130 {
lab=0}
N 590 -160 590 -130 {
lab=0}
N 570 -160 590 -160 {
lab=0}
N 260 -130 260 -100 {
lab=0}
N 240 -130 260 -130 {
lab=0}
N 240 -160 240 -130 {
lab=0}
N 240 -160 260 -160 {
lab=0}
N 690 -460 690 -400 {
lab=DIFFOUT}
N 570 -260 570 -250 {
lab=S}
N 500 -340 500 -320 {
lab=#net1}
N 570 -250 570 -190 {
lab=S}
N 690 -340 690 -320 {
lab=#net2}
N 500 -460 500 -400 {
lab=G}
C {code.sym} 800 -240 0 0 {name="MODELS"
spice_ignore=0
only_toplevel=false value="
** From the ngspice distribution:
** https://sourceforge.net/p/ngspice/ngspice/ci/master/tree/examples/mos/modelcard.nmos
** https://sourceforge.net/p/ngspice/ngspice/ci/master/tree/examples/mos/modelcard.pmos

.model cmosn NMOS
+Level=        49 version=3.3.0
+Tnom=27.0
+Nch= 2.498E+17  Tox=9E-09 Xj=1.00000E-07
+Lint=9.36e-8 Wint=1.47e-7
+Vth0= .6322    K1= .756  K2= -3.83e-2  K3= -2.612
+Dvt0= 2.812  Dvt1= 0.462  Dvt2=-9.17e-2
+Nlx= 3.52291E-08  W0= 1.163e-6
+K3b= 2.233
+Vsat= 86301.58  Ua= 6.47e-9  Ub= 4.23e-18  Uc=-4.706281E-11
+Rdsw= 650  U0= 388.3203 wr=1
+A0= .3496967 Ags=.1    B0=0.546    B1= 1
+Dwg = -6.0E-09 Dwb = -3.56E-09 Prwb = -.213
+Keta=-3.605872E-02  A1= 2.778747E-02  A2= .9
+Voff=-6.735529E-02  NFactor= 1.139926  Cit= 1.622527E-04
+Cdsc=-2.147181E-05
+Cdscb= 0  Dvt0w =  0 Dvt1w =  0 Dvt2w =  0
+Cdscd =  0 Prwg =  0
+Eta0= 1.0281729E-02  Etab=-5.042203E-03
+Dsub= .31871233
+Pclm= 1.114846  Pdiblc1= 2.45357E-03  Pdiblc2= 6.406289E-03
+Drout= .31871233  Pscbe1= 5000000  Pscbe2= 5E-09 Pdiblcb = -.234
+Pvag= 0 delta=0.01
+Wl =  0 Ww = -1.420242E-09 Wwl =  0
+Wln =  0 Wwn =  .2613948 Ll =  1.300902E-10
+Lw =  0 Lwl =  0 Lln =  .316394
+Lwn =  0
+kt1=-.3  kt2=-.051
+At= 22400
+Ute=-1.48
+Ua1= 3.31E-10  Ub1= 2.61E-19 Uc1= -3.42e-10
+Kt1l=0 Prt=764.3
+vgs_max=4 vds_max=4 vbs_max=4

.model cmosp PMOS
+Level=        49 version=3.3.0
+Tnom=27.0
+Nch= 3.533024E+17  Tox=9E-09 Xj=1.00000E-07
+Lint=6.23e-8 Wint=1.22e-7
+Vth0=-.6732829 K1= .8362093  K2=-8.606622E-02  K3= 1.82
+Dvt0= 1.903801  Dvt1= .5333922  Dvt2=-.1862677
+Nlx= 1.28e-8  W0= 2.1e-6
+K3b= -0.24 Prwg=-0.001 Prwb=-0.323
+Vsat= 103503.2  Ua= 1.39995E-09  Ub= 1.e-19  Uc=-2.73e-11
+Rdsw= 460  U0= 138.7609
+A0= .4716551 Ags=0.12
+Keta=-1.871516E-03  A1= .3417965  A2= 0.83
+Voff=-.074182  NFactor= 1.54389  Cit=-1.015667E-03
+Cdsc= 8.937517E-04
+Cdscb= 1.45e-4  Cdscd=1.04e-4
+Dvt0w=0.232 Dvt1w=4.5e6 Dvt2w=-0.0023
+Eta0= 6.024776E-02  Etab=-4.64593E-03
+Dsub= .23222404
+Pclm= .989  Pdiblc1= 2.07418E-02  Pdiblc2= 1.33813E-3
+Drout= .3222404  Pscbe1= 118000  Pscbe2= 1E-09
+Pvag= 0
+kt1= -0.25  kt2= -0.032 prt=64.5
+At= 33000
+Ute= -1.5
+Ua1= 4.312e-9 Ub1= 6.65e-19  Uc1= 0
+Kt1l=0
+vgs_max=4 vds_max=4 vbs_max=4
"}
C {lab_pin.sym} 30 -220 0 0 {name=p17 lab=0}
C {title.sym} 160 -30 0 0 {name=l1 author="Stefan Schippers"}
C {nmos4.sym} 550 -160 0 0 {name=m1 model=cmosn w=5u l=2u m=1}
C {pmos4.sym} 670 -490 0 0 {name=m2 model=cmosp w=5u l=2u m=1}
C {vsource.sym} 30 -250 0 0 {name=VVCC value='VCC'
}
C {lab_pin.sym} 570 -100 0 0 {name=p1 lab=0}
C {lab_pin.sym} 60 -310 0 1 {name=p2 lab=VCC}
C {nmos4.sym} 280 -160 0 1 {name=m3 model=cmosn w=5u l=2u m=1}
C {lab_pin.sym} 260 -100 0 0 {name=p3 lab=0}
C {isource.sym} 260 -270 0 0 {name=IBIAS value='IB'
}
C {lab_pin.sym} 260 -300 0 0 {name=p4 lab=0}
C {nmos4.sym} 480 -290 0 0 {name=m4 model=cmosn w=10u l=1u m=1}
C {lab_pin.sym} 520 -290 0 1 {name=p5 lab=0}
C {nmos4.sym} 710 -290 0 1 {name=m5 model=cmosn w=10u l=1u m=1}
C {lab_pin.sym} 670 -290 0 0 {name=p0 lab=0}
C {lab_pin.sym} 740 -490 0 1 {name=p6 lab=VCC}
C {pmos4.sym} 520 -490 0 1 {name=m6 model=cmosp w=5u l=2u m=1}
C {lab_pin.sym} 450 -490 0 0 {name=p7 lab=VCC}
C {lab_pin.sym} 570 -580 0 0 {name=p8 lab=VCC}
C {lab_pin.sym} 440 -290 0 0 {name=p9 lab=PLUS}
C {lab_pin.sym} 750 -290 0 1 {name=p10 lab=MINUS}
C {lab_pin.sym} 840 -420 0 1 {name=p11 lab=DIFFOUT}
C {lab_pin.sym} 260 -220 0 0 {name=p13 lab=GN}
C {lab_pin.sym} 30 -350 0 0 {name=p14 lab=0}
C {vsource.sym} 30 -380 0 0 {name=VMINUS
value="2.5 pulse 2.4 2.6 10n 1n 1n 0.999u 2u ac 1 0" 

}
C {lab_pin.sym} 60 -440 0 1 {name=p15 lab=MINUS}
C {lab_pin.sym} 30 -500 0 0 {name=p16 lab=0}
C {vsource.sym} 30 -530 0 0 {name=VPLUS value=2.5}
C {lab_pin.sym} 60 -590 0 1 {name=p18 lab=PLUS}
C {capa.sym} 750 -390 0 0 {name=CL
m=1
value=0.2p
footprint=1206
device="ceramic capacitor"}
C {lab_pin.sym} 500 -430 0 0 {name=p12 lab=G}
C {launcher.sym} 700 -60 0 0 {name=h1
descr=Backannotate
tclcommand="xschem annotate_op $\{netlist_dir\}/cmos_example_ngspice.raw"
}
C {launcher.sym} 700 -110 0 0 {name=h2
descr="View raw file"
tclcommand="textwindow $netlist_dir/cmos_example_ngspice.raw"}
C {launcher.sym} 475 -695 0 0 {name=h3 
descr="Load NGSPICE waveforms (ctrl-left-click)" 
tclcommand="
xschem raw_read $netlist_dir/cmos_example_ngspice.raw tran
"
}
C {launcher.sym} 1310 -30 0 0 {name=h4
descr="Graph Manual page"
url="https://xschem.sourceforge.io/stefan/xschem_man/graphs.html"}
C {ammeter.sym} 690 -370 0 1 {name=Vmeasr}
C {simulator_commands.sym} 920 -360 0 0 {name=COMMANDS
simulator=ngspice
only_toplevel=true 
value=".temp 30
.param IB=2u
.param VCC = 5

.option savecurrents
.save all @m1[gm] @m2[gm] @m3[gm] @m4[gm] @m5[gm] @m6[gm]
.control
  save all alli
  op
  let power=-v(vcc) * i(vvcc)
  settype power power
  write cmos_example_ngspice.raw
  set appendwrite
  dc vminus 2.4 2.6 0.001
  write cmos_example_ngspice.raw
  tran 0.5n 5u
  write cmos_example_ngspice.raw
  ac dec 10 1 1G
  remzerovec
  write cmos_example_ngspice.raw

  alterparam IB=10u
  reset
  save all
  dc vminus 2.4 2.6 0.001
  write cmos_example_ngspice.raw
  tran 0.5n 5u
  write cmos_example_ngspice.raw
  ac dec 10 1 1G
  remzerovec
  write cmos_example_ngspice.raw

  alterparam IB=100u
  reset
  save all
  dc vminus 2.4 2.6 0.001
  write cmos_example_ngspice.raw
  tran 0.5n 5u
  write cmos_example_ngspice.raw
  ac dec 10 1 1G
  remzerovec
  write cmos_example_ngspice.raw
  quit 0
.endc

"}
C {launcher.sym} 475 -655 0 0 {name=h6 
descr="Load XYCE waveforms (ctrl-left-click)" 
tclcommand="
xschem raw_read $netlist_dir/cmos_example_xyce.raw
"
}
C {simulator_commands.sym} 920 -180 0 0 {name=COMMANDS1
simulator=xyce
only_toplevel=true 
value="* .temp 30
.param IB=100u
.param VCC = 5

.op
.print dc format=raw file=cmos_example_xyce.raw v(*) i(*)
.dc vminus 2.4 2.6 0.001
.print dc format=raw file=cmos_example_xyce.raw v(*) i(*)

"}
C {ngspice_get_expr.sym} 160 -150 0 0 {name=r8 node="[to_eng [expr \{[ngspice::get_voltage gn] * [ngspice::get_current \{m3[id]\}]\}]]"
descr="Power="
}
C {ammeter.sym} 500 -370 0 1 {name=Vmeasl}
C {lab_pin.sym} 570 -230 0 0 {name=p19 lab=S}
C {launcher.sym} 475 -735 0 0 {name=h5 
descr="Switch rawfile" 
tclcommand="
xschem raw switch; xschem redraw"

}
C {ngspice_get_value.sym} 480 -240 0 1 {name=r2 node=@$\{path\}m4[gm]
descr="gm="}
C {ngspice_get_value.sym} 710 -240 0 0 {name=r3 node=@$\{path\}m5[gm]
descr="gm="}
C {ngspice_get_value.sym} 610 -130 0 0 {name=r4 node=@$\{path\}m1[gm]
descr="gm="}
C {lab_pin.sym} 750 -360 0 0 {name=p20 lab=0}
C {ngspice_get_value.sym} 700 -520 0 0 {name=r1 node=@$\{path\}m2[gm]
descr="gm="}
C {ngspice_get_value.sym} 490 -520 0 1 {name=r5 node=@$\{path\}m6[gm]
descr="gm="}
