% Configuration for techsweep_eldo_run.m
% Boris Murmann
% Stanford University
% September 13, 2017

% Patrick Munar & Claudio Talarico: 2021-07-26
% Gonzaga University
% Modified input netlist to match eldo syntax

function c = techsweep_cfg_bsim3_180_eldo

% Model info and file paths
c.modelfile = '/usr/class/models/ee214_hspice.mod';
c.modelinfo = 'Stanford EE214 models, 180nm CMOS, ELDO, BSIM3v3';
c.corner = 'NOM';
c.temp = 300;
c.modeln = 'nch';
c.modelp = 'pch';
c.savefilen = '180nch_e';
c.savefilep = '180pch_e';
c.simcmd = '/opt/mentor/amsv/amsv/bin/eldo -i techsweep.sp > techsweep.out';
c.outfile = 'techsweep.sw0';
c.outfile_noise = 'techsweep.ac0';

% Path to hspice toolbox (http://www.cppsim.com/download_hspice_tools.html)
addpath('/usr/local/MATLAB/HspiceToolbox')

% Sweep parameters
c.VGS_step = 25e-3;
c.VDS_step = 25e-3;
c.VSB_step = 100e-3;
c.VGS_max = 1.8;
c.VDS_max = 1.8;
c.VSB_max = 1.0;
c.VGS = 0:c.VGS_step:c.VGS_max;
c.VDS = 0:c.VDS_step:c.VDS_max;
c.VSB = 0:c.VSB_step:c.VSB_max;
c.LENGTH = [(0.18:0.02:0.5) (0.6:0.1:2.0)];
c.WIDTH = 5;
c.NFING = 1;

% Variable definitions
c.nvars = {'n_id', 'n_vt', 'n_vdsat', 'n_gm', 'n_gmb', 'n_gds', 'n_cgg', 'n_cgs', 'n_cgd', 'n_cgb', 'n_cdd', 'n_css'}; 
c.pvars = {'p_id', 'p_vt', 'p_vdsat', 'p_gm', 'p_gmb', 'p_gds', 'p_cgg', 'p_cgs', 'p_cgd', 'p_cgb', 'p_cdd', 'p_css'}; 
c.outvars = {'ID', 'VT', 'VDSAT', 'GM', 'GMB', 'GDS', 'CGG', 'CGS', 'CGD', 'CGB', 'CDD', 'CSS'};
c.nvars_noise = {'ni_mn', 'nf_mn'}; 
c.pvars_noise = {'ni_mp', 'nf_mp'}; 
c.outvars_noise = {'STH', 'SFL'};

% Simulation netlist
netlist = sprintf([...
'techsweep.sp \n'...
'.notrc \n'...
'.option COMPAT \n'...
'.option POST_VERSION=9601 POST=1 \n'...
'.option NOMOD NOASCII \n'...
'\n'...
'.inc %s \n'...
'.inc techsweep_params.sp \n'...
'.temp %d \n'...
'\n'...
'vnoi     vx  0         dc 0  ac 1 \n'...
'vdsn     vdn vx        dc ''ds''  \n'...
'vgsn     vgn 0         dc ''gs''  \n'...
'vbsn     vbn 0         dc ''-sb'' \n'...
'vdsp     vdp vx        dc ''-ds'' \n'...
'vgsp     vgp 0         dc ''-gs'' \n'...
'vbsp     vbp 0         dc ''sb''  \n'...
'h1       vn  0        ccvs  vnoi  1 \n'...
'r1       vn  0        100T nonoise \n'...
'mn       vdn vgn 0 vbn %s  L=''length*1e-6'' W=%d \n'...
'mp       vdp vgp 0 vbp %s  L=''length*1e-6'' W=%d \n'...
'\n'...
'***.dc gs 0 %d %d ds 0 %d %d \n'...
'.dc sweep data=data1 \n'...
'.ac lin 1 1 1 sweep data=data1 \n'...
'.noise v(vn) vnoi 80\n'...
'\n'...
'.probe dc n_id    = par(''id(mn)'') \n'...
'.probe dc n_vt    = par(''vth(mn)'') \n'...
'.probe dc n_vdsat = par(''vdsat(mn)'') \n'...
'.probe dc n_gm    = par(''gm(mn)'')   \n'...
'.probe dc n_gmb   = par(''gmbs(mn)'') \n'...
'.probe dc n_gds   = par(''gds(mn)'')  \n'...
'.probe dc n_cgg   = par(''cgg(mn)'') \n'...
'.probe dc n_cgs   = par(''-cgs(mn)'') \n'...
'.probe dc n_cgd   = par(''-cgd(mn)'') \n'...
'.probe dc n_cgb   = par(''-cbg(mn) '') \n'...
'.probe dc n_cdd   = par(''cdd(mn)'') \n'...
'.probe dc n_css   = par(''css(mn)'') \n'...
'\n'...
'.probe ac ni_mn   = par(''thnoise(mn)'') \n'...
'.probe ac nf_mn   = par(''flknoise(mn)'') \n'...
'\n'...
'.probe dc p_id    = par(''-id(mp)'') \n'...
'.probe dc p_vt    = par(''-vth(mp)'') \n'...
'.probe dc p_vdsat = par(''vdsat(mp)'') \n'...
'.probe dc p_gm    = par(''gm(mp)'')   \n'...
'.probe dc p_gmb   = par(''gmbs(mp)'') \n'...
'.probe dc p_gds   = par(''gds(mp)'')  \n'...
'.probe dc p_cgg   = par(''cgg(mp)'') \n'...
'.probe dc p_cgs   = par(''-cgs(mp)'') \n'...
'.probe dc p_cgd   = par(''-cgd(mp)'') \n'...
'.probe dc p_cgb   = par(''-cbg(mp) '') \n'...
'.probe dc p_cdd   = par(''cdd(mp)'') \n'...
'.probe dc p_css   = par(''css(mp)'') \n'...
'\n'...
'.probe ac ni_mp   = par(''thnoise(mp)'') \n'...
'.probe ac nf_mp   = par(''flknoise(mp)'') \n'...
'.end \n'...
], c.modelfile, c.temp-273, ...
c.modeln, c.WIDTH*1e-6, ...
c.modelp, c.WIDTH*1e-6, ...
c.VGS_max, c.VGS_step, ...
c.VDS_max, c.VDS_step);

% Write netlist
fid = fopen('techsweep.sp', 'w');
fprintf(fid, netlist);
fclose(fid);

return
