1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// license:GPL-2.0+
// copyright-holders:Couriersud
/*
* nld_4066.c
*
*/
#include "nld_4066.h"
#include "netlist/analog/nlid_twoterm.h"
#include "netlist/solver/nld_solver.h"
#include "nlid_system.h"
namespace netlist
{
namespace devices
{
NETLIB_OBJECT(CD4066_GATE)
{
NETLIB_CONSTRUCTOR(CD4066_GATE)
NETLIB_FAMILY("CD4XXX")
, m_supply(*this, "VDD", "VSS", true)
, m_R(*this, "R")
, m_control(*this, "CTL")
, m_base_r(*this, "BASER", nlconst::magic(270.0))
{
}
NETLIB_RESETI();
NETLIB_UPDATEI();
private:
nld_power_pins m_supply;
analog::NETLIB_SUB(R_base) m_R;
analog_input_t m_control;
param_fp_t m_base_r;
};
NETLIB_RESET(CD4066_GATE)
{
// Start in off condition
// FIXME: is ROFF correct?
m_R.set_R(plib::reciprocal(exec().gmin()));
}
NETLIB_UPDATE(CD4066_GATE)
{
nl_fptype sup = (m_supply.VCC() - m_supply.GND());
nl_fptype low = nlconst::magic(0.45) * sup;
nl_fptype high = nlconst::magic(0.55) * sup;
nl_fptype in = m_control() - m_supply.GND();
nl_fptype rON = m_base_r() * nlconst::magic(5.0) / sup;
nl_fptype R = -nlconst::one();
if (in < low)
{
R = plib::reciprocal(exec().gmin());
}
else if (in > high)
{
R = rON;
}
if (R > nlconst::zero())
{
m_R.update();
m_R.set_R(R);
m_R.solve_later();
}
}
NETLIB_DEVICE_IMPL(CD4066_GATE, "CD4066_GATE", "")
} //namespace devices
} // namespace netlist
|