-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface_hcsr04_fd.vhd
117 lines (103 loc) · 3.09 KB
/
interface_hcsr04_fd.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
--------------------------------------------------------------------
-- Arquivo : interface_hcsr04_fd.vhd
-- Projeto : Experiencia 4 - Interface com sensor de distancia
--------------------------------------------------------------------
-- Descricao : fluxo de dados do circuito
-- da interface HC-SR04
--------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity interface_hcsr04_fd is
port(
clock : in std_logic;
pulso : in std_logic;
gera : in std_logic;
zera : in std_logic;
registra : in std_logic;
fim_medida : out std_logic;
distancia : out std_logic_vector(11 downto 0);
trigger : out std_logic
);
end entity;
architecture interface_hcsr04_fd_structure of interface_hcsr04_fd is
component contador_cm is
generic (
constant R : integer;
constant N : integer
);
port (
clock : in std_logic;
reset : in std_logic;
pulso : in std_logic;
digito0 : out std_logic_vector(3 downto 0);
digito1 : out std_logic_vector(3 downto 0);
digito2 : out std_logic_vector(3 downto 0);
pronto : out std_logic
);
end component;
component registrador_n is
generic (
constant N: integer := 8
);
port (
clock : in std_logic;
clear : in std_logic;
enable : in std_logic;
D : in std_logic_vector (N-1 downto 0);
Q : out std_logic_vector (N-1 downto 0)
);
end component;
component gerador_pulso is
generic (
largura: integer:= 25
);
port(
clock : in std_logic;
reset : in std_logic;
gera : in std_logic;
para : in std_logic;
pulso : out std_logic;
pronto : out std_logic
);
end component;
signal s_distancia : std_logic_vector(11 downto 0);
begin
CONTCM: contador_cm
generic map(
R => 2941,
N => 12
)
port map(
clock => clock,
reset => zera,
pulso => pulso,
digito0 => s_distancia(3 downto 0),
digito1 => s_distancia(7 downto 4),
digito2 => s_distancia(11 downto 8),
pronto => fim_medida
);
REGDIST: registrador_n
generic map(
N => 12
)
port map(
clock => clock,
clear => zera,
enable => registra,
D => s_distancia,
Q => distancia
);
GPULSO: gerador_pulso
generic map(
largura => 500 -- 10us/20ns = 500 ciclos
)
port map(
clock => clock,
reset => zera,
gera => gera,
para => '0',
pulso => trigger,
pronto => open
);
end architecture;