-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcounter.vhd
189 lines (162 loc) · 5.59 KB
/
counter.vhd
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
-----------------------------------------------------------------------------------------------------------------------------------
---- CODE VERSION v1
-----------------------------------------------------------------------------------------------------------------------------------
-- library ieee;
-- use ieee.std_logic_1164.all;
-- use ieee.Numeric_std.all;
--
-- entity counter is
-- port( clk : in std_logic;
-- rst : in std_logic;
-- Admin_In : in std_logic;
-- Staff_In : in std_logic;
-- Visitor_In : in std_logic;
-- DisAbel_In : in std_logic;
-- Admin_Out : in std_logic;
-- Staff_Out : in std_logic;
-- Visitor_Out : in std_logic;
-- DisAbel_Out : in std_logic;
-- GatePerm:out std_logic
-- );
-- end counter;
--
-- architecture RTL of counter is
--
-- signal count : integer range 0 to 20;
-- signal CountAdmin : integer range 0 to 4;
-- signal CountDisAbel : integer range 0 to 14;
-- signal CountStaff : integer range 0 to 4;
-- signal CountVisitor : integer range 0 to 19;
-- begin
-- process(clk,rst)
-- begin
-- if( rst = '1') then
-- CountAdmin <= 0;
-- CountStaff <= 0;
-- CountVisitor <= 0;
-- CountDisAbel <= 0;D:/ModelSimProject/MultiLevelCarPArking/counter.vhd
-- elsif(rising_edge(clk))then
-- if(Admin_In = '1') then
-- CountAdmin <= CountAdmin + 1;
--
--
-- elsif(DisAbel_In = '1') then
-- CountDisAbel <= CountDisAbel + 1;
--
--
-- elsif(Staff_In = '1') then
-- CountStaff <= CountStaff + 1;
--
--
-- elsif(Visitor_In = '1') then
-- CountVisitor <= CountVisitor + 1;
--
--
-- elsif(Admin_Out = '1') then
-- CountAdmin <= CountAdmin - 1;
--
-- elsif(DisAbel_Out = '1') then
-- CountDisAbel <= CountDisAbel - 1;
--
-- elsif(Staff_Out = '1') then
-- CountStaff <= CountStaff - 1;
--
-- elsif(Visitor_Out = '1') then
-- CountVisitor <= CountVisitor - 1;
-- end if;
--
-- end if;
---------------------------------------------------------
---- If block reseting the counter
---------------------------------------------------------
-- if(CountAdmin >= 4) then
-- CountAdmin <= 0;
-- elsif(CountDisAbel >= 14) then
-- CountDisAbel<= 0;
-- elsif(CountStaff >= 14)then
-- CountStaff <=0;
-- elsif(CountVisitor >= 14)then
-- CountVisitor <= 0;
--
-- end if;
--
-- GatePerm <= '0' when(CountAdmin >= 4)else '1';
--
-- GatePerm <= '0' when(CountDisAbel >= 14)else '1';
--
-- GatePerm <= '0' when(CountStaff >= 14)else '1';
--
-- GatePerm <= '0' when(CountVisitor >= 14)else '1';
-- end process;
--
---- GATE: GatePerm <= '0' when(CountAdmin >= 4)else '1';
----
---- GatePerm <= '0' when(CountDisAbel >= 14)else '1';
----
---- GatePerm <= '0' when(CountStaff >= 14)else '1';
----
---- GatePerm <= '0' when(CountVisitor >= 14)else '1';
----
--
-- end RTl;
------------------------------------------------------------------------------------------------------------------------------------
-- CODE v2.0
------------------------------------------------------------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.Numeric_std.all;
entity counter is
port( clk : in std_logic;
rst : in std_logic;
Admin_In : in std_logic;
Staff_In : in std_logic;
Visitor_In : in std_logic;
DisAbel_In : in std_logic;
Admin_Out : in std_logic;
Staff_Out : in std_logic;
Visitor_Out : in std_logic;
DisAbel_Out : in std_logic;
GatePerm:out std_logic
);
end counter;
architecture RTL of counter is
signal CountAdmin : integer range 0 to 4;
signal CountDisAbel : integer range 0 to 14;
signal CountStaff : integer range 0 to 4;
signal CountVisitor : integer range 0 to 19;
begin
process(clk,rst,CountAdmin, CountStaff, CountVisitor, CountDisAbel,Admin_In,DisAbel_In,Staff_In,Visitor_In,Admin_Out,
DisAbel_Out,Staff_Out,Visitor_Out)
begin
if( rst = '1') then
CountAdmin <= 0;
CountStaff <= 0;
CountVisitor <= 0;
CountDisAbel <= 0;
elsif(rising_edge(clk))then
if(Admin_In = '1') then
CountAdmin <= CountAdmin + 1;
elsif(DisAbel_In = '1') then
CountDisAbel <= CountDisAbel + 1;
elsif(Staff_In = '1') then
CountStaff <= CountStaff + 1;
elsif(Visitor_In = '1') then
CountVisitor <= CountVisitor + 1;
elsif(Admin_Out = '1') then
CountAdmin <= CountAdmin - 1;
elsif(DisAbel_Out = '1') then
CountDisAbel <= CountDisAbel - 1;
elsif(Staff_Out = '1') then
CountStaff <= CountStaff - 1;
elsif(Visitor_Out = '1') then
CountVisitor <= CountVisitor - 1;
end if;
GATE: GatePerm <= '0' when (CountAdmin < 5)else '1';
GatePerm <= '0' when(CountDisAbel <= 14)else '1';
GatePerm <= '0' when(CountStaff <= 14)else '1';
GatePerm <= '0' when(CountVisitor <= 14)else '1';
GatePerm <= '0' when(CountAdmin <= 4)else '1';
end if;
end process;
end RTl;
------------------------------------------------------------------------------------------------------------------------------------