Skip to content

Commit ab30e8c

Browse files
committed
add MOSFETs
1 parent 3f795b3 commit ab30e8c

File tree

1 file changed

+180
-0
lines changed

1 file changed

+180
-0
lines changed

src/Electrical/Analog/mosfets.jl

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
"""
2+
NMOS(;name, V_tn, R_DS, lambda)
3+
4+
Creates an N-type MOSFET transistor
5+
6+
# Structural Parameters
7+
- `use_transconductance`: If `true` the parameter `k_n` needs to be provided, and is used in the calculation of the current
8+
through the transistor. Otherwise, `mu_n`, `C_ox`, `W`, and `L` need to be provided and are used to calculate the transconductance.
9+
10+
- `use_channel_length_modulation`: If `true` the channel length modulation effect is taken in to account. In essence this gives
11+
the drain-source current has a small dependency on the drains-source voltage in the saturation region of operation.
12+
13+
# Connectors
14+
- `d` Drain Pin
15+
- `g` Gate Pin
16+
- `s` Source Pin
17+
18+
# Parameters
19+
- `mu_n`: Electron mobility
20+
- `C_ox`: Oxide capacitance (F/m^2)
21+
- `W`: Channel width (m)
22+
- `L`: Channel length
23+
- `k_n`: MOSFET transconductance parameter
24+
25+
Based on the MOSFET models in (Sedra, A. S., Smith, K. C., Carusone, T. C., & Gaudet, V. C. (2021). Microelectronic circuits (8th ed.). Oxford University Press.)
26+
"""
27+
@mtkmodel NMOS begin
28+
@variables begin
29+
V_GS(t)
30+
V_DS(t)
31+
V_OV(t)
32+
end
33+
34+
@components begin
35+
d = Pin(), [description = "Drain pin"]
36+
g = Pin(), [description = "Gate pin"]
37+
s = Pin(), [description = "Source pin"]
38+
end
39+
40+
@parameters begin
41+
V_tn = 0.8, [description = "Threshold voltage (V)"]
42+
R_DS = 1e7, [description = "Drain to source resistance (Ω)"]
43+
44+
if use_channel_length_modulation
45+
lambda = 1 / 25, [description = "Channel length modulation coefficient (V^(-1))"]
46+
end
47+
48+
if !use_transconductance
49+
mu_n, [description = "Electron mobility"]
50+
C_ox, [description = "Oxide capacitance (F/m^2)"]
51+
W, [description = "Channel width (m)"]
52+
L, [description = "Channel length (m)"]
53+
else
54+
k_n = 20e-3, [description = "MOSFET transconductance parameter"]
55+
end
56+
end
57+
58+
@structural_parameters begin
59+
use_transconductance = true
60+
use_channel_length_modulation = true
61+
end
62+
63+
begin
64+
if !use_transconductance
65+
k_n = mu_n * C_ox * (W / L)
66+
end
67+
end
68+
69+
@equations begin
70+
V_DS ~ ifelse(d.v < s.v, s.v - d.v, d.v - s.v)
71+
V_GS ~ g.v - ifelse(d.v < s.v, d.v, s.v)
72+
V_OV ~ V_GS - V_tn
73+
74+
d.i ~ ifelse(d.v < s.v, -1, 1) * ifelse(V_GS < V_tn,
75+
0 + V_DS / R_DS,
76+
ifelse(V_DS < V_OV,
77+
ifelse(use_channel_length_modulation,
78+
k_n * (1 + lambda * V_DS) * (V_OV - V_DS / 2) * V_DS + V_DS / R_DS,
79+
k_n * (V_OV - V_DS / 2) * V_DS + V_DS / R_DS),
80+
ifelse(use_channel_length_modulation,
81+
((k_n * V_OV^2) / 2) * (1 + lambda * V_DS) + V_DS / R_DS,
82+
(k_n * V_OV^2) / 2 + V_DS / R_DS)
83+
)
84+
)
85+
86+
g.i ~ 0
87+
s.i ~ -d.i
88+
end
89+
end
90+
91+
92+
93+
"""
94+
PMOS(;name, V_tp, R_DS, lambda)
95+
96+
Creates an N-type MOSFET transistor
97+
98+
# Structural Parameters
99+
- `use_transconductance`: If `true` the parameter `k_p` needs to be provided, and is used in the calculation of the current
100+
through the transistor. Otherwise, `mu_n`, `C_ox`, `W`, and `L` need to be provided and are used to calculate the transconductance.
101+
102+
- `use_channel_length_modulation`: If `true` the channel length modulation effect is taken in to account. In essence this gives
103+
the drain-source current has a small dependency on the drains-source voltage in the saturation region of operation.
104+
105+
# Connectors
106+
- `d` Drain Pin
107+
- `g` Gate Pin
108+
- `s` Source Pin
109+
110+
# Parameters
111+
- `mu_p`: Electron mobility
112+
- `C_ox`: Oxide capacitance (F/m^2)
113+
- `W`: Channel width (m)
114+
- `L`: Channel length
115+
- `k_p`: MOSFET transconductance parameter
116+
117+
Based on the MOSFET models in (Sedra, A. S., Smith, K. C., Carusone, T. C., & Gaudet, V. C. (2021). Microelectronic circuits (8th ed.). Oxford University Press.)
118+
"""
119+
@mtkmodel PMOS begin
120+
@variables begin
121+
V_GS(t)
122+
V_DS(t)
123+
end
124+
125+
@components begin
126+
d = Pin(), [description = "Drain pin"]
127+
g = Pin(), [description = "Gate pin"]
128+
s = Pin(), [description = "Source pin"]
129+
end
130+
131+
@parameters begin
132+
V_tp = -1.5, [description = "Threshold voltage (V)"]
133+
R_DS = 1e7, [description = "Drain-source resistance (Ω)"]
134+
135+
if use_channel_length_modulation
136+
lambda = 1 / 25, [description = "Channel length modulation coefficient (V^(-1))"]
137+
end
138+
139+
if !use_transconductance
140+
mu_p, [description = "Hole mobility"]
141+
C_ox, [description = "Oxide capacitance (F/m^2)"]
142+
W, [description = "Channel width (m)"]
143+
L, [description = "Channel length (m)"]
144+
else
145+
k_p = 20e-3
146+
end
147+
end
148+
149+
@structural_parameters begin
150+
use_transconductance = true
151+
use_channel_length_modulation = true
152+
end
153+
154+
begin
155+
if !use_transconductance
156+
k_p = mu_p * C_ox * (W / L)
157+
end
158+
end
159+
160+
@equations begin
161+
V_DS ~ ifelse(d.v > s.v, s.v - d.v, d.v - s.v)
162+
V_GS ~ g.v - ifelse(d.v > s.v, d.v, s.v)
163+
164+
d.i ~ -ifelse(d.v > s.v, -1.0, 1.0) * ifelse(V_GS > V_tp,
165+
0.0 + V_DS / R_DS,
166+
ifelse(V_DS > (V_GS - V_tp),
167+
ifelse(use_channel_length_modulation,
168+
k_p * (1 + lambda * V_DS) * ((V_GS - V_tp) - V_DS / 2) * V_DS +
169+
V_DS / R_DS,
170+
k_p * ((V_GS - V_tp) - V_DS / 2) * V_DS + V_DS / R_DS),
171+
ifelse(use_channel_length_modulation,
172+
((k_p * (V_GS - V_tp)^2) / 2) * (1 + lambda * V_DS) + V_DS / R_DS,
173+
(k_p * (V_GS - V_tp)^2) / 2 + V_DS / R_DS)
174+
)
175+
)
176+
177+
g.i ~ 0
178+
s.i ~ -d.i
179+
end
180+
end

0 commit comments

Comments
 (0)