Open
Description
While fiddling with Modia, I tried to implement a basic NPN BJT model referring to the MATLAB code from (https://gist.github.com/bencholmes/d3ce40d1e9450f692320f68fd0a239f7) like this
BJT_NPN = Model(
b = Pin,
c = Pin,
e = Pin,
Ids = 1.e-6u"A",
Vt = 0.04u"V",
gainForward = 300.0,
gainReverse = 120.0,
equations = :[
alphaR = (gainReverse + 1)/gainReverse
Vbe = b.v - e.v
Vbc = b.v - c.v
If = Ids*(exp(Vbe/Vt) - 1)
Ir = Ids*(exp(Vbc/Vt) - 1)
c.i = If - Ir*alphaR
b.i = If/gainForward + Ir/gainReverse
e.i = c.i + b.i
]
)
Using it like this:
CommonEmitter= Model(
Vbb = ConstantVoltage | Map(V=5.0u"V"),
Vcc = ConstantVoltage | Map(V=15.0u"V"),
RC = Resistor | Map(R=10e3u"Ω"),
RB = Resistor | Map(R= 1e3u"Ω"),
X = BJT_NPN,
ground = Ground,
connect = :[
(Vcc.p, RC.p)
(Vbb.p, RB.p)
(X.c, RC.n)
(X.b, RB.n)
(ground.p, Vcc.n, Vbb.n, X.e)
]
)
commonEmitter1 = @instantiateModel(CommonEmitter)
simulate!(commonEmitter1, stopTime = 1.0u"s")
plot(commonEmitter1, [("X.b.v", "X.c.v", "X.e.v"]), ("X.b.i", "X.c.i", "X.e.i")], figure=1)
gives the following message
Information message from getSortedAndSolvedAST for model CommonEmitter:
The following variables are iteration variables but have no start/init values defined.
If units are used in the model, start/init values with correct units should be defined
to avoid unit errors during compilation.
Involved variables:
X.Vbe
RC.n.v
ERROR: LoadError: DimensionError: 0.0 and 0.0 V are not dimensionally compatible.
Stacktrace:
[1] +(x::Quantity{Float64, NoDims, Unitful.FreeUnits{(), NoDims, nothing}}, y::Quantity{Float64, 𝐋^2 𝐌 𝐈^-1 𝐓^-3, Unitful.FreeUnits{(V,), 𝐋^2 𝐌 𝐈^-
1 𝐓^-3, nothing}} )
Some help pointing in the right direction would be very helpful.
Metadata
Metadata
Assignees
Labels
No labels