-
Notifications
You must be signed in to change notification settings - Fork 1
/
TB.vhd
297 lines (244 loc) · 6.54 KB
/
TB.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE ieee.numeric_std.ALL;
ENTITY TbMaq IS
END TbMaq;
ARCHITECTURE TbMaq OF TbMaq IS
SIGNAL agua : STD_LOGIC;
SIGNAL suco : STD_LOGIC;
SIGNAL M100 : STD_LOGIC;
SIGNAL M050 : STD_LOGIC;
SIGNAL M025 : STD_LOGIC;
SIGNAL clk : std_logic;
SIGNAL reset : std_logic;
SIGNAL D025 : STD_LOGIC;
SIGNAL D050 : STD_LOGIC;
SIGNAL D100 : STD_LOGIC;
SIGNAL L_AGUA : STD_LOGIC;
SIGNAL L_SUCO : STD_LOGIC;
SIGNAL mr025 : unsigned(7 DOWNTO 0);
SIGNAL mr050 : unsigned(7 DOWNTO 0);
SIGNAL mr100 : unsigned(7 DOWNTO 0);
SIGNAL ir025 : unsigned(7 DOWNTO 0) := "00000001";
SIGNAL ir050 : unsigned(7 DOWNTO 0) := "00000001";
SIGNAL ir100 : unsigned(7 DOWNTO 0) := "00000001";
SIGNAL iAgua : unsigned(7 DOWNTO 0) := "00000101";
SIGNAL iSuco : unsigned(7 DOWNTO 0) := "00000101";
SIGNAL mAgua : unsigned(7 DOWNTO 0);
SIGNAL mSuco : unsigned(7 DOWNTO 0);
SIGNAL stts : std_logic_vector(2 DOWNTO 0);
--SIGNAL st025 : unsigned(7 DOWNTO 0);
--SIGNAL st050 : unsigned(7 DOWNTO 0);
--SIGNAL st100 : unsigned(7 DOWNTO 0);
SIGNAL u025 : std_logic;
SIGNAL u050 : std_logic;
SIGNAL u100 : std_logic;
SIGNAL DEV : std_logic;
SIGNAL L_DISP : std_logic;
CONSTANT Clk_period : TIME := 10 ns;
SIGNAL run : std_logic := '1';
BEGIN
Maq : ENTITY work.Maquina
PORT MAP(
agua => agua,
suco => suco,
M100 => M100,
M050 => M050,
M025 => M025,
clk => clk,
reset => reset,
D025 => D025,
D050 => D050,
D100 => D100,
L_AGUA => L_AGUA,
L_SUCO => L_SUCO,
mr025 => mr025,
mr050 => mr050,
mr100 => mr100,
ir025 => ir025,
ir050 => ir050,
ir100 => ir100,
stts => stts,
--st025 => st025,
--st050 => st050,
--st100 => st100,
iAgua => iAgua,
mAgua => mAgua,
iSuco => iSuco,
mSuco => mSuco,
u025 => u025,
u050 => u050,
u100 => u100,
DEV => DEV,
L_DISP => L_DISP
);
Clk_process : PROCESS
BEGIN
-- roda somente 100 vezes
FOR I IN 0 TO 100 LOOP
IF run = '1' THEN
Clk <= '0';
WAIT FOR Clk_period/2;
Clk <= '1';
WAIT FOR Clk_period/2;
ELSE
REPORT "Simulacao Completa" SEVERITY failure; -- para a simulacao
END IF;
END LOOP;
Clk <= '0';
WAIT;
END PROCESS;
tests : PROCESS
BEGIN
reset <= '1';
WAIT FOR clk_period/2;
reset <= '0';
-- insere moedas ate 1,75
-- pede uma agua com 25 cents
WAIT FOR Clk_period;
agua <= '1';
M025 <= '1';
WAIT FOR Clk_period;
M025 <= '0';
agua <= '0';
M050 <= '1';
WAIT FOR Clk_period;
M050 <= '0';
M100 <= '1';
WAIT FOR Clk_period;
M100 <= '0';
-- acaba com as aguas inserindo moedas de 1 real
WAIT FOR 40 ns;
reset <= '1';
WAIT FOR clk_period/2;
reset <= '0';
FOR i IN 0 TO 5 LOOP
report integer'image(i);
WAIT FOR clk_period;
M100 <= '1'; -- insere moeda de um real
WAIT FOR clk_period;
M100 <= '0';
agua <= '1'; -- pede uma agua
WAIT FOR clk_period;
agua <= '0';
END LOOP;
agua <= '0';
M100 <= '0';
--- Pede uma agua, quando nao tem agua
agua <= '1';
WAIT FOR clk_period;
agua <= '1';
agua <= '0';
WAIT FOR 40 ns;
-- reseta
reset <= '1';
WAIT FOR clk_period/2;
reset <= '0';
-- insere 1 moeda de um real e insere mais uma moeda de um real
-- pede devolucao
M100 <= '1';
WAIT FOR clk_period*2; -- espera dois periodos de clock (inserir 2 moedas)
M100 <= '0';
WAIT FOR clk_period;
DEV <= '1'; -- pede devolucao
WAIT FOR clk_period;
DEV <= '0';
WAIT FOR clk_period;
WAIT FOR 40 ns;
reset <= '1';
WAIT FOR clk_period/2;
reset <= '0';
-- insere 3 de 25 e 1 de 50 e pede uma agua.
M050 <= '1';
WAIT FOR clk_period;
M050 <= '0';
FOR i IN 0 TO 2 LOOP
M025 <= '1';
WAIT FOR clk_period;
M025 <= '0';
END LOOP;
agua <= '1';
WAIT FOR clk_period;
agua <= '0';
-- insere 1 de 50 e 1 de 1 e pede uma agua.
M050 <= '1';
WAIT FOR clk_period;
M050 <= '0';
M100 <= '1';
WAIT FOR clk_period;
M100 <= '0';
agua <= '1';
WAIT FOR clk_period;
agua <= '0';
-- insere uma de 1, uma de 50 e uma de 25 e pede uma agua
wait for clk_period*5;
M100 <= '1';
WAIT FOR clk_period;
M100 <= '0';
M050 <= '1';
WAIT FOR clk_period;
M050 <= '0';
M025 <= '1';
WAIT FOR clk_period;
M025 <= '0';
WAIT FOR clk_period;
agua <= '1';
WAIT FOR clk_period;
agua <= '0';
-- insere uma de 1, uma de 50 e uma de 25 e pede um suco
wait for clk_period*5;
M100 <= '1';
WAIT FOR clk_period;
M100 <= '0';
M050 <= '1';
WAIT FOR clk_period;
M050 <= '0';
M025 <= '1';
WAIT FOR clk_period;
M025 <= '0';
WAIT FOR clk_period;
suco <= '1';
WAIT FOR clk_period;
suco <= '0';
reset <= '1';
WAIT FOR clk_period/2;
reset <= '0';
-- devolucao acima de 1,75
M100 <='1';
WAIT FOR clk_period;
M100 <= '0';
M100 <='1';
WAIT FOR clk_period;
M100 <= '0';
suco <='1';
WAIT FOR clk_period;
suco <='0';
-- sem troco
WAIT FOR clk_period;
M100 <='1';
WAIT FOR clk_period;
M100 <= '0';
M100 <='1';
WAIT FOR clk_period;
M100 <= '0';
suco <='1';
WAIT FOR clk_period;
suco <='0';
--pede agua, nao tem troco
ir025 <= "00000000";
reset <= '1';
WAIT FOR clk_period/2;
reset <= '0';
M100 <='1';
WAIT FOR clk_period;
M100 <= '0';
M025 <='1';
WAIT FOR clk_period;
M025 <= '0';
agua <= '1';
WAIT FOR clk_period;
agua <='0';
run <= '0'; -- termina a simulacao
WAIT;
END PROCESS;
END TbMaq;