-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulation.vhd
256 lines (233 loc) · 7.38 KB
/
simulation.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity parking_system_tb is
end entity;
architecture behavior of parking_system_tb is
-- signals for testing
signal ticket_in: integer;
signal enter_time_in: integer;
signal exit_time_in: integer;
signal clk: std_logic;
signal payment_out: integer;
signal full_out: std_logic;
signal id_valid: std_logic;
signal car_entering: std_logic;
signal car_exiting: std_logic;
signal gate_open: std_logic;
signal rst: std_logic;
signal occupy: std_logic_vector(49 downto 0);
signal led: std_logic_vector(49 downto 0);
signal free_count: natural;
signal occupied_count: natural;
signal temperature: natural;
signal fire: std_logic;
signal coffee_button: std_logic;
signal hot_chocolate_button: std_logic;
signal ice_cream_button: std_logic;
signal water_button: std_logic;
signal coffee_ready: std_logic;
signal hot_chocolate_ready: std_logic;
signal ice_cream_ready: std_logic;
signal water_ready: std_logic;
signal money_received: std_logic;
signal change_amount: natural;
signal seg : std_logic_vector(6 downto 0);
signal seg2 : std_logic_vector(6 downto 0);
SIGNAL sensor_pw : STD_LOGIC_VECTOR(49 DOWNTO 0) := (OTHERS => '0');
SIGNAL carexist : STD_LOGIC_VECTOR(49 DOWNTO 0);
SIGNAL distance : STD_LOGIC_VECTOR(7 DOWNTO 0);
SIGNAL placement : natural Range 0 to 49;
SIGNAL check : integer;
SIGNAL check_count : natural := 0;
-- component to be tested
component parking_system is
GENERIC(
clk_freq : INTEGER := 40);
port (
ticket_in : in integer;
enter_time_in : in integer;
exit_time_in : in integer;
clk : in std_logic;
payment_out : out integer;
full_out : out std_logic;
id_valid : in std_logic;
car_entering : inout std_logic;
car_exiting : inout std_logic;
gate_open : out std_logic;
rst: in std_logic;
occupy: in std_logic_vector(49 downto 0);
led: out std_logic_vector(49 downto 0);
free_count: inout natural;
occupied_count: inout natural;
temperature: in natural;
fire: out std_logic;
coffee_button: in std_logic;
hot_chocolate_button: in std_logic;
ice_cream_button: in std_logic;
water_button: in std_logic;
coffee_ready: inout std_logic;
hot_chocolate_ready: inout std_logic;
ice_cream_ready: inout std_logic;
water_ready: inout std_logic;
money_received: in std_logic;
change_amount: out natural;
seg : out std_logic_vector(6 downto 0);
seg2 : out std_logic_vector(6 downto 0);
sensor_pw : IN STD_LOGIC_VECTOR(49 DOWNTO 0);
carexist : OUT STD_LOGIC_VECTOR(49 DOWNTO 0);
placement : IN natural Range 0 to 49;
check : out integer;
distance : INOUT STD_LOGIC_VECTOR(7 DOWNTO 0);
check_count : out natural:= 0
);
end component;
CONSTANT clk_period : time := 10 ns;
begin
-- instantiate the design under test
dut: entity work.parking_system
port map (
clk => clk,
rst => rst,
ticket_in => ticket_in,
enter_time_in => enter_time_in,
exit_time_in => exit_time_in,
payment_out => payment_out,
full_out => full_out,
id_valid => id_valid,
car_entering => car_entering,
car_exiting => car_exiting,
gate_open => gate_open,
occupy => occupy,
led => led,
free_count => free_count,
occupied_count => occupied_count,
temperature => temperature,
fire => fire,
coffee_button => coffee_button,
hot_chocolate_button => hot_chocolate_button,
ice_cream_button => ice_cream_button,
water_button => water_button,
coffee_ready => coffee_ready,
hot_chocolate_ready => hot_chocolate_ready,
ice_cream_ready => ice_cream_ready,
water_ready => water_ready,
money_received => money_received,
change_amount => change_amount,
seg => seg,
seg2 => seg2,
sensor_pw => sensor_pw,
carexist => carexist,
distance => distance,
placement => placement,
check => check,
check_count => check_count
);
-- clock generation process
clk_process: process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
-- test scenario
test_scenario: process
begin
-- initialize test input signals
rst <= '1';
wait for 10 ns;
rst <= '0';
wait for 10 ns;
gate_open <= '0';
wait for 10 ns;
-- set temperature to a high value to trigger fire indicator
temperature <= 400;
wait for 10 ns;
-- set temperature back to a normal value
temperature <= 200;
wait for 10 ns;
-- press coffee button and pay for drink
coffee_button <= '1';
money_received <= '1';
wait for 10 ns;
coffee_button <= '0';
money_received <= '0';
wait for 10 ns;
-- press hot chocolate button and pay for drink
hot_chocolate_button <= '1';
money_received <= '1';
wait for 10 ns;
hot_chocolate_button <= '0';
money_received <= '0';
wait for 10 ns;
-- press ice cream button and pay for drink
ice_cream_button <= '1';
money_received <= '1';
wait for 10 ns;
ice_cream_button <= '0';
money_received <= '0';
wait for 10 ns;
-- press water button and pay for drink
water_button <= '1';
money_received <= '1';
wait for 10 ns;
water_button <= '0';
money_received <= '0';
wait for 10 ns;
car_entering <= '1';
id_valid <= '1';
car_exiting <= '0';
wait for 10 ns;
car_entering <= '0';
wait for 10 ns;
car_entering <= '1';
id_valid <= '0';
ticket_in <= 5;
enter_time_in <= 3;
car_exiting <= '0';
wait for 10 ns;
car_entering <= '0';
wait for 10 ns;
placement <= 0;
sensor_pw(placement) <= '1';
wait for clk_period*2;
placement <= 0;
sensor_pw(placement) <= '0';
wait for clk_period*2;
placement <= 0;
sensor_pw(placement) <= '1';
wait for clk_period*2;
placement <= 0;
sensor_pw(placement) <= '0';
wait for clk_period*2;
placement <= 1;
sensor_pw(placement) <= '1';
wait for clk_period*2;
placement <= 1;
sensor_pw(placement) <= '0';
wait for clk_period*2;
placement <= 1;
sensor_pw(placement) <= '1';
wait for clk_period*2;
placement <= 1;
sensor_pw(placement) <= '0';
wait for clk_period*2;
placement <= 0;
sensor_pw(placement) <= '1';
wait for clk_period*2;
placement <= 2;
sensor_pw(placement) <= '1';
wait for clk_period*2;
placement <= 2;
sensor_pw(placement) <= '0';
wait for clk_period*2;
placement <= 2;
sensor_pw(placement) <= '1';
wait for clk_period*2;
placement <= 2;
sensor_pw(placement) <= '0';
wait for clk_period*2;
wait;
end process;
end architecture;