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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
// license:GPL-2.0+
// copyright-holders:Couriersud
/*
* nld_4017.cpp
*
* CD4017: Decade Counter/Divider with 10 Decoded Outputs
*
* +--------------+
* Q5 |1 ++ 16| VDD
* Q1 |2 15| RESET
* Q0 |3 14| CLOCK
* Q2 |4 4017 13| CLOCK ENABLE
* Q6 |5 12| CARRY OUT
* Q7 |6 11| Q9
* Q3 |7 10| Q4
* VSS |8 9| Q8
* +--------------+
*
*
* CD4022: Divide-by-8 Counter/Divider with 8 Decoded Outputs
*
* +--------------+
* Q1 |1 ++ 16| VDD
* Q0 |2 15| RESET
* Q2 |3 14| CLOCK
* Q5 |4 4022 13| CLOCK ENABLE
* Q6 |5 12| CARRY OUT
* NC |6 11| Q4
* Q3 |7 10| Q7
* VSS |8 9| NC
* +--------------+
*
* Naming conventions follow Fairchild datasheet
*
* FIXME: Timing depends on VDD-VSS
* This needs a cmos d-a/a-d proxy implementation.
*
*/
#include "nl_base.h"
#include "nl_factory.h"
namespace netlist
{
namespace devices
{
template <std::size_t MaxCount>
NETLIB_OBJECT(CD4017_base)
{
NETLIB_CONSTRUCTOR_MODEL(CD4017_base, "CD4XXX")
, m_CLK(*this, "CLK", NETLIB_DELEGATE(clk))
, m_CLKEN(*this, "CLKEN", NETLIB_DELEGATE(inputs))
, m_RESET(*this, "RESET", NETLIB_DELEGATE(inputs))
, m_CO(*this, "CO")
, m_Q(*this, 0, "Q{}")
, m_cnt(*this, "m_cnt", 0)
, m_supply(*this)
{
}
private:
NETLIB_RESETI()
{
m_CLK.set_state(logic_t::STATE_INP_LH);
m_cnt = 0;
}
NETLIB_HANDLERI(clk)
{
++m_cnt;
update_outputs(m_cnt);
}
NETLIB_HANDLERI(inputs)
{
if (m_RESET())
{
m_CLK.inactivate();
m_cnt = 0;
update_outputs(m_cnt);
}
else if (m_CLKEN())
{
m_CLK.inactivate();
}
else
{
m_CLK.activate_lh();
}
}
void update_outputs(const unsigned cnt) noexcept
{
for (std::size_t i = 0; i < MaxCount; i++)
m_Q[i].push(i == cnt, NLTIME_FROM_NS(200));
m_CO.push(cnt < MaxCount / 2, NLTIME_FROM_NS(160));
}
logic_input_t m_CLK;
logic_input_t m_CLKEN;
logic_input_t m_RESET;
logic_output_t m_CO;
object_array_t<logic_output_t, MaxCount> m_Q;
state_var<unsigned> m_cnt;
nld_power_pins m_supply;
};
using NETLIB_NAME(CD4017) = NETLIB_NAME(CD4017_base)<10>;
using NETLIB_NAME(CD4022) = NETLIB_NAME(CD4017_base)<8>;
NETLIB_DEVICE_IMPL(CD4017, "CD4017", "")
NETLIB_DEVICE_IMPL(CD4022, "CD4022", "")
} //namespace devices
} // namespace netlist
|