-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutomatic_coffe_machine.vhd
511 lines (420 loc) · 15.1 KB
/
Automatic_coffe_machine.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
library ieee;
library STD;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_unsigned.all;
use IEEE.numeric_std.ALL;
entity coffe2 is
port(
clk, reset : in std_logic;
caffe_b : in std_logic;
cappuccino_b : in std_logic;
ricarica_b : in std_logic;
c1 : in std_logic;
c2 : in std_logic;
c3 : in std_logic;
c4 : in std_logic;
LED_out : out bit_vector (0 to 6);
LED_reg_1 : out bit_vector (0 to 6);
LED_reg_0 : out bit_vector (0 to 6);
LED_next_1 : out bit_vector (0 to 6);
LED_next_0 : out bit_vector (0 to 6);
LED_reset : out bit_vector (0 to 6)
);
end coffe2;
architecture arch of coffe2 is
type stateMealy_type is (zero, uno,due,tre,quattro,cinque,sei, sette, otto, nove, dieci, undici, dodici, tredici, quattordici, quindici); -- 16 states are required for Mealy
signal stateMealy_reg, stateMealy_next : stateMealy_type;
signal count: integer:=0;
signal max: integer:=50000;
signal interval_m: integer:=45000;
signal interval_p: integer:=5000;
signal caffe: std_logic :='0';
signal cappuccino: std_logic :='0';
signal ricarica: std_logic :='0';
signal tmp : std_logic := '0';
signal clock_out: std_logic:='0';
begin
process(clk)
begin
if(clk'event and clk='1') then
count <=count+1;
if (count = max) then
tmp <= NOT tmp;
count <= 1;
end if;
end if;
clock_out <= tmp;
end process;
process(clock_out, reset,stateMealy_reg,count)
begin
if (reset = '1') then -- go to state zero if reset
LED_reset<= "1001111";
if ((c1='0')and(c2='0')and(c3='0')and(c4='0')) then
stateMealy_reg <= zero;--stato iniziale deciso dall'importo presente sulla chiavetta
elsif ((c1='0')and(c2='0')and(c3='0')and(c4='1')) then
stateMealy_reg <= uno;--stato iniziale deciso dall'importo presente sulla chiavetta
elsif ((c1='0')and(c2='0')and(c3='1')and(c4='0')) then
stateMealy_reg <= due;--stato iniziale deciso dall'importo presente sulla chiavetta
elsif ((c1='0')and(c2='0')and(c3='1')and(c4='1')) then
stateMealy_reg <= tre;--stato iniziale deciso dall'importo presente sulla chiavetta
elsif ((c1='0')and(c2='1')and(c3='0')and(c4='0')) then
stateMealy_reg <= quattro;--stato iniziale deciso dall'importo presente sulla chiavetta
elsif ((c1='0')and(c2='1')and(c3='0')and(c4='1')) then
stateMealy_reg <= cinque;--stato iniziale deciso dall'importo presente sulla chiavetta
elsif ((c1='0')and(c2='1')and(c3='1')and(c4='0')) then
stateMealy_reg <= sei;--stato iniziale deciso dall'importo presente sulla chiavetta
elsif ((c1='0')and(c2='1')and(c3='1')and(c4='1')) then
stateMealy_reg <= sette;--stato iniziale deciso dall'importo presente sulla chiavetta
elsif ((c1='1')and(c2='0')and(c3='0')and(c4='0')) then
stateMealy_reg <= otto;--stato iniziale deciso dall'importo presente sulla chiavetta
elsif ((c1='1')and(c2='0')and(c3='0')and(c4='1')) then
stateMealy_reg <= nove;--stato iniziale deciso dall'importo presente sulla chiavetta
elsif ((c1='1')and(c2='0')and(c3='1')and(c4='0')) then
stateMealy_reg <= dieci;--stato iniziale deciso dall'importo presente sulla chiavetta
elsif ((c1='1')and(c2='0')and(c3='1')and(c4='1')) then
stateMealy_reg <= undici;--stato iniziale deciso dall'importo presente sulla chiavetta
elsif ((c1='1')and(c2='1')and(c3='0')and(c4='0')) then
stateMealy_reg <= dodici;--stato iniziale deciso dall'importo presente sulla chiavetta
elsif ((c1='1')and(c2='1')and(c3='0')and(c4='1')) then
stateMealy_reg <= tredici;--stato iniziale deciso dall'importo presente sulla chiavetta
elsif ((c1='1')and(c2='1')and(c3='1')and(c4='0')) then
stateMealy_reg <= quattordici;--stato iniziale deciso dall'importo presente sulla chiavetta
elsif ((c1='1')and(c2='1')and(c3='1')and(c4='1')) then
stateMealy_reg <= quindici;--stato iniziale deciso dall'importo presente sulla chiavetta
end if;
elsif (count = interval_m and clock_out = '0') then -- otherwise update the states
stateMealy_reg <= stateMealy_next;
LED_reset<= "0000001";
end if;
end process;
process (caffe_b,count,clock_out)
begin
if (caffe_b'event and caffe_b = '1') then
caffe <= '1';
end if;
if (count=interval_p and clock_out = '1') then caffe <= '0';
end if;
end process;
process (cappuccino_b,count,clock_out)
begin
if (cappuccino_b'event and cappuccino_b = '1') then
cappuccino <= '1';
end if;
if (count=interval_p and clock_out = '1') then cappuccino <= '0';
end if;
end process;
process (ricarica_b,count,clock_out)
begin
if (ricarica_b'event and ricarica_b = '1') then
ricarica <= '1';
end if;
if (count=interval_p and clock_out = '1') then ricarica <= '0';
end if;
end process;
-- Mealy Design
process(stateMealy_reg, caffe,cappuccino,ricarica,reset,clock_out, count)
begin
-- store current state as next
if (reset = '1') then -- otherwise update the states
if(count = interval_m and clock_out = '0') then
stateMealy_next <= stateMealy_reg; -- required: when no case statement is satisfied
end if;
elsif (clock_out'event and clock_out = '1')then
case stateMealy_reg is
when zero =>
LED_reg_1<= "0000001";
LED_reg_0<= "0000001";
--
if (caffe = '1') then
stateMealy_next <= zero; --NON PERMESSO
LED_out <= "0110000";
elsif (cappuccino = '1') then
stateMealy_next <= zero; --NON PERMESSO
LED_out <= "0110000";
elsif (ricarica = '1') then
stateMealy_next <= dieci;
LED_out <= "0111000";
end if;
when uno =>
--
LED_reg_1<= "0000001";
LED_reg_0<= "1001111";
if (caffe = '1') then
stateMealy_next <= uno; --NON PERMESSO
LED_out <= "0110000";
elsif (cappuccino = '1') then
stateMealy_next <= uno; --NON PERMESSO
LED_out <= "0110000";
elsif (ricarica = '1') then
stateMealy_next <= undici;
LED_out <= "0111000";
end if;
when due =>
--
LED_reg_1<= "0000001";
LED_reg_0<= "0010010";
if caffe = '1' then
stateMealy_next <= due; --NON PERMESSO
LED_out <= "0110000";
elsif cappuccino = '1' then
stateMealy_next <= due; --NON PERMESSO
LED_out <= "0110000";
elsif ricarica = '1' then
stateMealy_next <= dodici;
LED_out <= "0111000";
end if;
when tre =>
--
LED_reg_1<= "0000001";
LED_reg_0<= "0000110";
if caffe = '1' then
stateMealy_next <= tre; --NON PERMESSO
LED_out <= "0110000";
elsif cappuccino = '1' then
stateMealy_next <= tre; --NON PERMESSO
LED_out <= "0110000";
elsif ricarica = '1' then
stateMealy_next <= tredici;
LED_out <= "0111000";
end if;
when quattro =>
--
LED_reg_1<= "0000001";
LED_reg_0<= "1001100";
if caffe = '1' then
stateMealy_next <= quattro; --NON PERMESSO
LED_out <= "0110000";
elsif cappuccino = '1' then
stateMealy_next <= quattro; --NON PERMESSO
LED_out <= "0110000";
elsif ricarica = '1' then
stateMealy_next <= quattordici;
LED_out <= "0111000";
end if;
when cinque =>
--
LED_reg_1<= "0000001";
LED_reg_0<= "0100100";
if caffe = '1' then
stateMealy_next <= zero;
LED_out <= "0110001";
elsif cappuccino = '1' then
stateMealy_next <= cinque; --NON PERMESSO
LED_out <= "0110000";
elsif ricarica = '1' then
stateMealy_next <= quindici; --NON PERMESSO
LED_out <= "0111000";
end if;
when sei =>
--
LED_reg_1<= "0000001";
LED_reg_0<= "0100000";
if caffe = '1' then
stateMealy_next <= uno;
LED_out <= "0110001";
elsif cappuccino = '1' then
stateMealy_next <= zero;
LED_out <= "0000010";
elsif ricarica = '1' then
stateMealy_next <= sei; --NON PERMESSO
LED_out <= "0110000";
end if;
when sette =>
--
LED_reg_1<= "0000001";
LED_reg_0<= "0001111";
if caffe = '1' then
stateMealy_next <= due;
LED_out <= "0110001";
elsif cappuccino = '1' then
stateMealy_next <= uno;
LED_out <= "0000010";
elsif ricarica = '1' then
stateMealy_next <= sette; --NON PERMESSO
LED_out <= "0110000";
end if;
when otto =>
--
LED_reg_1<= "0000001";
LED_reg_0<= "0000000";
if caffe = '1' then
stateMealy_next <= tre;
LED_out <= "0110001";
elsif cappuccino = '1' then
stateMealy_next <= due;
LED_out <= "0000010";
elsif ricarica = '1' then
stateMealy_next <= otto; --NON PERMESSO
LED_out <= "0110000";
end if;
when nove =>
--
LED_reg_1<= "0000001";
LED_reg_0<= "0000100";
if caffe = '1' then
stateMealy_next <= quattro;
LED_out <= "0110001";
elsif cappuccino = '1' then
stateMealy_next <= tre;
LED_out <= "0000010";
elsif ricarica = '1' then
stateMealy_next <= nove; --NON PERMESSO
LED_out <= "0110000";
end if;
when dieci =>
--
LED_reg_1<= "1001111";
LED_reg_0<= "0000001";
if caffe = '1' then
stateMealy_next <= cinque;
LED_out <= "0110001";
elsif cappuccino = '1' then
stateMealy_next <= quattro;
LED_out <= "0000010";
elsif ricarica = '1' then
stateMealy_next <= dieci; --NON PERMESSO
LED_out <= "0110000";
end if;
when undici =>
--
LED_reg_1<= "1001111";
LED_reg_0<= "1001111";
if caffe = '1' then
stateMealy_next <= sei;
LED_out <= "0110001";
elsif cappuccino = '1' then
stateMealy_next <= cinque;
LED_out <= "0000010";
elsif ricarica = '1' then
stateMealy_next <= undici;--NON PERMESSO
LED_out <= "0110000";
end if;
when dodici =>
--
LED_reg_1<= "1001111";
LED_reg_0<= "0010010";
if caffe = '1' then
stateMealy_next <= sette;
LED_out <= "0110001";
elsif cappuccino = '1' then
stateMealy_next <= sei;
LED_out <= "0000010";
elsif ricarica = '1' then
stateMealy_next <= dodici;--NON PERMESSO
LED_out <= "0110000";
end if;
when tredici =>
--
LED_reg_1<= "1001111";
LED_reg_0<= "0000110";
if caffe = '1' then
stateMealy_next <= otto;
LED_out <= "0110001";
elsif cappuccino = '1' then
stateMealy_next <= sette;
LED_out <= "0000010";
elsif ricarica = '1' then
stateMealy_next <= tredici;--NON PERMESSO
LED_out <= "0110000";
end if;
when quattordici =>
--
LED_reg_1<= "1001111";
LED_reg_0<= "1001100";
if caffe = '1' then
stateMealy_next <= nove;
LED_out <= "0110001";
elsif cappuccino = '1' then
stateMealy_next <= otto;
LED_out <= "0000010";
elsif ricarica = '1' then
stateMealy_next <= quattordici;--NON PERMESSO
LED_out <= "0110000";
end if;
when quindici =>
--
LED_reg_1<= "1001111";
LED_reg_0<= "0100100";
if caffe = '1' then
stateMealy_next <= dieci;
LED_out <= "0110001";
elsif cappuccino = '1' then
stateMealy_next <= nove;
LED_out <= "0000010";
elsif ricarica = '1' then
stateMealy_next <= quindici;--NON PERMESSO
LED_out <= "0110000";
end if;
end case;
end if;
end process;
process(stateMealy_next)
begin
case stateMealy_next is
when zero =>
LED_next_1<= "0000001";
LED_next_0<= "0000001";
when uno =>
--
LED_next_1<= "0000001";
LED_next_0<= "1001111";
when due =>
--
LED_next_1<= "0000001";
LED_next_0<= "0010010";
when tre =>
--
LED_next_1<= "0000001";
LED_next_0<= "0000110";
when quattro =>
--
LED_next_1<= "0000001";
LED_next_0<= "1001100";
when cinque =>
--
LED_next_1<= "0000001";
LED_next_0<= "0100100";
when sei =>
--
LED_next_1<= "0000001";
LED_next_0<= "0100000";
when sette =>
--
LED_next_1<= "0000001";
LED_next_0<= "0001111";
when otto =>
--
LED_next_1<= "0000001";
LED_next_0<= "0000000";
when nove =>
--
LED_next_1<= "0000001";
LED_next_0<= "0000100";
when dieci =>
--
LED_next_1<= "1001111";
LED_next_0<= "0000001";
when undici =>
--
LED_next_1<= "1001111";
LED_next_0<= "1001111";
when dodici =>
--
LED_next_1<= "1001111";
LED_next_0<= "0010010";
when tredici =>
--
LED_next_1<= "1001111";
LED_next_0<= "0000110";
when quattordici =>
--
LED_next_1<= "1001111";
LED_next_0<= "1001100";
when quindici =>
--
LED_next_1<= "1001111";
LED_next_0<= "0100100";
end case;
end process;
end arch;