SEMAFORO
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity semaforo is
generic(
min_cnt : integer := 0;
max_cnt : integer := 25_000_001;
top_cnt : integer := 25_000_000
);
port(
clk : in std_logic;
reset : in std_logic;
--in in std_logic;
output : out std_logic_vector(2 downto 0)
);
end semaforo;
architecture Behavioral of semaforo is
-- Build an enumerated type for the state machine
type state_type is (s0,s1,s2);
-- Registrer to hold the current state
signal state: state_type;
signal cnt : integer range min_cnt to max_cnt:=0;
begin
process (clk, reset)
begin
if reset = '1' then
state <= s0;
elsif (rising_edge(clk)) then
case state is
when s0 =>
if cnt = top_cnt then
state <= s1;
cnt <= 0;
else
state <= s0;
cnt <= cnt+1;
end if;
when s1 =>
if cnt = top_cnt then
state <= s2;
cnt <= 0;
else
state <= s1;
cnt <= cnt+1;
end if;
when s2 =>
if cnt = top_cnt then
state <= s0;
cnt <= 0;
else
state <= s2;
cnt <= cnt+1;
end if;
end case;
end if;
end process;
process (state, cnt)
begin
case state is
when s0 =>
output <= "001";
when s1 =>
output <= "010";
when s2 =>
output <= "100";
end case;
end process;
end Behavioral;
use IEEE.STD_LOGIC_1164.ALL;
entity semaforo is
generic(
min_cnt : integer := 0;
max_cnt : integer := 25_000_001;
top_cnt : integer := 25_000_000
);
port(
clk : in std_logic;
reset : in std_logic;
--in in std_logic;
output : out std_logic_vector(2 downto 0)
);
end semaforo;
architecture Behavioral of semaforo is
-- Build an enumerated type for the state machine
type state_type is (s0,s1,s2);
-- Registrer to hold the current state
signal state: state_type;
signal cnt : integer range min_cnt to max_cnt:=0;
begin
process (clk, reset)
begin
if reset = '1' then
state <= s0;
elsif (rising_edge(clk)) then
case state is
when s0 =>
if cnt = top_cnt then
state <= s1;
cnt <= 0;
else
state <= s0;
cnt <= cnt+1;
end if;
when s1 =>
if cnt = top_cnt then
state <= s2;
cnt <= 0;
else
state <= s1;
cnt <= cnt+1;
end if;
when s2 =>
if cnt = top_cnt then
state <= s0;
cnt <= 0;
else
state <= s2;
cnt <= cnt+1;
end if;
end case;
end if;
end process;
process (state, cnt)
begin
case state is
when s0 =>
output <= "001";
when s1 =>
output <= "010";
when s2 =>
output <= "100";
end case;
end process;
end Behavioral;
Comentarios
Publicar un comentario