HeatingNPN

model HeatingNPN "Simple NPN BJT according to Ebers-Moll with heating port"
    parameter Real Bf = 50 "Forward beta";
    parameter Real Br = 0.1 "Reverse beta";
    parameter SI.Current Is = 1e-16 "Transport saturation current";
    parameter SI.InversePotential Vak = 0.02 "Early voltage (inverse), 1/Volt";
    parameter SI.Time Tauf = 1.2e-10 "Ideal forward transit time";
    parameter SI.Time Taur = 5e-9 "Ideal reverse transit time";
    parameter SI.Capacitance Ccs = 1e-12 "Collector-substrate(ground) cap.";
    parameter SI.Capacitance Cje = 4e-13 "Base-emitter zero bias depletion cap.";
    parameter SI.Capacitance Cjc = 5e-13 "Base-coll. zero bias depletion cap.";
    parameter SI.Voltage Phie = 0.8 "Base-emitter diffusion voltage";
    parameter Real Me = 0.4 "Base-emitter gradation exponent";
    parameter SI.Voltage Phic = 0.8 "Base-collector diffusion voltage";
    parameter Real Mc = 0.333 "Base-collector gradation exponent";
    parameter SI.Conductance Gbc = 1e-15 "Base-collector conductance";
    parameter SI.Conductance Gbe = 1e-15 "Base-emitter conductance";
    parameter Real EMin = -100 "if x < EMin, the exp(x) function is linearized";
    parameter Real EMax = 40 "if x > EMax, the exp(x) function is linearized";
    parameter SI.Temperature Tnom = 300.15 "Parameter measurement temperature";
    parameter Real XTI = 3 "Temperature exponent for effect on Is";
    parameter Real XTB = 0 "Forward and reverse beta temperature exponent";
    parameter SI.Voltage EG = 1.11 "Energy gap for temperature effect on Is";
    parameter Real NF = 1 "Forward current emission coefficient";
    parameter Real NR = 1 "Reverse current emission coefficient";

    extends Modelica.Electrical.Analog.Interfaces.ConditionalHeatPort(useHeatPort = true);

    SI.Voltage vbc "Base-collector voltage";
    SI.Voltage vbe "Base-emitter voltage";
    Real qbk "Relative majority carrier charge, inverse";
    SI.Current ibc "Base-collector diode current";
    SI.Current ibe "Base-emitter diode current";
    SI.Capacitance cbc "Total base-collector capacitance";
    SI.Capacitance cbe "Total base-emitter capacitance";
    SI.Capacitance Capcje "Effective base-emitter depletion capacitance";
    SI.Capacitance Capcjc "Effective base-collector depletion capacitance";
    SI.Current is_t "Temperature dependent transport saturation current";
    Real br_t "Temperature dependent forward beta";
    Real bf_t "Temperature dependent reverse beta";
    SI.Voltage vt_t "Voltage equivalent of effective temperature";
    Real hexp "Auxiliary quantity temperature dependent exponent";
    Real htempexp "Auxiliary quantity exp(hexp)";
    Modelica.Electrical.Analog.Interfaces.Pin C "Collector"
        annotation (Placement(
            transformation(extent = {
                {90, 50}, 
                {110, 70}}),
            iconTransformation(extent = {
                {90, 50}, 
                {110, 70}})));
    Modelica.Electrical.Analog.Interfaces.Pin B "Base"
        annotation (Placement(transformation(extent = {
            {-90, -10}, 
            {-110, 10}})));
    Modelica.Electrical.Analog.Interfaces.Pin E "Emitter"
        annotation (Placement(
            transformation(extent = {
                {90, -50}, 
                {110, -70}}),
            iconTransformation(extent = {
                {90, -50}, 
                {110, -70}})));
