blob: 8aeac121b8c83137ffe8e40700d3e3de833cd964 (
plain) (
blame)
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 <devices/nlid_cmos.h>
#include "analog/nld_twoterm.h"
#include "nld_4066.h"
namespace netlist
{
namespace devices
{
NETLIB_OBJECT(CD4066_GATE)
{
NETLIB_CONSTRUCTOR(CD4066_GATE)
NETLIB_FAMILY("CD4XXX")
, m_supply(*this, "PS")
, m_R(*this, "R")
, m_control(*this, "CTL")
, m_base_r(*this, "BASER", 270.0)
{
}
NETLIB_RESETI() { }
NETLIB_UPDATEI();
public:
NETLIB_SUB(vdd_vss) m_supply;
NETLIB_SUB(R) m_R;
analog_input_t m_control;
param_double_t m_base_r;
};
NETLIB_UPDATE(CD4066_GATE)
{
nl_double sup = (m_supply.vdd() - m_supply.vss());
nl_double low = NL_FCONST(0.45) * sup;
nl_double high = NL_FCONST(0.55) * sup;
nl_double in = INPANALOG(m_control) - m_supply.vss();
nl_double rON = m_base_r * NL_FCONST(5.0) / sup;
nl_double R = -1.0;
if (in < low)
{
R = NL_FCONST(1.0) / netlist().gmin();
}
else if (in > high)
{
R = rON;
}
if (R > NL_FCONST(0.0))
{
// We only need to update the net first if this is a time stepping net
if (1) // m_R.m_P.net().as_analog().solver().is_timestep())
{
m_R.update_dev();
m_R.set_R(R);
m_R.m_P.schedule_after(NLTIME_FROM_NS(1));
}
else
{
m_R.set_R(R);
m_R.update_dev();
}
}
}
NETLIB_DEVICE_IMPL(CD4066_GATE)
} //namespace devices
} // namespace netlist
|