Skip to content

Commit 9758187

Browse files
Merge pull request #353 from jClugstor/add_NPN
Add NPN and PNP BJT transistor models
2 parents 3021900 + 92ef325 commit 9758187

File tree

4 files changed

+508
-0
lines changed

4 files changed

+508
-0
lines changed

docs/src/API/electrical.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ IdealOpAmp
3434
Diode
3535
HeatingDiode
3636
VariableResistor
37+
PNP
38+
NPN
3739
```
3840

3941
## Analog Sensors
Lines changed: 332 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,332 @@
1+
"""
2+
NPN(;name, B_F, B_R, Is, V_T, V_A, phi_C, phi_E, Z_C, Z_E, Tau_f, Tau_r, C_jC0, C_jE0, C_CS, gamma_C, gamma_E, NF, NR)
3+
4+
Creates an NPN Bipolar Junction Transistor following a modified Ebers-Moll model. Includes an optional substrate pin and optional
5+
Early voltage effect.
6+
7+
# Structural Parameters
8+
- `use_substrate`: If `true`, a substrate pin connector is available. If `false` it is
9+
assumed the substrate is connected to the collector pin.
10+
11+
- `use_Early`: If `true`, the Early effect is modeled, which takes in to account the effect
12+
collector-base voltage variations have on the collector-base depletion region. In many cases this
13+
effectively means that the collector current has a dependency on the collector-emitter voltage.
14+
15+
- `use_advanced_continuation`: When false, the `C_jC` and `C_jE` non-linear capacitance curves use
16+
a simplified linear continuation starting when `V_BC` and `V_BE` are 0, respectively. If `true`, the `Z_C` and `Z_E` parameters
17+
are used to start the linear continuation at `Phi_C - Z_C` and `Phi_E - Z_E`.
18+
19+
# Connectors
20+
- `b` Base Pin
21+
- `c` Collector Pin
22+
- `e` Emitter Pin
23+
- `s` Substrate Pin, only available when `use_substrate = true`
24+
25+
# Parameters
26+
- `B_F`: Forward beta
27+
- `B_R`: Reverse beta
28+
- `Is`: Saturation current
29+
- `V_T`: Thermal voltage at 300K
30+
- `V_A`: Inverse Early voltage
31+
- `phi_C`: Collector junction exponent
32+
- `phi_E`: Emitter junction exponent
33+
- `Z_C`: Collector junction offset
34+
- `Z_E`: Emitter junction offset
35+
- `Tau_f`: Forward transit time
36+
- `Tau_r`: Reverse transit time
37+
- `C_jC0`: Collector junction capacitance coefficient
38+
- `C_jE0`: Emitter junction capacitance coefficient
39+
- `C_CS`: Collector-substrate capacitance
40+
- `gamma_C`: Collector junction exponent
41+
- `gamma_E`: Emitter junction exponent
42+
- `NF`: Forward emission coefficient
43+
- `NR`: Reverse emission coefficient
44+
"""
45+
@mtkmodel NPN begin
46+
@variables begin
47+
V_BE(t)
48+
V_BC(t)
49+
ICC(t)
50+
IEC(t)
51+
52+
C_jC(t)
53+
C_jE(t)
54+
C_DC(t)
55+
C_DE(t)
56+
57+
I_sub(t)
58+
V_sub(t)
59+
V_CS(t)
60+
end
61+
62+
@structural_parameters begin
63+
use_substrate = false
64+
use_Early = true
65+
use_advanced_continuation = false
66+
end
67+
68+
@components begin
69+
b = Pin()
70+
e = Pin()
71+
c = Pin()
72+
73+
if use_substrate
74+
s = Pin()
75+
end
76+
end
77+
78+
@parameters begin
79+
B_F = 50.0, [description = "Forward beta"]
80+
B_R = 0.1, [description = "Reverse beta"]
81+
Is = 1e-16, [description = "Saturation current"]
82+
V_T = 0.026, [description = "Thermal voltage at 300K"]
83+
84+
if use_Early
85+
V_A = 0.02, [description = "Inverse Early voltage"]
86+
end
87+
88+
phi_C = 0.8, [description = "Collector junction scaling factor"]
89+
phi_E = 0.6, [description = "Emitter junction scaling factor"]
90+
91+
if use_advanced_continuation
92+
Z_C = 0.1, [description = "Collector junction offset"]
93+
Z_E = 0.1, [description = "Emitter junction offset"]
94+
end
95+
96+
Tau_f = 0.12e-9, [description = "Forward transit time"]
97+
Tau_r = 5e-9, [description = "Reverse transit time"]
98+
99+
C_jC0 = 0.5e-12, [description = "Collector-junction capacitance coefficient"]
100+
C_jE0 = 0.4e-12, [description = "Emitter-junction capacitance coefficient"]
101+
102+
C_CS = 1e-12, [description = "Collector-substrate capacitance"]
103+
104+
gamma_C = 0.5, [description = "Collector junction exponent"]
105+
gamma_E = 1.0 / 3.0, [description = "Emitter junction exponent"]
106+
107+
NF = 1.0, [description = "Forward ideality exponent"]
108+
NR = 1.0, [description = "Reverse ideality exponent"]
109+
end
110+
111+
@equations begin
112+
V_BE ~ b.v - e.v
113+
V_BC ~ b.v - c.v
114+
115+
ICC ~ Is * (exp(V_BE / V_T) - 1)
116+
IEC ~ Is * (exp(V_BC / V_T) - 1)
117+
118+
if !use_advanced_continuation
119+
C_jC ~ ifelse(V_BC / phi_C > 0.0, 1 + gamma_C * V_BC / phi_C,
120+
(C_jC0) / (1 - V_BC / phi_C)^gamma_C)
121+
C_jE ~ ifelse(V_BE / phi_E > 0.0, 1 + gamma_E * V_BE / phi_E,
122+
(C_jE0) / (1 - V_BE / phi_E)^gamma_E)
123+
end
124+
125+
if use_advanced_continuation
126+
C_jC ~ if V_BC > phi_C - Z_C
127+
((C_jC0 * gamma_C * (1 - ((phi_C - Z_C) / phi_C))^(-gamma_C - 1)) / phi_C) *
128+
V_BC -
129+
((C_jC0 * gamma_C * (1 - ((phi_C - Z_C) / phi_C))^(-gamma_C - 1)) / phi_C) *
130+
(phi_C - Z_C) + (C_jC0) / (1 - (phi_C - Z_C) / phi_C)^gamma_C
131+
else
132+
(C_jC0) / (1 - V_BC / phi_C)^gamma_C
133+
end
134+
135+
C_jE ~ if V_BE > phi_E - Z_E
136+
((C_jE0 * gamma_E * (1 - ((phi_E - Z_E) / phi_E))^(-gamma_E - 1)) / phi_E) *
137+
V_BE -
138+
((C_jE0 * gamma_E * (1 - ((phi_E - Z_E) / phi_E))^(-gamma_E - 1)) / phi_E) *
139+
(phi_E - Z_E) + (C_jE0) / (1 - (phi_E - Z_E) / phi_E)^gamma_E
140+
else
141+
(C_jE0) / (1 - V_BE / phi_E)^gamma_E
142+
end
143+
end
144+
145+
C_DE ~ Tau_f * (Is / (NF * V_T)) * exp(V_BE / (NF * V_T))
146+
C_DC ~ Tau_r * (Is / (NR * V_T)) * exp(V_BC / (NR * V_T))
147+
148+
if use_substrate
149+
s.i ~ I_sub
150+
s.v ~ V_sub
151+
V_CS ~ c.v - V_sub
152+
end
153+
154+
if !use_substrate
155+
V_sub ~ c.v
156+
end
157+
158+
I_sub ~ ifelse(use_substrate, -C_CS * D(V_CS), -C_CS * D(V_sub))
159+
160+
c.i ~ (ICC - IEC) * ifelse(use_Early, (1 - V_BC * V_A), 1.0) - IEC / B_R -
161+
(C_jC + C_DC) * D(V_BC) - I_sub
162+
b.i ~ IEC / B_R + ICC / B_F + (C_jC + C_DC) * D(V_BC) + (C_jE + C_DE) * D(V_BE)
163+
e.i ~ -c.i - b.i - I_sub
164+
end
165+
end
166+
167+
168+
"""
169+
PNP(;name, B_F, B_R, Is, V_T, V_A, phi_C, phi_E, Z_C, Z_E, Tau_f, Tau_r, C_jC0, C_jE0, C_CS, gamma_C, gamma_E, NF, NR)
170+
171+
Creates a PNP Bipolar Junction Transistor following a modified Ebers-Moll model. Includes an optional substrate pin and optional
172+
Early voltage effect.
173+
174+
# Structural Parameters
175+
- `use_substrate`: If `true`, a substrate pin connector is available. If `false` it is
176+
assumed the substrate is connected to the collector pin.
177+
178+
- `use_Early`: If `true`, the Early effect is modeled, which takes in to account the effect
179+
collector-base voltage variations have on the collector-base depletion region. In many cases this
180+
effectively means that the collector current has a dependency on the collector-emitter voltage.
181+
182+
- `use_advanced_continuation`: When false, the `C_jC` and `C_jE` non-linear capacitance curves use
183+
a simplified linear continuation starting when `V_CB` and `V_EB` are 0, respectively. If `true`, the `Z_C` and `Z_E` parameters
184+
are used to start the linear continuation at `Phi_C - Z_C` and `Phi_E - Z_E`.
185+
186+
# Connectors
187+
- `b` Base Pin
188+
- `c` Collector Pin
189+
- `e` Emitter Pin
190+
- `s` Substrate Pin, only available when `use_substrate = true`
191+
192+
# Parameters
193+
- `B_F`: Forward beta
194+
- `B_R`: Reverse beta
195+
- `Is`: Saturation current
196+
- `V_T`: Thermal voltage at 300K
197+
- `V_A`: Inverse Early voltage
198+
- `phi_C`: Collector junction exponent
199+
- `phi_E`: Emitter junction exponent
200+
- `Z_C`: Collector junction offset
201+
- `Z_E`: Emitter junction offset
202+
- `Tau_f`: Forward transit time
203+
- `Tau_r`: Reverse transit time
204+
- `C_jC0`: Collector junction capacitance coefficient
205+
- `C_jE0`: Emitter junction capacitance coefficient
206+
- `C_CS`: Collector-substrate capacitance
207+
- `gamma_C`: Collector junction exponent
208+
- `gamma_E`: Emitter junction exponent
209+
- `NF`: Forward emission coefficient
210+
- `NR`: Reverse emission coefficient
211+
"""
212+
@mtkmodel PNP begin
213+
@variables begin
214+
V_EB(t)
215+
V_CB(t)
216+
ICC(t)
217+
IEC(t)
218+
219+
C_jC(t)
220+
C_jE(t)
221+
C_DC(t)
222+
C_DE(t)
223+
224+
I_sub(t)
225+
V_sub(t)
226+
V_CS(t)
227+
end
228+
229+
@structural_parameters begin
230+
use_substrate = false
231+
use_Early = true
232+
use_advanced_continuation = false
233+
end
234+
235+
@components begin
236+
b = Pin()
237+
e = Pin()
238+
c = Pin()
239+
240+
if use_substrate
241+
s = Pin()
242+
end
243+
end
244+
245+
@parameters begin
246+
B_F = 50.0, [description = "Forward beta"]
247+
B_R = 0.1, [description = "Reverse beta"]
248+
Is = 1e-16, [description = "Saturation current"]
249+
V_T = 0.026, [description = "Thermal voltage at 300K"]
250+
251+
if use_Early
252+
V_A = 0.02, [description = "Inverse Early voltage"]
253+
end
254+
255+
phi_C = 0.8, [description = "Collector junction scaling factor"]
256+
phi_E = 0.6, [description = "Emitter junction scaling factor"]
257+
258+
if use_advanced_continuation
259+
Z_C = 0.1, [description = "Collector junction offset"]
260+
Z_E = 0.1, [description = "Emitter junction offset"]
261+
end
262+
263+
Tau_f = 0.12e-9, [description = "Forward transit time"]
264+
Tau_r = 5e-9, [description = "Reverse transit time"]
265+
266+
C_jC0 = 0.5e-12, [description = "Collector-junction capacitance coefficient"]
267+
C_jE0 = 0.4e-12, [description = "Emitter-junction capacitance coefficient"]
268+
269+
C_CS = 1e-12, [description = "Collector-substrate capacitance"]
270+
271+
gamma_C = 0.5, [description = "Collector junction exponent"]
272+
gamma_E = 1.0 / 3.0, [description = "Emitter junction exponent"]
273+
274+
NF = 1.0, [description = "Forward ideality exponent"]
275+
NR = 1.0, [description = "Reverse ideality exponent"]
276+
end
277+
278+
@equations begin
279+
V_EB ~ e.v - b.v
280+
V_CB ~ c.v - b.v
281+
282+
ICC ~ Is * (exp(V_EB / V_T) - 1)
283+
IEC ~ Is * (exp(V_CB / V_T) - 1)
284+
285+
if !use_advanced_continuation
286+
C_jC ~ ifelse(V_CB / phi_C > 0.0, 1 + gamma_C * V_CB / phi_C,
287+
(C_jC0) / (1 - V_CB / phi_C)^gamma_C)
288+
C_jE ~ ifelse(V_EB / phi_E > 0.0, 1 + gamma_E * V_EB / phi_E,
289+
(C_jE0) / (1 - V_EB / phi_E)^gamma_E)
290+
end
291+
292+
if use_advanced_continuation
293+
C_jC ~ if V_CB > phi_C - Z_C
294+
((C_jC0 * gamma_C * (1 - ((phi_C - Z_C) / phi_C))^(-gamma_C - 1)) / phi_C) *
295+
V_CB -
296+
((C_jC0 * gamma_C * (1 - ((phi_C - Z_C) / phi_C))^(-gamma_C - 1)) / phi_C) *
297+
(phi_C - Z_C) + (C_jC0) / (1 - (phi_C - Z_C) / phi_C)^gamma_C
298+
else
299+
(C_jC0) / (1 - V_CB / phi_C)^gamma_C
300+
end
301+
302+
C_jE ~ if V_EB > phi_E - Z_E
303+
((C_jE0 * gamma_E * (1 - ((phi_E - Z_E) / phi_E))^(-gamma_E - 1)) / phi_E) *
304+
V_BE -
305+
((C_jE0 * gamma_E * (1 - ((phi_E - Z_E) / phi_E))^(-gamma_E - 1)) / phi_E) *
306+
(phi_E - Z_E) + (C_jE0) / (1 - (phi_E - Z_E) / phi_E)^gamma_E
307+
else
308+
(C_jE0) / (1 - V_BE / phi_E)^gamma_E
309+
end
310+
end
311+
312+
C_DE ~ Tau_f * (Is / (NF * V_T)) * exp(V_EB / (NF * V_T))
313+
C_DC ~ Tau_r * (Is / (NR * V_T)) * exp(V_CB / (NR * V_T))
314+
315+
if use_substrate
316+
s.i ~ I_sub
317+
s.v ~ V_sub
318+
V_CS ~ c.v - V_sub
319+
end
320+
321+
if !use_substrate
322+
V_sub ~ c.v
323+
end
324+
325+
I_sub ~ ifelse(use_substrate, -C_CS * D(V_CS), -C_CS * D(V_sub))
326+
327+
c.i ~ IEC / B_R - (ICC - IEC) * ifelse(use_Early, (1 - V_CB * V_A), 1.0) +
328+
(C_jC + C_DC) * D(V_CB) - I_sub
329+
b.i ~ -IEC / B_R - ICC / B_F - (C_jC + C_DC) * D(V_CB) - (C_jE + C_DE) * D(V_EB)
330+
e.i ~ -c.i - b.i - I_sub
331+
end
332+
end

src/Electrical/Electrical.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ include("Analog/sensors.jl")
2424
export Voltage, Current
2525
include("Analog/sources.jl")
2626

27+
export NPN, PNP
28+
include("Analog/transistors.jl")
29+
2730
# include("Digital/gates.jl")
2831
# include("Digital/sources.jl")
2932

0 commit comments

Comments
 (0)