equation
    assert(0 < T_heatPort, "Temperature must be positive");
    Capcjc = smooth(1, Cjc * powlin(vbc / Phic, Mc));
    Capcje = smooth(1, Cje * powlin(vbe / Phie, Me));
    LossPower = vbc * ibc / br_t + vbe * ibe / bf_t + (ibe - ibc) * qbk * (C.v - E.v);
    bf_t = Bf * pow(T_heatPort / Tnom, XTB);
    br_t = Br * pow(T_heatPort / Tnom, XTB);
    cbc = smooth(1, Taur * is_t / (NR * vt_t) * exlin2(vbc / (NR * vt_t), EMin, EMax) + Capcjc);
    cbe = smooth(1, Tauf * is_t / (NF * vt_t) * exlin2(vbe / (NF * vt_t), EMin, EMax) + Capcje);
    hexp = (T_heatPort / Tnom - 1) * EG / vt_t;
    htempexp = smooth(1, exlin2(hexp, EMin, EMax));
    ibc = smooth(1, is_t * (exlin2(vbc / (NR * vt_t), EMin, EMax) - 1) + vbc * Gbc);
    ibe = smooth(1, is_t * (exlin2(vbe / (NF * vt_t), EMin, EMax) - 1) + vbe * Gbe);
    is_t = Is * pow(T_heatPort / Tnom, XTI) * htempexp;
    qbk = 1 - vbc * Vak;
    vbc = B.v - C.v;
    vbe = B.v - E.v;
    vt_t = k / q * T_heatPort;
    B.i = ibe / bf_t + ibc / br_t + cbc * der(vbc) + cbe * der(vbe);
    C.i = (ibe - ibc) * qbk - ibc / br_t - cbc * der(vbc) + Ccs * der(C.v);
    E.i = -B.i - C.i + Ccs * der(C.v);

    annotation (
        defaultComponentName = "npn",
        Documentation(
            info = "<html>\n<p>This model is a simple model of a bipolar NPN junction transistor according to Ebers-Moll.\n<br>A heating port is added for thermal electric simulation. The heating port is defined in the Modelica.Thermal library.\n<br>A typical parameter set is (the parameter Vt is no longer used):</p>\n<pre>  Bf  Br  Is     Vak  Tauf    Taur  Ccs   Cje     Cjc     Phie  Me   PHic   Mc     Gbc    Gbe\n  -   -   A      V    s       s     F     F       F       V     -    V      -      mS     mS\n  50  0.1 1e-16  0.02 0.12e-9 5e-9  1e-12 0.4e-12 0.5e-12 0.8   0.4  0.8    0.333  1e-15  1e-15</pre>\n<p><strong>References:</strong></p>\n<p>Vlach, J.; Singal, K.: Computer methods for circuit analysis and design. Van Nostrand Reinhold, New York 1983 on page 317 ff.</p>\n</html>",
            revisions = "<html>\n<ul>\n<li><em> March 11, 2009   </em>\n       by Christoph Clauss<br> conditional heat port added<br>\n       </li>\n<li><em>March 20, 2004   </em>\n       by Christoph Clauss<br> implemented<br>\n       </li>\n</ul>\n</html>"),
        Icon(
            coordinateSystem(
                preserveAspectRatio = true,
                extent = {
                    {-100, -100}, 
                    {100, 100}}),
            graphics = {
                Line(
                    points = {
                        {-20, 40}, 
                        {-20, -40}},
                    color = {0, 0, 255}), 
                Line(
                    points = {
                        {-20, 0}, 
                        {-100, 0}},
                    color = {0, 0, 255}), 
                Line(
                    points = {
                        {91, 60}, 
                        {30, 60}},
                    color = {0, 0, 255}), 
                Line(
                    points = {
                        {30, 60}, 
                        {-20, 10}},
                    color = {0, 0, 255}), 
                Line(
                    points = {
                        {-20, -10}, 
                        {30, -60}},
                    color = {0, 0, 255}), 
                Line(
                    points = {
                        {30, -60}, 
                        {91, -60}},
                    color = {0, 0, 255}), 
                Polygon(
                    points = {
                        {30, -60}, 
                        {24, -46}, 
                        {16, -54}, 
                        {30, -60}},
                    fillColor = {0, 0, 255},
                    fillPattern = FillPattern.Solid,
                    lineColor = {0, 0, 255}), 
                Text(
                    extent = {
                        {-150, 130}, 
                        {150, 90}},
                    textString = "%name",
                    lineColor = {0, 0, 255})}));
end HeatingNPN;