예제 #1
0
        private DiodeModel CreateDiodeModel(string name, string parameters)
        {
            var dm = new DiodeModel(name);

            ApplyParameters(dm, parameters);
            return(dm);
        }
예제 #2
0
        public DiodeElm(Point p1, Point p2, int f, StringTokenizer st) : base(p1, p2, f)
        {
            const double defaultdrop = 0.805904783;

            mDiode = new Diode(mCir);
            double fwdrop   = defaultdrop;
            double zvoltage = 0;

            try {
                ReferenceName = st.nextToken();
            } catch { }
            if (0 != (f & FLAG_MODEL))
            {
                try {
                    mModelName = CustomLogicModel.unescape(st.nextToken());
                } catch { }
            }
            else
            {
                if (0 != (f & FLAG_FWDROP))
                {
                    try {
                        fwdrop = st.nextTokenDouble();
                    } catch { }
                }
                mModel     = DiodeModel.GetModelWithParameters(fwdrop, zvoltage);
                mModelName = mModel.Name;
            }
            setup();
        }
예제 #3
0
 public override ElementInfo GetElementInfo(int n)
 {
     if (n == 0)
     {
         var ei = new ElementInfo("名前", 0, 0, 0);
         ei.Text = ReferenceName;
         return(ei);
     }
     if (!mCustomModelUI && n == 1)
     {
         var ei = new ElementInfo("モデル", 0, -1, -1);
         mModels   = DiodeModel.GetModelList(this is ZenerElm);
         ei.Choice = new ComboBox();
         for (int i = 0; i != mModels.Count; i++)
         {
             var dm = mModels[i];
             ei.Choice.Items.Add(dm.GetDescription());
             if (dm == mModel)
             {
                 ei.Choice.SelectedIndex = i;
             }
         }
         return(ei);
     }
     return(base.GetElementInfo(n));
 }
예제 #4
0
        private DiodeModel CreateDiodeModel(string name, string parameters)
        {
            var model = new DiodeModel(name);

            ApplyParameters(model, parameters);
            return(model);
        }
예제 #5
0
        public void When_GetPropertyOP_Expect_Reference()
        {
            // https://github.com/SpiceSharp/SpiceSharp/issues/169
            var dModel = new DiodeModel("test");
            var ckt    = new Circuit(
                new VoltageSource("V1", "a", "0", 0),
                new Resistor("R1", "b", "0", 1000),
                new Diode("LED", "a", "b", "test"),
                dModel
                );

            var dc = new DC("DC", "V1", -3.0, 3.0, 0.1);

            var voltageExport = new RealPropertyExport(dc, "LED", "v");

            dc.ExportSimulationData += (sender, args) =>
            {
                var voltage  = voltageExport.Value;
                var voltage2 = args.GetVoltage("a") - args.GetVoltage("b");

                // Because the property is always one iteration behind on the current solution, we relax the error a little bit
                double tol = Math.Max(Math.Abs(voltage), Math.Abs(voltage2)) * RelTol + 1e-9;
                Assert.AreEqual(voltage2, voltage, tol);
            };
            dc.Run(ckt);
        }
예제 #6
0
        public override SpiceSharp.Components.Model Generate(string id, string type, ParameterCollection parameters, ICircuitContext context)
        {
            var model = new DiodeModel(id);

            SetParameters(context, model, parameters);
            return(model);
        }
        public override Model Generate(string id, string type, ParameterCollection parameters, ICircuitContext context)
        {
            var model = new DiodeModel(id);

            SetParameters(context, model, parameters);

            return(new Model(id, model, model.Parameters));
        }
예제 #8
0
 protected void setup()
 {
     mModel     = DiodeModel.GetModelWithNameOrCopy(mModelName, mModel);
     mModelName = mModel.Name;
     mDiode.Setup(mModel);
     mHasResistance = (mModel.SeriesResistance > 0);
     mDiodeEndNode  = (mHasResistance) ? 2 : 1;
     allocNodes();
 }
