]> Creatis software - CreaPhase.git/blob - octave_packages/ocs-0.1.3/sbn/Mshichmanhodgesmosfet.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / ocs-0.1.3 / sbn / Mshichmanhodgesmosfet.m
1 ## Copyright (C) 2006-2009  Carlo de Falco, Massimiliano Culpo
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>, culpo@math.uni-wuppertal.de
20
21 ## -*- texinfo -*-
22 ##
23 ## @deftypefn{Function File} @
24 ## {[@var{a},@var{b},@var{c}]=} Mshichmanhodgesmosfet(@var{string},@var{parameters},@
25 ## @var{parameternames},@var{extvar},@var{intvar},@var{t})
26 ##
27 ## SBN file implementing Schichman-Hodges MOSFETs model.
28 ##
29 ## @var{string} is used to select among models. Possible models are:
30 ##
31 ## @enumerate
32 ## @item @var{string} = "NMOS" (Schichman-Hodges n-MOSFET)
33 ## @item @var{string} = "PMOS" (Schichman-Hodges p-MOSFET)
34 ## @end enumerate
35 ##
36 ## Parameters for all the above models are:
37 ## @itemize
38 ## @item rd     -> parasitic resistance between drain and source
39 ## @item W      -> MOSFET width
40 ## @item L      -> channel length
41 ## @item mu0    -> reference value for mobility
42 ## @item Vth    -> threshold voltage
43 ## @item Cox    -> oxide capacitance
44 ## @item Cgs    -> gate-source capacitance
45 ## @item Cgd    -> gate-drain capacitance
46 ## @item Cgb    -> gate-bulk capacitance
47 ## @item Csb    -> source-bulk capacitance
48 ## @item Cdb    -> drain-bulk capacitance
49 ## @item Tshift -> shift for reference temperature on MOSFETs (default 0)
50 ## @end itemize
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]= Mshichmanhodgesmosfet (string,parameters,parameternames,extvar,intvar,t)   
59
60   if isempty(intvar)
61     ## If intvar is empty, then we are initializing the system
62     ## and there is no need of a matrix evaluation
63     a = sparse(10,10);
64     b = [];
65     c = [];
66   else
67     ## If intvar is NOT empty, then we are evaluating the 
68     ## element stamp
69     switch string
70       case "NMOS"
71         
72         rd   = 1e6;
73         W    = 1;
74         L    = 1;
75         mu0  = 1e-5;
76         Vth  = .5;
77         Cox  = 1e-9;
78         Cgb  = Cox;
79         Cgs=Cgd=Csb=Cdb=.1*Cox;
80         Tshift = 0;
81
82         for ii=1:length(parameternames)
83           eval([parameternames{ii} "=",...
84                 num2str(parameters(ii)) " ;"])  
85         endfor
86
87         [gm,gd,ids,didT,P,dPdT,dPdvgs,dPdvds] = \
88             nmos(extvar,mu0,Cox,W,L,Vth,rd,Tshift);
89
90         vg   = extvar(1);
91         vs   = extvar(2);
92         vd   = extvar(3);
93         vb   = extvar(4);
94         T    = max(extvar(5),0);
95         
96         if isempty(intvar)
97           intvar = zeros(5,1);
98         endif
99         
100         Qgb  = intvar(1);
101         Qgs  = intvar(2);
102         Qgd  = intvar(3);
103         Qsb  = intvar(4);
104         Qdb  = intvar(5);
105         
106         a11 = a21 = a22 = zeros(5,5);
107         a12 = [ 1  1  1  0  0; \
108                0 -1  0  1  0; \
109                0  0 -1  0  1; \
110                -1  0  0 -1 -1; \
111                0  0  0  0  0];
112
113         a   = [a11 a12; a21 a22];
114
115         b11 = [0        0                0      0     0; \
116                -gm      (gm+gd)         -gd     0 -didT; \
117                gm      -(gm+gd)          gd     0  didT; \
118                0        0                0      0     0; \
119                dPdvgs  -(dPdvgs+dPdvds)  dPdvds 0  dPdT];
120
121         b12 = zeros(5,5);
122
123         b21 = [Cgb  0        0   -Cgb  0; \
124                Cgs -Cgs      0    0    0; \
125                Cgd  0       -Cgd  0    0; \
126                0    Csb      0   -Csb  0; \
127                0    0        Cdb -Cdb  0];
128         b22 = -eye(5);
129
130         b   = [b11 b12; b21 b22];
131         
132         
133         c1 = [0; -ids; ids; 0; P];
134
135         c2 = [Cgb*(vg - vb) - Qgb;\
136               Cgs*(vg - vs) - Qgs;\
137               Cgd*(vg - vd) - Qgd;\
138               Csb*(vs - vb) - Qsb;\
139               Cdb*(vd - vb) - Qdb];
140         
141         c = [c1;c2];
142         
143
144         break;
145
146       case "PMOS"
147         
148         rd   = 1e6;
149         W    = 1;
150         L    = 1;
151         mu0  = 1e-5;
152         Vth  = -.5;
153         Cox  = 1e-9;
154         Cgb=Cox;
155         Cgs=Cgd=Csb=Cdb=.1*Cox;
156         Tshift = 0;
157
158         for ii=1:length(parameternames)
159           eval([parameternames{ii} "=",...
160                 num2str(parameters(ii)) " ;"])  
161         endfor
162
163         [gm,gd,ids,didT,P,dPdT,dPdvgs,dPdvds] = \
164             pmos(extvar,mu0,Cox,W,L,Vth,rd,Tshift);
165
166         
167         vg   = extvar(1);
168         vs   = extvar(2);
169         vd   = extvar(3);
170         vb   = extvar(4);
171         T    = extvar(5);
172
173         if isempty(intvar)
174           intvar = zeros(5,1);
175         endif
176
177         Qgb  = intvar(1);
178         Qgs  = intvar(2);
179         Qgd  = intvar(3);
180         Qsb  = intvar(4);
181         Qdb  = intvar(5);
182         
183         a11 = a21 = a22 = zeros(5,5);
184         a12 = [ 1  1  1  0  0; \
185                0 -1  0  1  0; \
186                0  0 -1  0  1; \
187                -1  0  0 -1 -1; \
188                0  0  0  0  0];
189
190         a   = [a11 a12; a21 a22];
191         
192         b11 = [0        0                0      0     0; \
193                -gm      (gm+gd)         -gd     0 -didT; \
194                gm      -(gm+gd)          gd     0  didT; \
195                0        0                0      0     0; \
196                dPdvgs  -(dPdvgs+dPdvds)  dPdvds 0  dPdT];
197
198         b12 = zeros(5,5);
199
200         b21 = [Cgb  0        0   -Cgb  0; \
201                Cgs -Cgs      0    0    0; \
202                Cgd  0       -Cgd  0    0; \
203                0    Csb      0   -Csb  0; \
204                0    0        Cdb -Cdb  0];
205         
206         b22 = -eye(5);
207
208         b   = [b11 b12; b21 b22];
209         
210         
211         c1 = [0; -ids; ids; 0; P];
212
213         c2 = [Cgb*(vg - vb) - Qgb;\
214               Cgs*(vg - vs) - Qgs;\
215               Cgd*(vg - vd) - Qgd;\
216               Csb*(vs - vb) - Qsb;\
217               Cdb*(vd - vb) - Qdb];
218         
219         c = [c1;c2];
220         
221         break;
222
223       otherwise
224         error(["unknown option:" string]);
225     endswitch
226   endif
227   
228 endfunction
229
230 function [gm,gd,ids,didT,P,dPdT,dPdvgs,dPdvds] = nmos(extvar,mu0,Cox,W,L,Vth,rd,Tshift)
231   ##Computes values for nmos case
232   
233   vg   = extvar(1);
234   vs   = extvar(2);
235   vd   = extvar(3);
236   vb   = extvar(4);
237   T    = max(extvar(5),0);
238
239   k    = mu0*Cox*((T + Tshift)/300)^(-3/2)*W/L;
240   dkdT = mu0*Cox*W*(-3/2)*((T + Tshift)/300)^(-5/2)*(1/300)/L;
241   
242   vgs  = vg-vs;
243   vds  = vd-vs;
244   
245   if (vgs < Vth)
246     
247     gm  = 0;
248     gd  = 1/rd;
249     ids = vds*gd;
250     didT= 0;
251     
252   elseif (((vgs-Vth) >= (vds)) && (vds >= 0))
253     
254     ids = k*((vgs-Vth)*vds-(vds^2)/2)+vds/rd;
255     gm  = k*vds;
256     gd  = k*(vgs-Vth-vds) + 1/rd;
257     didT= dkdT*((vgs-Vth)*vds-(vds^2)/2);
258     
259   elseif (((vgs-Vth) >= (vds)) && (vds < 0))
260     
261     gm  = 0;
262     gd  = 1/rd;
263     ids = vds*gd;
264     didT= 0;
265     
266   else # (i.e. if 0 <= vgs-vth <= vds)
267     
268     ids = (k/2)*(vgs-Vth)^2+vds/rd;
269     gm  = k*(vgs-Vth);
270     gd  = 1/rd;
271     didT= (dkdT/(2))*(vgs-Vth)^2;
272     
273   endif
274   
275   P       = -ids * vds;
276   dPdT    = -didT* vds;
277   dPdvgs  = -(gm*vds);
278   dPdvds  = -(gd*vds + ids);
279
280 endfunction
281
282 function [gm,gd,ids,didT,P,dPdT,dPdvgs,dPdvds] = pmos(extvar,mu0,Cox,W,L,Vth,rd,Tshift)
283   ##Computes values for pmos case
284
285   vg   = extvar(1);
286   vs   = extvar(2);
287   vd   = extvar(3);
288   vb   = extvar(4);
289   T    = extvar(5);
290
291   k    = - mu0 * Cox * ((T + Tshift)/300)^(-3/2) *W/L;
292   dkdT = - mu0 * Cox * W *(-3/2)*((T + Tshift)/300)^(-5/2)*(1/300)/L;
293
294   vgs  = vg-vs;
295   vds  = vd-vs;
296
297   if (vgs > Vth)
298     
299     gm  = 0;
300     gd  = 1/rd;
301     ids = vds*gd;
302     didT= 0;
303
304   elseif (((vgs-Vth) <= (vds)) && (vds <= 0))
305     
306     ids = k*((vgs-Vth)*vds-(vds^2)/2)+vds/rd;
307     gm  = k*vds;
308     gd  = k*(vgs-Vth-vds)+1/rd;
309     didT= dkdT*((vgs-Vth)*vds-(vds^2)/2);
310
311   elseif (((vgs-Vth) <= (vds)) && (vds > 0))
312     
313     gm  = 0;
314     gd  = 1/rd;
315     ids = vds*gd;
316     didT= 0;
317
318   else 
319
320     ids = (k/2)*(vgs-Vth)^2+vds/rd;
321     gm  = k*(vgs-Vth);
322     gd  = 1/rd;
323     didT= (dkdT/(2))*(vgs-Vth)^2;
324
325   endif
326   
327   P    = -ids * vds;
328   dPdT = -didT* vds;
329   dPdvgs  = -(gm*vds);
330   dPdvds  = -(gd*vds + ids);
331   
332 endfunction