Previous 199869 Revisions Next

r26432 Tuesday 26th November, 2013 at 22:03:42 UTC by Couriersud
Netlist: Pretend accuracy by specifying tons of parameters for diode model of which only two are used ;
Speed comes at a price :-)

Now, even a CVD (Constant voltage drop) diode model with series resistor can benefit from these parameters by using them to estimate a typical operating point and thus dynamic resistance when the model is setup.
[src/emu/netlist]nl_base.c nl_base.h nl_setup.c pstring.c pstring.h
[src/emu/netlist/devices]nld_system.h
[src/mame/drivers]pong.c

trunk/src/emu/netlist/nl_base.h
r26431r26432
592592};
593593
594594// ----------------------------------------------------------------------------------------
595// net_param_t
596// ----------------------------------------------------------------------------------------
597
598class netlist_param_t : public netlist_owned_object_t
599{
600public:
601
602    enum param_type_t {
603        STRING,
604        DOUBLE,
605        INTEGER,
606        LOGIC
607    };
608
609    netlist_param_t(const param_type_t atype)
610    : netlist_owned_object_t(PARAM, ANALOG)
611    , m_param_type(atype)
612    {  }
613
614
615    ATTR_HOT inline const param_type_t param_type() const { return m_param_type; }
616
617private:
618    const param_type_t m_param_type;
619};
620
621class netlist_param_double_t : public netlist_param_t
622{
623public:
624    netlist_param_double_t()
625    : netlist_param_t(DOUBLE)
626    , m_param(0.0)
627    {  }
628
629    ATTR_HOT inline void setTo(const double param);
630    ATTR_COLD inline void initial(const double val) { m_param = val; }
631    ATTR_HOT inline const double Value() const        { return m_param;   }
632
633private:
634    double m_param;
635};
636
637class netlist_param_int_t : public netlist_param_t
638{
639public:
640    netlist_param_int_t()
641    : netlist_param_t(INTEGER)
642    , m_param(0)
643    {  }
644
645    ATTR_HOT inline void setTo(const int param);
646    ATTR_COLD inline void initial(const int val) { m_param = val; }
647
648    ATTR_HOT inline const int Value() const     { return m_param;     }
649
650private:
651    int m_param;
652};
653
654class netlist_param_logic_t : public netlist_param_int_t
655{
656public:
657    netlist_param_logic_t()
658    : netlist_param_int_t()
659    {  }
660};
661
662class netlist_param_str_t : public netlist_param_t
663{
664public:
665    netlist_param_str_t()
666    : netlist_param_t(STRING)
667    , m_param("")
668    {  }
669
670    ATTR_HOT inline void setTo(const pstring &param);
671    ATTR_COLD inline void initial(const pstring &val) { m_param = val; }
672
673    ATTR_HOT inline const pstring &Value() const     { return m_param;     }
674
675private:
676   pstring m_param;
677};
678
679class netlist_param_multi_t : public netlist_param_str_t
680{
681public:
682    netlist_param_multi_t()
683    : netlist_param_str_t()
684    {  }
685
686    /* these should be cached! */
687    ATTR_COLD double dValue(const pstring &entity, const double defval = 0.0) const;
688
689private:
690};
691
692// ----------------------------------------------------------------------------------------
595693// net_device_t
596694// ----------------------------------------------------------------------------------------
597695
r26431r26432
729827private:
730828};
731829
732class netlist_param_t : public netlist_object_t
733{
734public:
735830
736    enum param_type_t {
737        STRING,
738        DOUBLE,
739        INTEGER,
740        LOGIC
741    };
742
743   netlist_param_t(const param_type_t atype)
744   : netlist_object_t(PARAM, ANALOG)
745    , m_param_type(atype)
746   , m_netdev(NULL)
747   {  }
748
749
750    ATTR_HOT inline const param_type_t param_type() const { return m_param_type; }
751   ATTR_HOT inline netlist_core_device_t &netdev() const { return *m_netdev; }
752   ATTR_COLD void set_netdev(netlist_core_device_t &dev) { m_netdev = &dev; }
753
754private:
755    const param_type_t m_param_type;
756   netlist_core_device_t *m_netdev;
757};
758
759class netlist_param_double_t : public netlist_param_t
760{
761public:
762    netlist_param_double_t()
763    : netlist_param_t(DOUBLE)
764    , m_param(0.0)
765    {  }
766
767    ATTR_HOT inline void setTo(const double param) { m_param = param; netdev().update_param(); }
768    ATTR_COLD inline void initial(const double val) { m_param = val; }
769    ATTR_HOT inline const double Value() const        { return m_param;   }
770
771private:
772    double m_param;
773};
774
775class netlist_param_int_t : public netlist_param_t
776{
777public:
778    netlist_param_int_t()
779    : netlist_param_t(INTEGER)
780    , m_param(0)
781    {  }
782
783    ATTR_HOT inline void setTo(const int param) { m_param = param; netdev().update_param(); }
784    ATTR_COLD inline void initial(const int val) { m_param = val; }
785
786    ATTR_HOT inline const int Value() const     { return m_param;     }
787
788private:
789    int m_param;
790};
791
792class netlist_param_logic_t : public netlist_param_int_t
793{
794public:
795    netlist_param_logic_t()
796    : netlist_param_int_t()
797    {  }
798};
799
800831// ----------------------------------------------------------------------------------------
801832// netlist_base_t
802833// ----------------------------------------------------------------------------------------
r26431r26432
936967// Inline implementations
937968// ----------------------------------------------------------------------------------------
938969
970ATTR_HOT inline void netlist_param_str_t::setTo(const pstring &param)
971{
972    m_param = param;
973    netdev().update_param();
974}
975
976ATTR_HOT inline void netlist_param_int_t::setTo(const int param)
977{
978    m_param = param;
979    netdev().update_param();
980}
981
982ATTR_HOT inline void netlist_param_double_t::setTo(const double param)
983{
984    m_param = param;
985    netdev().update_param();
986}
987
988
939989ATTR_HOT inline void netlist_input_t::inactivate()
940990{
941991   if (!is_state(STATE_INP_PASSIVE))
trunk/src/emu/netlist/nl_setup.c
r26431r26432
188188                            dynamic_cast<netlist_param_int_t &>(param).initial(vald);
189189                        }
190190                        break;
191                        case netlist_param_t::STRING:
192                        {
193                            dynamic_cast<netlist_param_str_t &>(param).initial(val);
194                        }
195                        break;
191196                        default:
192197                            fatalerror("Parameter is not supported %s : %s\n", temp.cstr(), val.cstr());
193198                    }
trunk/src/emu/netlist/pstring.h
r26431r26432
2727    ~pstring();
2828
2929    // construction with copy
30    pstring(const char *string) {init(); if (string != NULL) pcopy(string); }
30    pstring(const char *string) {init(); if (string != NULL && *string != 0) pcopy(string); }
3131    pstring(const pstring &string) {init(); pcopy(string); }
3232
3333    // assignment operators
r26431r26432
6262    inline const int len() const { return m_ptr->len(); }
6363
6464    inline bool equals(const pstring &string) { return (pcmp(string.cstr(), m_ptr->str()) == 0); }
65    inline bool iequals(const pstring &string) { return (pcmpi(string.cstr(), m_ptr->str()) == 0); }
66
6567    int cmp(pstring &string) { return pcmp(string.cstr()); }
68    int cmpi(pstring &string) { return pcmpi(cstr(), string.cstr()); }
6669
6770    int find(const char *search, int start = 0) const
6871    {
r26431r26432
123126            return strncmp(left, right, count);
124127    }
125128
129    int pcmpi(const char *lhs, const char *rhs, int count = -1) const;
130
126131    void pcopy(const char *from, int size);
127132
128133    inline void pcopy(const char *from)
trunk/src/emu/netlist/devices/nld_system.h
r26431r26432
4646        NETDEV_PARAMI(_name, C, _C)
4747
4848/* Generic Diode */
49#define NETDEV_D(_name)                                                             \
50        NET_REGISTER_DEV(D, _name)
49#define NETDEV_D(_name,  _model)                                                    \
50        NET_REGISTER_DEV(D, _name)                                                  \
51        NETDEV_PARAMI(_name, model, _model)
5152
53#define NETDEV_1N914(_name) NETDEV_D(_name, "Is=2.52n Rs=.568 N=1.752 Cjo=4p M=.4 tt=20n Iave=200m Vpk=75 mfg=OnSemi type=silicon")
54
5255// .model 1N914 D(Is=2.52n Rs=.568 N=1.752 Cjo=4p M=.4 tt=20n Iave=200m Vpk=75 mfg=OnSemi type=silicon)
5356
5457// ----------------------------------------------------------------------------------------
r26431r26432
266269    {
267270    }
268271
269    netlist_param_double_t m_Vt;
270    netlist_param_double_t m_Is;
271    netlist_param_double_t m_Rmin;
272    netlist_param_multi_t m_model;
272273
274    double m_Vt;
275    double m_Is;
276    double m_n;
277
273278    double m_VtInv;
274279    double m_Vcrit;
275280    double m_Vd;
r26431r26432
279284    {
280285        register_terminal("A", m_P);
281286        register_terminal("K", m_N);
287        register_param("model", m_model, "");
282288
283        register_param("Vt", m_Vt, 0.0258);
284        register_param("Is", m_Is, 1e-15);
285        register_param("Rmin", m_Rmin, 1.4);
286289        m_Vd = 0.7;
287290    }
288291
289292    virtual void update_param()
290293    {
291        m_Vcrit = m_Vt.Value() * log(m_Vt.Value() / m_Is.Value() / sqrt(2.0));
292        m_VtInv = 1.0 / m_Vt.Value();
294        m_Is = m_model.dValue("Is", 1e-15);
295        m_n = m_model.dValue("N", 1);
296
297        m_Vt = 0.0258 * m_n;
298
299        m_Vcrit = m_Vt * log(m_Vt / m_Is / sqrt(2.0));
300        m_VtInv = 1.0 / m_Vt;
293301        NL_VERBOSE_OUT(("VCutoff: %f\n", m_Vcrit));
294302    }
295303
r26431r26432
298306        const double nVd = m_P.net().Q_Analog()- m_N.net().Q_Analog();
299307
300308        //FIXME: Optimize cutoff case
301        m_Vd = (nVd > m_Vcrit) ? m_Vd + log((nVd - m_Vd) * m_VtInv + 1.0) * m_Vt.Value() : nVd;
309        m_Vd = (nVd > m_Vcrit) ? m_Vd + log((nVd - m_Vd) * m_VtInv + 1.0) * m_Vt : nVd;
302310
303311        const double eVDVt = exp(m_Vd * m_VtInv);
304        const double Id = m_Is.Value() * (eVDVt - 1.0);
312        const double Id = m_Is * (eVDVt - 1.0);
305313
306        m_g = m_Is.Value() * m_VtInv * eVDVt;
314        m_g = m_Is * m_VtInv * eVDVt;
307315
308316        m_I = (Id - m_Vd * m_g);
309317        //printf("Vd: %f %f %f %f\n", m_Vd, m_g, Id, m_I);
trunk/src/emu/netlist/nl_base.c
r26431r26432
329329template <class C, class T>
330330ATTR_COLD void netlist_device_t::register_param(netlist_core_device_t &dev, const pstring &sname, C &param, const T initialVal)
331331{
332    param.set_netdev(dev);
332    param.init_object(dev, sname);
333333    param.initial(initialVal);
334334    m_setup->register_object(*this, *this, sname, param, netlist_terminal_t::STATE_NONEX);
335335}
r26431r26432
337337template ATTR_COLD void netlist_device_t::register_param(netlist_core_device_t &dev, const pstring &sname, netlist_param_double_t &param, const double initialVal);
338338template ATTR_COLD void netlist_device_t::register_param(netlist_core_device_t &dev, const pstring &sname, netlist_param_int_t &param, const int initialVal);
339339template ATTR_COLD void netlist_device_t::register_param(netlist_core_device_t &dev, const pstring &sname, netlist_param_logic_t &param, const int initialVal);
340template ATTR_COLD void netlist_device_t::register_param(netlist_core_device_t &dev, const pstring &sname, netlist_param_str_t &param, const char * initialVal);
341template ATTR_COLD void netlist_device_t::register_param(netlist_core_device_t &dev, const pstring &sname, netlist_param_str_t &param, const pstring &initialVal);
342template ATTR_COLD void netlist_device_t::register_param(netlist_core_device_t &dev, const pstring &sname, netlist_param_multi_t &param, const char * initialVal);
340343
341344
342345// ----------------------------------------------------------------------------------------
r26431r26432
532535    m_high_V = high;
533536}
534537
538// ----------------------------------------------------------------------------------------
539// netlist_param_t & friends
540// ----------------------------------------------------------------------------------------
535541
542ATTR_COLD double netlist_param_multi_t::dValue(const pstring &entity, const double defval) const
543{
544    pstring tmp = this->Value();
545    // .model 1N914 D(Is=2.52n Rs=.568 N=1.752 Cjo=4p M=.4 tt=20n Iave=200m Vpk=75 mfg=OnSemi type=silicon)
546    int p = tmp.find(entity);
547    if (p>=0)
548    {
549        int pblank = tmp.find(" ", p);
550        if (pblank < 0) pblank = tmp.len() + 1;
551        tmp = tmp.substr(p, pblank - p);
552        int pequal = tmp.find("=", 0);
553        if (pequal < 0)
554           fatalerror("parameter %s misformat in model %s temp %s\n", entity.cstr(), Value().cstr(), tmp.cstr());
555        tmp = tmp.substr(pequal+1);
556        double factor = 1.0;
557        switch (*(tmp.right(1).cstr()))
558        {
559            case 'm': factor = 1e-3; break;
560            case 'u': factor = 1e-6; break;
561            case 'n': factor = 1e-9; break;
562            case 'p': factor = 1e-12; break;
563            case 'f': factor = 1e-15; break;
564            case 'a': factor = 1e-18; break;
565
566        }
567        if (factor != 1.0)
568            tmp = tmp.left(tmp.len() - 1);
569        return atof(tmp.cstr()) * factor;
570    }
571    else
572        return defval;
573}
574
575
536576// ----------------------------------------------------------------------------------------
537577// mainclock
538578// ----------------------------------------------------------------------------------------
trunk/src/emu/netlist/pstring.c
r26431r26432
6666    return ret;
6767}
6868
69//-------------------------------------------------
70//  pcmpi - compare a character array to an nstring
71//-------------------------------------------------
72
73int pstring::pcmpi(const char *lhs, const char *rhs, int count) const
74{
75    // loop while equal until we hit the end of strings
76    int index;
77    for (index = 0; index < count; index++)
78        if (lhs[index] == 0 || tolower(lhs[index]) != tolower(rhs[index]))
79            break;
80
81    // determine the final result
82    if (index < count)
83        return tolower(lhs[index]) - tolower(rhs[index]);
84    if (lhs[index] == 0)
85        return 0;
86    return 1;
87}
88
6989pstring pstring::vprintf(va_list args) const
7090{
7191    // sprintf into the temporary buffer
trunk/src/mame/drivers/pong.c
r26431r26432
465465   NETDEV_PARAM(videomix.R2, RES_K(1.2))
466466   NETDEV_PARAM(videomix.R3, RES_K(22))
467467
468    NETDEV_SOLVER(Solver)
469    NETDEV_ANALOG_CONST(V5, 5)
470    NETDEV_ANALOG_CONST(V1, 1)
471    NETDEV_ANALOG_CONST(V0, 0)
472468
473469#if 0
474470    NETDEV_R(R1, 10)
r26431r26432
507503    tt(28)
508504    tt(29)
509505*/
510#if 0
506#if 1
507    NETDEV_SOLVER(Solver)
508    NETDEV_ANALOG_CONST(V5, 5)
509    NETDEV_ANALOG_CONST(V1, 1)
510    NETDEV_ANALOG_CONST(V0, 0)
511
511512    NETDEV_R(R5, 1000)
512    NETDEV_D(D1)
513    NETDEV_1N914(D1)
513514    NET_C(V5, R5.1)
514515    NET_C(R5.2, D1.A)
515516    NET_C(D1.K, V0)
516517    //NETDEV_LOG(log1, D1.A)
517518#endif
518519
519#if 1
520#if 0
521    NETDEV_SOLVER(Solver)
522    NETDEV_ANALOG_CONST(V5, 5)
523    NETDEV_ANALOG_CONST(V1, 1)
524    NETDEV_ANALOG_CONST(V0, 0)
520525    // astable NAND Multivibrator
521526    NETDEV_R(R1, 1000)
522527    NETDEV_C(C1, 1e-6)

Previous 199869 Revisions Next


© 1997-2024 The MAME Team