예제 #9
0
        /// <summary>
        /// Create a diode with a model
        /// </summary>
        /// <param name="name">Diode name</param>
        /// <param name="anode">Anode</param>
        /// <param name="cathode">Cathode</param>
        /// <param name="model">Model</param>
        /// <param name="modelparams">Model parameters</param>
        /// <returns></returns>
        Diode CreateDiode(string name, string anode, string cathode, string model, string modelparams)
        {
            var d  = new Diode(name);
            var dm = new DiodeModel(model);

            ApplyParameters(dm, modelparams);
            d.SetModel(dm);
            d.Connect(anode, cathode);
            return(d);
        }
예제 #10
0
        /// <summary>
        /// Create a diode with a model
        /// </summary>
        /// <param name="name">Diode name</param>
        /// <param name="anode">Anode</param>
        /// <param name="cathode">Cathode</param>
        /// <param name="model">Model</param>
        /// <param name="modelparams">Model parameters</param>
        /// <returns></returns>
        Diode CreateDiode(Identifier name, Identifier anode, Identifier cathode, Identifier model, string modelparams)
        {
            Diode      d  = new Diode(name);
            DiodeModel dm = new DiodeModel(model);

            ApplyParameters(dm, modelparams);
            d.SetModel(dm);
            d.Connect(anode, cathode);
            return(d);
        }
예제 #11
0
 public ZenerElm(Point p1, Point p2, int f, StringTokenizer st) : base(p1, p2, f, st)
 {
     if ((f & FLAG_MODEL) == 0)
     {
         double zvoltage = st.nextTokenDouble();
         mModel     = DiodeModel.GetModelWithParameters(mModel.FwDrop, zvoltage);
         mModelName = mModel.Name;
         Console.WriteLine("model name wparams = " + mModelName);
     }
     setup();
 }
예제 #12
0
 public LEDElm(Point p1, Point p2, int f, StringTokenizer st) : base(p1, p2, f, st)
 {
     if ((f & (FLAG_MODEL | FLAG_FWDROP)) == 0)
     {
         const double fwdrop = 2.1024259;
         mModel     = DiodeModel.GetModelWithParameters(fwdrop, 0);
         mModelName = mModel.Name;
         Console.WriteLine("model name wparams = " + mModelName);
         setup();
     }
     mColorR = 1.0;
     mColorG = 0.0;
     mColorB = 0.0;
     mMaxBrightnessCurrent = 0.01;
     try {
         mColorR = st.nextTokenDouble();
         mColorG = st.nextTokenDouble();
         mColorB = st.nextTokenDouble();
         mMaxBrightnessCurrent = st.nextTokenDouble();
     } catch { }
 }
예제 #13
0
 public override void SetElementValue(int n, ElementInfo ei)
 {
     if (n == 0)
     {
         ReferenceName = ei.Textf.Text;
         setTextPos();
     }
     if (!mCustomModelUI && n == 1)
     {
         int ix = ei.Choice.SelectedIndex;
         if (ix >= mModels.Count)
         {
             mModels        = null;
             mCustomModelUI = true;
             ei.NewDialog   = true;
             return;
         }
         mModel     = mModels[ei.Choice.SelectedIndex];
         mModelName = mModel.Name;
         setup();
         return;
     }
     base.SetElementValue(n, ei);
 }
