LIBRARY IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use ieee.numeric_std.all;
ENTITY brake_var IS
port (
clk : in std_logic;
reset : in std_logic;
chip_select : in std_logic;
writedata : in std_logic_vector (31 downto 0);
write_n : in std_logic;
address : in std_logic;
readdata : out std_logic_vector (31 downto 0);
out_port1 : out std_logic_vector (7 downto 0);
out_port2 : out std_logic_vector (7 downto 0));
END brake_var;
ARCHITECTURE brake_system OF brake_var IS
signal D : unsigned (31 downto 0); -- distance d'arrêt
signal v : unsigned (31 downto 0); -- vitesse du véhicule
signal Dmax : unsigned (31 downto 0); -- vitesse max (danger)
signal tb : std_logic;
signal brake : std_logic;
BEGIN
readdata <= std_logic_vector(D) when address = '0' else std_logic_vector(v);
registers: PROCESS (clk, reset)
BEGIN
if reset = '0' then
D <= (others =>'0');
v <= (others =>'0');
elsif clk'event and clk = '1' then
if chip_select ='1' and write_n = '0' then
if address = '0' then
D (31 downto 0) <= unsigned(writedata (31 downto 0));
else v (15 downto 0) <= unsigned(writedata (15 downto 0));
end if;
end if;
end if;
END PROCESS;
distance : PROCESS (clk,reset)
begin
if reset = '0' then
D <= (others =>'0');
elsif clk'event and clk='1' then
D(31 downto 0) <= (v(15 downto 0)*3)/10 + (v(15 downto 0)*v(15 downto 0))/100;
else
D <= (others =>'0');
end if;
END PROCESS;
tableau_de_bord : PROCESS (clk,reset)
begin
if reset = '0' then
tb <= '0';
elsif clk'event and clk='1' then
if
D < Dmax then tb <= '0' ;
else
tb <='1' ;
end if ;
end if;
end process;
frein : PROCESS (clk,reset)
begin
if reset = '0' then
brake <= '0';
elsif clk'event and clk='1' then
if tb = '0'
then brake <= '0';
else brake <='1'; -- freinage
end if;
end if;
END PROCESS;
out_port1 <= (others=> tb);
out_port2 <= (others=> brake);
END brake_system ;