diff options
-rw-r--r-- | nl_examples/opamp_amplification_curve.cpp | 38 | ||||
-rw-r--r-- | src/lib/netlist/tools/nl_convert.cpp | 33 | ||||
-rw-r--r-- | src/lib/netlist/tools/nl_convert.h | 2 |
3 files changed, 61 insertions, 12 deletions
diff --git a/nl_examples/opamp_amplification_curve.cpp b/nl_examples/opamp_amplification_curve.cpp index 73cb7273d9b..e1665244b0e 100644 --- a/nl_examples/opamp_amplification_curve.cpp +++ b/nl_examples/opamp_amplification_curve.cpp @@ -18,7 +18,7 @@ #include "netlist/devices/net_lib.h" -#define OPAMP_TEST "MB3614(FPF=10 UGF=1000k)" +#define OPAMP_TEST "MB3614(DAB=0.0015)" NETLIST_START(main) @@ -33,26 +33,48 @@ NETLIST_START(main) PARAM(Solver.DYNAMIC_MIN_TIMESTEP, 1e-7) VS(vs, 0) - PARAM(vs.FUNC, "0.001 * sin(6.28 * pow(10, 1 + 10*T) * T)") - //PARAM(vs.FUNC, "0.001 * sin(6.28 * pow(10, trunc((1 + T * 4)*2)/2) * T)") - //PARAM(vs.FUNC, "1.001 * sin(6.28 * 100 * T)") + /* + * Having f(t)=sin(g(t)*t) the derivative becomes + * + * f'(t) = d/dt(g(t)*t) * cos(g(t)*t) + * + * w(t) = d/dt(g(t)*t) = 2*pi*freq(t) is the angular frequency at time t + * + * choosing freq(t) = pow(10, a+b*t) and integrating we get + * + * g(t)*t = 2 * pi /(b*ln(10)) * (pow(10, a+b*t)-pow(10,a)) + */ + + PARAM(vs.FUNC, "0.001 * sin(0.2728752708 * (pow(10, 1 + 10*T) - 10))") + + /* + * Stepwise ... same as above + */ + //PARAM(vs.FUNC, "0.001 * sin(6.28 * pow(10, trunc((1 + T * 10)*10)/10) * T)") + + /* + * Fixed Frequency: + * PARAM(vs.FUNC, "1.001 * sin(6.28 * 100 * T)") + */ PARAM(vs.R, 0.001) ALIAS(clk, vs.1) NET_C(vs.2, GND) ANALOG_INPUT(V12, 12) ANALOG_INPUT(VM12, -12) - OPAMP(op,OPAMP_TEST) + OPAMP(op, OPAMP_TEST) NET_C(op.GND, VM12) NET_C(op.VCC, V12) /* Opamp B wired as inverting amplifier connected to output of first opamp */ - RES(R1, 0.1) - RES(R2, 10000) + RES(R1, 100) + RES(RP, 100) + RES(R2, 10000000) - NET_C(op.PLUS, GND) + NET_C(op.PLUS, RP.1) + NET_C(RP.2, GND) NET_C(op.MINUS, R2.2) NET_C(op.MINUS, R1.2) diff --git a/src/lib/netlist/tools/nl_convert.cpp b/src/lib/netlist/tools/nl_convert.cpp index 0acf5041c91..cbc17da5406 100644 --- a/src/lib/netlist/tools/nl_convert.cpp +++ b/src/lib/netlist/tools/nl_convert.cpp @@ -269,6 +269,14 @@ void nl_convert_spice_t::convert(const pstring &contents) out("NETLIST_END()\n"); } +static pstring rem(const std::vector<pstring> &vps, std::size_t start) +{ + pstring r(vps[start]); + for (std::size_t i=start + 1; i<vps.size(); i++) + r += " " + vps[i]; + return r; +} + void nl_convert_spice_t::process_line(const pstring &line) { if (line != "") @@ -286,7 +294,8 @@ void nl_convert_spice_t::process_line(const pstring &line) case '.': if (tt[0] == ".SUBCKT") { - out("NETLIST_START({})\n", tt[1].c_str()); + m_subckt = tt[1] + "_"; + out("NETLIST_START({})\n", tt[1]); for (std::size_t i=2; i<tt.size(); i++) add_ext_alias(tt[i]); } @@ -294,6 +303,11 @@ void nl_convert_spice_t::process_line(const pstring &line) { dump_nl(); out("NETLIST_END()\n"); + m_subckt = ""; + } + else if (tt[0] == ".MODEL") + { + out("NET_MODEL(\"{} {}\")\n", m_subckt + tt[1], rem(tt,2)); } else out("// {}\n", line.c_str()); @@ -309,7 +323,7 @@ void nl_convert_spice_t::process_line(const pstring &line) auto nval = plib::pstonum_ne<long>(tt[4], err); plib::unused_var(nval); - if ((err || plib::startsWith(tt[4], "N")) && tt.size() > 5) + if ((!err || plib::startsWith(tt[4], "N")) && tt.size() > 5) model = tt[5]; else model = tt[4]; @@ -320,7 +334,7 @@ void nl_convert_spice_t::process_line(const pstring &line) plib::perrlogger("error with model desc {}\n", model); pins = plib::left(m[1], 3); } - add_device("QBJT_EB", tt[0], m[0]); + add_device("QBJT_EB", tt[0], m_subckt + m[0]); add_term(tt[1], tt[0] + "." + pins.at(0)); add_term(tt[2], tt[0] + "." + pins.at(1)); add_term(tt[3], tt[0] + "." + pins.at(2)); @@ -349,6 +363,19 @@ void nl_convert_spice_t::process_line(const pstring &line) add_term(tt[1], tt[0] + ".1"); add_term(tt[2], tt[0] + ".2"); break; + case 'B': // arbitrary behavioural current source - needs manual work afterwords + add_device("CS", tt[0], "/*" + rem(tt, 3) + "*/"); + add_term(tt[1], tt[0] + ".P"); + add_term(tt[2], tt[0] + ".N"); + break; + case 'E': + add_device("VCVS", tt[0]); + add_term(tt[1], tt[0] + ".OP"); + add_term(tt[2], tt[0] + ".ON"); + add_term(tt[3], tt[0] + ".IP"); + add_term(tt[4], tt[0] + ".IN"); + out("PARAM({}, {})\n", tt[0] + ".G", tt[5]); + break; case 'V': // just simple Voltage sources .... if (tt[2] == "0") diff --git a/src/lib/netlist/tools/nl_convert.h b/src/lib/netlist/tools/nl_convert.h index 5cdae8e372d..731d1f58647 100644 --- a/src/lib/netlist/tools/nl_convert.h +++ b/src/lib/netlist/tools/nl_convert.h @@ -164,7 +164,7 @@ protected: void process_line(const pstring &line); private: - + pstring m_subckt; }; class nl_convert_eagle_t : public nl_convert_base_t |