]> Creatis software - CreaPhase.git/blob - octave_packages/ocs-0.1.3/sbn/Mnmosfet.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / ocs-0.1.3 / sbn / Mnmosfet.m
1 ## Copyright (C) 2006,2007,2008  Carlo de Falco            
2 ##
3 ## This file is part of:
4 ## OCS - A Circuit Simulator for Octave
5 ##
6 ## OCS is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation.
9 ##
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ## GNU General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program (see the file LICENSE); if not,
17 ## see <http://www.gnu.org/licenses/>.
18 ##
19 ## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> 
20
21 ## -*- texinfo -*-
22 ##
23 ## @deftypefn{Function File} @
24 ## {[@var{a},@var{b},@var{c}]=}Mnmosfet(@var{string},@var{parameters},@
25 ## @var{parameternames},@var{extvar},@var{intvar},@var{t})
26 ##
27 ## SBN file implementing standard models for n-mosfets.
28 ##
29 ## @var{string} is used to select among models. Parameters are listed
30 ## as inner items. Possible models are:
31 ##
32 ## @enumerate
33 ## @item @var{string} = "simple" (Standard model for MOSFET)
34 ## @itemize @minus
35 ## @item rd  -> parasitic resistance between drain and source
36 ## @item k   -> k parameter for usual mosfet model
37 ## @item Vth -> threshold voltage
38 ## @end itemize
39 ## @item @var{string} = "lincap" (Adds RC parasitics)
40 ## @itemize @minus
41 ## @item rd  -> parasitic resistance between drain and source
42 ## @item k   -> k parameter for usual mosfet model
43 ## @item Vth -> threshold voltage
44 ## @item Rs  -> parasitic source resistance 
45 ## @item Rd  -> parasitic drain resistance
46 ## @item Cs  -> gate-source capacitance
47 ## @item Cd  -> gate-drain capacitance
48 ## @item Cb  -> gate-bulk capacitance
49 ## @end itemize
50 ## @end enumerate
51 ##
52 ## See the @cite{IFF file format specifications} for details about 
53 ## the output structures.
54 ##
55 ## @seealso{prs_iff,asm_initialize_system,asm_build_system}
56 ## @end deftypefn
57
58 function [a,b,c]=Mnmosfet(string,parameters,parameternames,extvar,intvar,t) 
59   
60   switch string
61     case "simple"
62       
63       rd   = 1e6;
64       k    = 1e-5;
65       Vth  = .5;
66
67       for ii=1:length(parameternames)
68         eval([parameternames{ii} "=",...
69               num2str(parameters(ii)) " ;"])    
70       endfor
71
72       vg   = extvar(1);
73       vs   = extvar(2);
74       vd   = extvar(3);
75       vb   = extvar(4);
76
77       vgs  = vg-vs;
78       vds  = vd-vs;
79       
80       if (vgs < Vth)
81
82         
83         gm = 0;
84         gd = 1/rd;
85         id = vds*gd;
86         
87       elseif (((vgs-Vth) >= (vds)) && (vds>=0))
88         
89         id = k*((vgs-Vth)*vds-(vds^2)/2)+vds/rd;
90         gm = k*vds;
91         gd = k*(vgs-Vth-vds)+1/rd;
92
93       elseif (((vgs-Vth) >= (vds)) && (vds<0))
94         
95         gm = 0;
96         gd = 1/rd;
97         id = vds*gd;
98
99       else # (i.e. if 0 <= vgs-vth <= vds)
100
101         id = (k/(2))*(vgs-Vth)^2+vds/rd;
102         gm = (2*k/(2))*(vgs-Vth);
103         gd = 1/rd;
104
105       endif
106       
107       a = zeros(4);
108       
109       b = [0    0       0 0;
110            -gm  (gm+gd) -gd 0; 
111            gm -(gm+gd)  gd 0;
112            0    0       0  0];
113       
114       c = [0 -id id 0]';
115       break;
116
117     case "lincap"
118
119       ## Default parameter values
120       if isempty(intvar)
121         intvar = zeros(5,1);
122       endif
123       Rs = 1e2; Rd = 1e2; Cs = 1e-15; 
124       Cd = 1e-15; Cb = 1e-14;
125       rd = inf; k = 1e-3; Vth = .1; 
126
127       ## parameters given in input
128       for ii=1:length(parameternames)
129         eval([parameternames{ii} "=",...
130               num2str(parameters(ii)) " ;"])    
131       endfor
132       
133      
134       persistent tmpstruct
135       
136       if isempty(tmpstruct)
137  
138         mtdnmos   = file_in_path(path,"Mtdnmos.cir");
139         mtdnmos(end-3:end)=[];
140         tmpstruct = prs_iff(mtdnmos);
141   
142       endif
143      
144
145       tmpstruct.NLC.pvmatrix    = [k Vth rd];
146       tmpstruct.LCR(1).pvmatrix = [Rs; Rd];
147       tmpstruct.LCR(2).pvmatrix = [Cs; Cd; Cb];
148
149       [A0,B,C]     = asm_initialize_system(tmpstruct,[extvar;intvar]);
150       [A1,Jac,res] = asm_build_system(tmpstruct,[extvar;intvar],t);
151
152       a = A0+A1;
153       b = B+Jac;
154       c = res + B*[extvar;intvar] + C;
155
156       break;
157     otherwise
158       error(["unknown option:" string]);
159   endswitch
160
161 endfunction