-
-
Notifications
You must be signed in to change notification settings - Fork 43
Add NMOS PMOS Transistors #376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jClugstor
wants to merge
11
commits into
SciML:main
Choose a base branch
from
jClugstor:add_NMOS_PMOS
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add the docstring to the docs |
Rebase |
71aa4d4
to
d3621ad
Compare
BenChung
approved these changes
Apr 11, 2025
Rebase |
8cabba3
to
1a4474f
Compare
I can't seem to figure out this error. I think I'm missing an import or something. If I define it on it's own it works fine: using ModelingToolkit, ModelingToolkitStandardLibrary
using OrdinaryDiffEq
using NonlinearSolve
import ModelingToolkitStandardLibrary: Electrical.Pin, Electrical.Voltage, Electrical.Ground, Electrical.Resistor, Electrical.Capacitor, Electrical.NMOS
using ModelingToolkitStandardLibrary.Blocks: Constant
using ModelingToolkit: t_nounits as t, D_nounits as D
@mtkmodel CustomNMOS begin
@variables begin
V_GS(t)
V_DS(t)
V_OV(t)
end
@components begin
d = Pin()
g = Pin()
s = Pin()
b = Pin()
end
@parameters begin
V_tn = 0.8
R_DS = 1e7
lambda = 1 / 25
if !use_transconductance
mu_n
C_ox
W
L
else
k_n = 20e-3
end
end
@structural_parameters begin
use_bulk = false
use_transconductance = true
use_channel_length_modulation = true
end
begin
if !use_transconductance
k_n = mu_n * C_ox * (W / L)
end
end
@equations begin
V_DS ~ ifelse(d.v < s.v, s.v - d.v, d.v - s.v)
V_GS ~ g.v - ifelse(d.v < s.v, d.v, s.v)
V_OV ~ V_GS - V_tn
d.i ~
ifelse(d.v < s.v, -1, 1) * ifelse(V_GS < V_tn,
0 + V_DS / R_DS,
ifelse(V_DS < V_OV,
ifelse(use_channel_length_modulation, k_n * (1 + lambda * V_DS) * (V_OV - V_DS / 2) * V_DS + V_DS / R_DS, k_n * (V_OV - V_DS / 2) * V_DS + V_DS / R_DS),
ifelse(use_channel_length_modulation, ((k_n * V_OV^2) / 2) * (1 + lambda * V_DS) + V_DS / R_DS, (k_n * V_OV^2) / 2 + V_DS / R_DS)
)
)
g.i ~ 0
s.i ~ -d.i
end
end
@mtkmodel Custom_SimpleNMOSCircuit begin
@components begin
Q1 = CustomNMOS(use_channel_length_modulation=false)
Vcc = Voltage()
Vb = Voltage()
ground = Ground()
Vcc_const = Constant(k=V_cc)
Vb_const = Constant(k=V_b)
end
@parameters begin
V_cc = 5.0
V_b = 3.5
end
@equations begin
#voltage sources
connect(Vcc_const.output, Vcc.V)
connect(Vb_const.output, Vb.V)
#ground connections
connect(Vcc.n, Vb.n, ground.g, Q1.s)
#other stuff
connect(Vcc.p, Q1.d)
connect(Vb.p, Q1.g)
end
end
@mtkbuild custom_sys = Custom_SimpleNMOSCircuit(V_cc=5.0, V_b=3.5) but then when I try to use the library version which is the exact same code: # from library
@mtkmodel SimpleNMOSCircuit begin
@components begin
Q1 = NMOS(use_channel_length_modulation=false)
Vcc = Voltage()
Vb = Voltage()
ground = Ground()
Vcc_const = Constant(k=V_cc)
Vb_const = Constant(k=V_b)
end
@parameters begin
V_cc = 5.0
V_b = 3.5
end
@equations begin
#voltage sources
connect(Vcc_const.output, Vcc.V)
connect(Vb_const.output, Vb.V)
#ground connections
connect(Vcc.n, Vb.n, ground.g, Q1.s)
#other stuff
connect(Vcc.p, Q1.d)
connect(Vb.p, Q1.g)
end
end
@mtkbuild custom_sys = SimpleNMOSCircuit(V_cc=5.0, V_b=3.5) I get ERROR: MethodError: no method matching *(::ModelingToolkit.NoValue, ::Num)
The function `*` exists, but no method is defined for this combination of argument types.
Closest candidates are:
*(::Any, ::Any, ::Any, ::Any...)
@ Base operators.jl:596
*(::ChainRulesCore.NoTangent, ::Any)
@ ChainRulesCore ~/.julia/packages/ChainRulesCore/U6wNx/src/tangent_arithmetic.jl:64
*(::Any, ::ChainRulesCore.NoTangent)
@ ChainRulesCore ~/.julia/packages/ChainRulesCore/U6wNx/src/tangent_arithmetic.jl:65
...
Stacktrace:
[1]
@ ModelingToolkitStandardLibrary.Electrical ~/.julia/packages/ModelingToolkit/YLJ0I/src/systems/model_parsing.jl:918
[2] __NMOS__
@ ~/.julia/packages/ModelingToolkit/YLJ0I/src/systems/model_parsing.jl:140 [inlined]
[3] #_#385
@ ~/.julia/packages/ModelingToolkit/YLJ0I/src/systems/model_parsing.jl:25 [inlined]
[4] macro expansion
@ ~/.julia/packages/ModelingToolkit/YLJ0I/src/systems/abstractsystem.jl:1957 [inlined]
[5]
@ Main ~/.julia/packages/ModelingToolkit/YLJ0I/src/systems/model_parsing.jl:140
[6] __SimpleNMOSCircuit__
@ ~/.julia/packages/ModelingToolkit/YLJ0I/src/systems/model_parsing.jl:140 [inlined]
[7] #_#385
@ ~/.julia/packages/ModelingToolkit/YLJ0I/src/systems/model_parsing.jl:25 [inlined]
[8] top-level scope
@ ~/.julia/packages/ModelingToolkit/YLJ0I/src/systems/abstractsystem.jl:1957
Some type information was truncated. Use `show(err)` to see complete types. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Additional context
Add any other context about the problem here.