blob: 535314c0aa44f1b42ff5313e8b922d4cff813825 (
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
|
// license:GPL-2.0+
// copyright-holders:Couriersud
/*
* nld_4066.c
*
*/
#include "nld_4066.h"
NETLIB_NAMESPACE_DEVICES_START()
NETLIB_START(CD4066_GATE)
{
register_input("CTL", m_control);
register_sub("PS", m_supply);
register_sub("R", m_R);
register_param("BASER", m_base_r, 270.0);
}
NETLIB_RESET(CD4066_GATE)
{
m_R.do_reset();
}
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_NAMESPACE_DEVICES_END()
|