You are on page 1of 1

--Module: Frecuency Divider 100Mhz to 1Mhz------ Led<= '1';

else
library ieee; Led<= '0';
use ieee.std_logic_1164.all; end if;
use ieee.numeric_std.all;
use ieee.std_logic_arith.all;
Led_Output <=
CONV_STD_LOGIC_VECTOR((echo_time/58),8);
entity divisor_frecuencia is
--------- 1/58 = 1 / (29 * 2)------
Port ( clk, rst : in std_logic;
end if;
clk_out : out std_logic);
end process;
end divisor_frecuencia;
end Sensores;
::::::::::::::::
--------TOP--------
architecture Behavioral of divisor_frecuencia is
begin
library ieee;
process(clk, rst)
use ieee.std_logic_1164.all;
variable cont: integer:=0;
use ieee.numeric_std.all;
----- F=50Mhz T=20ns / F=1Mhz T=1000ns
use ieee.std_logic_arith.all;
begin
entity Top is
if (rst='1') then Port(clk,rst : in std_logic;
cont:=0; Leds_Out : out std_logic_vector(7 downto 0);
clk_out <= '0'; ----------7 mas significativo
elsif rising_edge(clk) then PulsoEcho : in std_logic;
cont := cont + 1; Trigg : out std_logic;
if cont = 50 then LedS : out std_logic);
cont:=0; end Top;
end if;
architecture Behavioral of Top is
if cont < 25 then
clk_out <= '1'; component Sensor is
else port (Led_Output : out std_logic_vector(7 downto 0);
clk_out <= '0'; ------- --7 mas significativo
end if; Trigger : out std_logic;
end if; Echo : in std_logic;
end process; Led : out std_logic;
end Behavioral; clk : in std_logic);
:::::::::::::::::::::::::::::::::::: end component;
------Module: Sensor Ultrasonic --------------
component divisor_frecuencia is
library ieee; Port ( clk, rst : in std_logic;
use ieee.std_logic_1164.all; clk_out : out std_logic);
use ieee.numeric_std.all; end component;
use ieee.std_logic_arith.all;
signal xclk : std_logic;
entity Sensor is
port ( Led_Output : out std_logic_vector(7 downto 0); begin
Trigger : out std_logic;
Echo : in std_logic; mod1: divisor_frecuencia port map(
Led : out std_logic; clk => clk,
clk : in std_logic); rst => rst,
end Sensor; clk_out=> xclk
);
architecture Sensores of Sensor is
signal echo_time: integer:=0; mod2: Sensor port map(
begin Led_OutPut => Leds_Out,
process(clk) Trigger => Trigg,
variable c1,c2 : integer:=0; Echo => PulsoEcho,
variable y : std_logic:='1'; Led => LedS,
begin clk => xclk
);
end Behavioral;
if rising_edge(clk) then
:::::::::::::::::
if(c1=0) then
Trigger<='1';
elsif(c1=10) then
Trigger<='0';
y:='1';
elsif(c1=1000011) then
c1:=0;
Trigger<='1';
end if;
c1:=c1+1;

if(Echo = '1') then


c2:=c2+1;
elsif(Echo = '0' and y='1')then
echo_time <= c2;
c2 :=0 ;
y :='0';
end if;

if (echo_time < 290) then-- 5 cm

You might also like