semaforo
Publicado por charly (1 intervención) el 10/05/2016 04:28:06
hola alguien que me ayude a hacer este código de otra manera por favor.
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
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity semaforo is
port ( sensor : in std_logic;
reset: in std_logic;
clk : in std_logic;
sem_carre: out std_logic_vector ( 2 downto 0);
sem_camino : out std_logic_vector (2 downto 0));
end semaforo;
architecture colores of semaforo is
type estado is (inicial,carre_ama,cami_verde,cami_rillo,espera);
constant verde : std_logic_vector ( 2 downto 0):= "001";
constant amarillo : std_logic_vector ( 2 downto 0):= "010";
constant rojo : std_logic_vector ( 2 downto 0):= "100";
signal estado_actual : estado:= inicial;
signal reset_cuenta : boolean:= false; -- son valores falso o verdadero---
signal fin_cuenta_10, fin_cuenta_20: boolean;
signal cuenta: integer range 0 to 63;
begin maquina:
process (clk,reset)
begin
if reset='1' then
estado_actual <= inicial;
elsif clk='1' and clk'event then
case estado_actual is
when inicial =>
if sensor = '1'then
estado_actual <= carre_ama;
end if;
when carre_ama =>
estado_actual <= cami_verde;
when cami_verde =>
if fin_cuenta_10 then
estado_actual<= cami_rillo;
end if;
when cami_rillo =>
estado_actual <= espera;
when espera =>
if fin_cuenta_20 then
estado_actual <= inicial;
end if;
end case ;
end if ;
end process maquina ;
salida:
process (estado_actual)
begin
case estado_actual is
when inicial =>
sem_carre <= verde;
sem_camino <= rojo;
reset_cuenta <= true;
when carre_ama =>
sem_carre <= amarillo;
sem_camino <= rojo;
reset_cuenta <= true;
when cami_verde =>
sem_carre <= rojo;
sem_camino <= verde;
reset_cuenta <= false;
when cami_rillo =>
sem_carre <= rojo;
sem_camino <= amarillo;
reset_cuenta <= true;
when espera =>
sem_carre <= verde;
sem_camino <= rojo;
reset_cuenta <= false;
end case;
end process salida;
contandor:
process (clk)
begin
if clk='1' and clk'event then
if reset_cuenta then cuenta <= 0;
else cuenta <= cuenta+1;
end if;
end if ;
end process contandor;
fin_cuenta_10 <= true when cuenta = 9 else false;
fin_cuenta_20 <= true when cuenta = 19 else false;
end colores;
Valora esta pregunta
1