diff options
Diffstat (limited to 'src/emu/netlist/analog/nld_twoterm.c')
-rw-r--r-- | src/emu/netlist/analog/nld_twoterm.c | 95 |
1 files changed, 76 insertions, 19 deletions
diff --git a/src/emu/netlist/analog/nld_twoterm.c b/src/emu/netlist/analog/nld_twoterm.c index 02ec7fa9c29..1a99dcaf90a 100644 --- a/src/emu/netlist/analog/nld_twoterm.c +++ b/src/emu/netlist/analog/nld_twoterm.c @@ -5,22 +5,26 @@ * */ +#include <solver/nld_solver.h> +#include <algorithm> + #include "nld_twoterm.h" -#include "nld_solver.h" + +NETLIB_NAMESPACE_DEVICES_START() // ---------------------------------------------------------------------------------------- -// netlist_generic_diode +// generic_diode // ---------------------------------------------------------------------------------------- -ATTR_COLD netlist_generic_diode::netlist_generic_diode() +ATTR_COLD generic_diode::generic_diode() { m_Vd = 0.7; set_param(1e-15, 1, 1e-15); } -ATTR_COLD void netlist_generic_diode::set_param(const nl_double Is, const nl_double n, nl_double gmin) +ATTR_COLD void generic_diode::set_param(const nl_double Is, const nl_double n, nl_double gmin) { - static const int csqrt2 = nl_math::sqrt(2.0); + static const double csqrt2 = nl_math::sqrt(2.0); m_Is = Is; m_n = n; m_gmin = gmin; @@ -31,7 +35,7 @@ ATTR_COLD void netlist_generic_diode::set_param(const nl_double Is, const nl_dou m_VtInv = 1.0 / m_Vt; } -ATTR_COLD void netlist_generic_diode::save(pstring name, netlist_object_t &parent) +ATTR_COLD void generic_diode::save(pstring name, object_t &parent) { parent.save(m_Vd, name + ".m_Vd"); parent.save(m_Id, name + ".m_Id"); @@ -43,14 +47,14 @@ ATTR_COLD void netlist_generic_diode::save(pstring name, netlist_object_t &paren // ---------------------------------------------------------------------------------------- ATTR_COLD NETLIB_NAME(twoterm)::NETLIB_NAME(twoterm)(const family_t afamily) - : netlist_device_t(afamily) + : device_t(afamily) { m_P.m_otherterm = &m_N; m_N.m_otherterm = &m_P; } ATTR_COLD NETLIB_NAME(twoterm)::NETLIB_NAME(twoterm)() - : netlist_device_t(TWOTERM) + : device_t(TWOTERM) { m_P.m_otherterm = &m_N; m_N.m_otherterm = &m_P; @@ -115,10 +119,6 @@ NETLIB_UPDATE(R) NETLIB_UPDATE_PARAM(R) { - //printf("updating %s to %f\n", name().cstr(), m_R.Value()); - - // FIXME: Only attached nets should be brought up to current time - //netlist().solver()->update_to_current_time(); // bring up current time update_dev(); if (m_R.Value() > 1e-9) set_R(m_R.Value()); @@ -139,7 +139,7 @@ NETLIB_START(POT) register_subalias("2", m_R1.m_N); register_subalias("3", m_R2.m_N); - connect(m_R2.m_P, m_R1.m_N); + connect_late(m_R2.m_P, m_R1.m_N); register_param("R", m_R, 1.0 / netlist().gmin()); register_param("DIAL", m_Dial, 0.5); @@ -165,9 +165,6 @@ NETLIB_UPDATE_PARAM(POT) if (m_DialIsLog.Value()) v = (nl_math::exp(v) - 1.0) / (nl_math::exp(1.0) - 1.0); - // FIXME: Only attached nets should be brought up to current time - //netlist().solver()->update_to_current_time(); // bring up current time - m_R1.update_dev(); m_R2.update_dev(); @@ -213,9 +210,6 @@ NETLIB_UPDATE_PARAM(POT2) if (m_Reverse.Value()) v = 1.0 - v; - // FIXME: Only attached nets should be brought up to current time - //netlist().solver()->update_to_current_time(); // bring up current time - m_R1.update_dev(); m_R1.set_R(std::max(m_R.Value() * v, netlist().gmin())); @@ -246,6 +240,7 @@ NETLIB_RESET(C) NETLIB_UPDATE_PARAM(C) { //step_time(1.0/48000.0); + m_GParallel = netlist().gmin() * m_C.Value(); } NETLIB_UPDATE(C) @@ -253,6 +248,14 @@ NETLIB_UPDATE(C) NETLIB_NAME(twoterm)::update(); } +ATTR_HOT void NETLIB_NAME(C)::step_time(const nl_double st) +{ + /* Gpar should support convergence */ + const nl_double G = m_C.Value() / st + m_GParallel; + const nl_double I = -G * deltaV(); + set(G, 0.0, I); +} + // ---------------------------------------------------------------------------------------- // nld_D // ---------------------------------------------------------------------------------------- @@ -286,3 +289,57 @@ NETLIB_UPDATE_TERMINALS(D) m_D.update_diode(deltaV()); set(m_D.G(), 0.0, m_D.Ieq()); } + +// ---------------------------------------------------------------------------------------- +// nld_VS +// ---------------------------------------------------------------------------------------- + +NETLIB_START(VS) +{ + NETLIB_NAME(twoterm)::start(); + + register_param("R", m_R, 0.1); + register_param("V", m_V, 0.0); + + register_terminal("P", m_P); + register_terminal("N", m_N); +} + +NETLIB_RESET(VS) +{ + NETLIB_NAME(twoterm)::reset(); + this->set(1.0 / m_R, m_V, 0.0); +} + +NETLIB_UPDATE(VS) +{ + NETLIB_NAME(twoterm)::update(); +} + +// ---------------------------------------------------------------------------------------- +// nld_CS +// ---------------------------------------------------------------------------------------- + +NETLIB_START(CS) +{ + NETLIB_NAME(twoterm)::start(); + + register_param("I", m_I, 1.0); + + register_terminal("P", m_P); + register_terminal("N", m_N); +} + +NETLIB_RESET(CS) +{ + NETLIB_NAME(twoterm)::reset(); + printf("m_I %f\n", m_I.Value()); + this->set(0.0, 0.0, m_I); +} + +NETLIB_UPDATE(CS) +{ + NETLIB_NAME(twoterm)::update(); +} + +NETLIB_NAMESPACE_DEVICES_END() |