]> Creatis software - CreaPhase.git/blob - octave_packages/ocs-0.1.3/sbn/Mpmosfet.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / ocs-0.1.3 / sbn / Mpmosfet.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}]=} Mpmosfet(@var{string},@var{parameters},@
25 ## @var{parameternames},@var{extvar},@var{intvar},@var{t})
26 ##
27 ## SBN file implementing standard models for p-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]= Mpmosfet (string,parameters,parameternames,extvar,intvar,t) 
59   
60   switch string
61     case "simple"
62       
63       rd = 1e6;
64       
65       for ii=1:length(parameternames)
66         eval([parameternames{ii} "=",...
67               num2str(parameters(ii)) " ;"]);
68       endfor
69
70       vg   = extvar(1);
71       vs   = extvar(2);
72       vd   = extvar(3);
73       vb   = extvar(4);
74
75       vgs  = vg-vs;
76       vds  = vd-vs;
77       
78       if (vgs > Vth)
79
80         gm = 0;
81         gd = 1/rd;
82         id = vds*gd;
83         
84       elseif (((vgs-Vth) <= (vds)) && (vds<=0))
85         
86         id = k*((vgs-Vth)*vds-(vds^2)/2)+vds/rd;
87         gm = k*vds;
88         gd = k*(vgs-Vth-vds)+1/rd;
89         
90       elseif (((vgs-Vth) <= (vds)) && (vds>0))
91         
92         gm = 0;
93         gd = 1/rd;
94         id = vds*gd;
95         
96       else
97
98         id = k*(vgs-Vth)^2/2+vds/rd;
99         gm = k*(vgs-Vth);
100         gd = 1/rd;
101         
102       endif
103       a = zeros(4);
104       
105       b = [0    0       0  0;
106            -gm  (gm+gd) -gd  0; 
107            gm -(gm+gd)  gd  0;
108            0    0       0   0 ];
109       
110       c =[0 -id id 0]';
111       break;
112
113     case "lincap"
114       
115       ## Default parameter values
116       if isempty(intvar)
117         intvar = zeros(5,1);
118       endif
119       Rs = 1e2; Rd = 1e2; Cs = 1e-15; 
120       Cd = 1e-15; Cb = 1e-12;
121       rd = inf; k = -1e-3; Vth = -.1; 
122
123       ## parameters given in input
124       
125       for ii=1:length(parameternames)
126         eval([parameternames{ii} "=",...
127               num2str(parameters(ii)) " ;"])    
128       endfor
129       
130       
131       mtdpmos   = file_in_path(path,"Mtdpmos.cir");
132       mtdpmos(end-3:end)=[];
133       tmpstruct = prs_iff(mtdpmos);
134       
135
136       tmpstruct.NLC.pvmatrix    = [k Vth rd];
137       tmpstruct.LCR(1).pvmatrix = [Rs; Rd];
138       tmpstruct.LCR(2).pvmatrix = [Cs; Cd; Cb];
139       
140       [A0,B,C]     = asm_initialize_system(tmpstruct,[extvar;intvar]);
141       [A1,Jac,res] = asm_build_system(tmpstruct,[extvar;intvar],t);
142       
143       a = A0+A1;
144       b = B+Jac;
145       c = res + B*[extvar;intvar] + C;
146
147       break;
148
149     otherwise
150       error(["unknown option:" string]);
151   endswitch
152
153 endfunction