예제 #14
0
        public void When_LargeExample_Expect_Reference()
        {
            // First create the models
            var diodeModelA = new DiodeModel("DA")
                              .SetParameter("n", 0.1e-3);
            var diodeModelB = new DiodeModel("DB")
                              .SetParameter("is", 100e-14);
            var bjtModelQp1 = new BipolarJunctionTransistorModel("QP1")
                              .SetParameter("pnp", true)
                              .SetParameter("is", 16e-15)
                              .SetParameter("bf", 1700.0);
            var bjtModelQp2 = new BipolarJunctionTransistorModel("QP2")
                              .SetParameter("pnp", true)
                              .SetParameter("is", 16e-15)
                              .SetParameter("bf", 1610.5);

            var ckt = new Circuit(
                new NodeMapper(new[]
            {
                "VDD", "test:11", "test:12", "VEE", "test:91", "test:92", "test:13",
                "test:15", "test:14", "test:16", "test:20", "test:32", "test:111",
                "test:17", "test:112", "test:113", "test:114", "test:115", "INP",
                "INN", "test:21", "test:22", "test:23", "test:110", "test:33",
                "test:59", "test:34", "test:60", "test:61", "test:63", "test:62",
                "test:65", "test:66", "test:64", "test:67", "test:68", "test:69",
                "test:70", "OUT", "test:77", "test:78", "test:79", "test:80",
                "test:81", "test:83", "test:84", "test:85", "test:86", "test:87",
                "test:88", "test:89", "test:90"
            }),
                diodeModelA,
                diodeModelB,
                bjtModelQp1,
                bjtModelQp2,
                new VoltageSource("test:VS1", "VDD", "test:11", 0),
                new CurrentSource("test:IBIAS", "test:11", "test:12", 61.3e-6),
                new Diode("test:DBIAS", "VEE", "test:12", "DA"),
                new Resistor("test:RE1", "test:12", "test:91", 1.005e3),
                new Resistor("test:RE2", "test:12", "test:92", 1.005e3),
                new BipolarJunctionTransistor("test:QI1", "test:13", "test:15", "test:91", "test:91", "QP1"),
                new BipolarJunctionTransistor("test:QI2", "test:14", "test:16", "test:92", "test:92", "QP2"),
                new Resistor("test:RIN1", "test:15", "test:20", 3e6),
                new Resistor("test:RIN2", "test:16", "test:20", 3e6),
                new Diode("test:DIN1", "test:15", "VDD", "DB"),
                new Diode("test:DIN2", "VEE", "test:15", "DB"),
                new Diode("test:DIN3", "test:16", "VDD", "DB"),
                new Diode("test:DIN4", "VEE", "test:16", "DB"),
                new VoltageControlledVoltageSource("test:ECR1", "test:15", "test:32", "test:111", "test:20", 1),
                new VoltageSource("test:VOS", "test:17", "test:32", 1e-3),
                new Diode("test:DP1", "test:17", "test:112", "DB"),
                new Diode("test:DP2", "test:112", "test:113", "DB"),
                new Diode("test:DP3", "test:113", "test:16", "DB"),
                new Diode("test:DP4", "test:16", "test:114", "DB"),
                new Diode("test:DP5", "test:114", "test:115", "DB"),
                new Diode("test:DP6", "test:115", "test:17", "DB"),
                new Resistor("test:RP1", "test:17", "INP", 3.5e3),
                new Resistor("test:RP2", "test:16", "INN", 3.5e3),
                new Resistor("test:RC1", "test:13", "VEE", 1.856e3),
                new Resistor("test:RC2", "test:14", "VEE", 1.856e3),
                new Capacitor("test:C1", "test:13", "test:14", 14.0e-12),
                new VoltageControlledCurrentSource("test:GA", "test:21", "test:20", "test:14", "test:13",
                                                   326.8e-6),
                new CurrentControlledCurrentSource("test:FSUP", "VEE", "VDD", "test:VS1", 1),
                new Resistor("test:RO1", "test:21", "test:20", 30606),
                new VoltageControlledCurrentSource("test:GB", "test:22", "test:20", "test:21", "test:20", 1),
                new Resistor("test:RO2", "test:22", "test:20", 20e3),
                new VoltageControlledVoltageSource("test:EF", "test:23", "test:20", "test:22", "test:20", 1),
                new Capacitor("test:CC", "test:23", "test:21", 36.8e-12),
                new VoltageControlledVoltageSource("test:EG", "test:20", "VEE", "VDD", "VEE", 0.5),
                new VoltageControlledCurrentSource("test:GCP", "test:22", "test:20", "test:110", "test:20", 10),
                new Diode("test:DVL1", "test:22", "test:33", "DA"),
                new VoltageSource("test:VMIN1", "test:59", "test:33", 6.85e-3),
                new Diode("test:DVL2", "test:34", "test:22", "DA"),
                new VoltageSource("test:VMIN2", "test:34", "test:60", 4e-3),
                new VoltageControlledVoltageSource("test:ELIM2", "test:59", "test:61", "VDD", "VEE", 0.5),
                new VoltageControlledVoltageSource("test:ELIM1", "test:63", "test:60", "VDD", "VEE", 0.5),
                new VoltageControlledVoltageSource("test:ECOMP2", "test:62", "test:20", "test:65", "test:66", 1),
                new VoltageControlledVoltageSource("test:ECOMP1", "test:64", "test:20", "test:65", "test:66", 1),
                new VoltageControlledVoltageSource("test:EOUT", "test:65", "test:20", "test:22", "test:20", 1),
                new Resistor("test:ROUT1", "test:65", "test:66", 150),
                new VoltageSource("test:VIS3", "test:66", "test:67", 0),
                new Diode("test:DSC1", "test:67", "test:68", "DA"),
                new Diode("test:DSC2", "test:69", "test:67", "DA"),
                new Diode("test:DSC3", "test:69", "test:70", "DA"),
                new Diode("test:DSC4", "test:70", "test:68", "DA"),
                new CurrentSource("test:ISC1", "test:68", "test:69", 25e-3),
                new Resistor("test:RSC", "test:68", "test:69", 10e6),
                new Resistor("test:ROUT2", "test:70", "OUT", 0.1e-3),
                new Resistor("test:RLOAD", "OUT", "test:20", 10e6),
                new Diode("test:DSUP", "VEE", "VDD", "DB"),
                new Resistor("test:RSUP", "VDD", "VEE", 200e3),
                new CurrentSource("test:ISUP", "VDD", "VEE", 95e-6),
                new CurrentControlledCurrentSource("test:FSUP1", "test:20", "test:77", "test:VIS3", 1),
                new Capacitor("test:CSUP", "test:77", "test:20", 1e-12),
                new Diode("test:DSUP1", "test:20", "test:77", "DB"),
                new Diode("test:DSUP2", "test:77", "test:78", "DB"),
                new VoltageSource("test:VIS4", "test:78", "test:20", 0),
                new CurrentControlledCurrentSource("test:FSUP2", "VDD", "VEE", "test:VIS4", 1),
                new VoltageControlledVoltageSource("test:ESUP1", "test:79", "test:20", "VDD", "VEE", 1),
                new Capacitor("test:CPSRR", "test:79", "test:80", 7.5e-12),
                new Resistor("test:RPSRR", "test:80", "test:20", 5e3),
                new VoltageControlledCurrentSource("test:GPSRR1", "test:20", "test:110", "test:80", "test:20",
                                                   0.05),
                new VoltageControlledCurrentSource("test:GPSRR2", "test:20", "test:111", "test:79", "test:20",
                                                   10.5e-6),
                new Resistor("test:RRDC", "test:111", "test:20", 1),
                new Resistor("test:RRR", "test:110", "test:20", 1),
                new VoltageControlledVoltageSource("test:ECM1", "test:81", "test:20", "test:12", "VEE", 1),
                new VoltageControlledCurrentSource("test:GCM2", "test:20", "test:111", "test:81", "test:20", 10e-6),
                new Diode("test:DIL", "test:12", "test:83", "DA"),
                new Resistor("test:RIL", "test:83", "test:84", 50),
                new VoltageSource("test:VIL", "test:85", "test:84", 0.9),
                new VoltageControlledVoltageSource("test:EIL", "test:85", "VEE", "VDD", "VEE", 1),
                new Diode("test:DVL3", "VEE", "test:12", "DA"),
                new Diode("test:DVL4", "test:12", "test:86", "DA"),
                new CurrentControlledCurrentSource("test:FVL", "test:86", "VEE", "test:VIS5", 1),
                new VoltageSource("test:VVL", "test:87", "VEE", 2.3),
                new VoltageSource("test:VIS5", "test:87", "test:88", 0),
                new Diode("test:DVL5", "test:88", "test:89", "DA"),
                new Resistor("test:RVL", "test:89", "test:90", 300),
                new VoltageControlledVoltageSource("test:EVL1", "test:90", "VEE", "VDD", "VEE", 1),
                new Resistor("RF", "OUT", "INN", 10),
                new VoltageSource("VSIG", "INP", "0", new Pulse(-1.5, 1.5, 1e-6, 10e-9, 10e-9, 5e-6, 10e-6)),
                new VoltageSource("VSUP", "VDD", "VEE", 5),
                new VoltageControlledVoltageSource("EG1", "0", "VEE", "VDD", "VEE", 0.2)
                );

            // Calculate the operating point
            var tran = new Transient("tran", 1e-9, 10e-6);

            tran.Run(ckt);
        }