Está en la página 1de 6

Prueba

Realice el diagrama de estados y el código VHDL de un semáforo que tiene las


siguientes señales: verde, amarillo, rojo, clock, reset, enable. Verde se activa por 10
segundo (ciclos de reloj), amarillo por 2 segundos y rojo por 6 segundos. Cuando el
semáforo esta deshabilitado se mantiene parpadeando el amarillo. Cuando se resetea
(LOW) el semáforo se pone en un estado de inicio con verde y rojo encendidos
simultáneamente.

Codigo

Maq_Est
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_unsigned.all;
--Realice el diagrama de estados y el código VHDL de un semáforo que
tiene las
--siguientes señales: verde, amarillo, rojo, clock, reset, enable.
Verde se activa
--por 10 segundo (ciclos de reloj), amarillo por 2 segundos y rojo por
6 segundos.
--Cuando el semáforo esta deshabilitado se mantiene parpadeando el
amarillo.
--Cuando se resetea (LOW) el semáforo se pone en un estado de inicio
con verde y rojo
--encendidos simultáneamente.
----------------------------------------------------
entity MaqEst is
Port(
clk, rst, enable : in std_logic;
sal_estado : out std_logic_vector(1 downto
0); --Est1, Est2, Est3
luces : out std_logic_vector(2 downto
0)); --verde, amarillo, rojo
end MaqEst;
----------------------------------------------------
architecture MaqEst_arch of MaqEst is
signal counter_1s: std_logic_vector(27 downto 0):= x"0000000";
signal delay_count:std_logic_vector(3 downto 0):= x"0";
signal delay_10s, delay_2s, delay_6s, VERDE_H, AMARILLO_H,
AMARILLO_L, ROJO_H: std_logic:='0';
signal clk_1s_enable: std_logic; -- 1s clock enable
type estados_ME is (Est1, Est2, Est3);
-- Est1: VERDE (10 seg), AMARILLO (2 seg), ROJO (6 seg)
-- Est2: AMARILLO PARPADEO
-- Est3: VERDE Y ROJO: ON
attribute num_estado: string;
attribute num_estado of estados_ME: type is "01 10 11";
signal ps, ns : estados_ME;

begin
EM: process(clk,ns,rst)
begin
if (rst='0') then ps <= Est3;
elsif (rising_edge(clk)) then ps <= ns;
end if;
end process EM;

COMB_EST: process(ps,enable, delay_10s, delay_2s, delay_6s)


begin
luces <= "101";
case ps is
when Est1 => -- Enable=1: VERDE (10 seg), AMARILLO (2 seg), ROJO (6
seg)
luces <= "100";
VERDE_H <= '1';
if (enable='1' and delay_10s='1') then
ns<=Est1;
luces <= "010";
AMARILLO_H <= '1';
elsif(enable='1' and delay_2s='1') then
ns<=Est1;
luces <= "001";
ROJO_H <= '1';
elsif(enable='1' and delay_6s='1') then
ns<=Est1;
luces <= "100";
VERDE_H <= '1';
else ns<=Est2;
end if;

when Est2 =>


luces <= "010";
AMARILLO_H <= '1';
AMARILLO_L <= '0';
if (enable='1' and delay_2s='1') then
ns<=Est1;
else ns<=Est2;
luces <= "000";
AMARILLO_H <= '0';
AMARILLO_L <= '1';
end if;

when Est3=>
luces <= "101";
VERDE_H <= '1';
ROJO_H <= '1';
if (enable='1') then
ns<=Est1;
else ns<=Est2;
end if;
end case;
end process COMB_EST;

with ps select
sal_estado <= "01" when Est1,
"10" when Est2,
"11" when Est3,
"ZZ" when others;

process(clk)
begin
if(rising_edge(clk)) then
if(clk_1s_enable='1') then
if(VERDE_H='1' or AMARILLO_H='1' or ROJO_H='1') then
delay_count <= delay_count + x"1";
if((delay_count = x"9") and VERDE_H ='1') then
delay_10s <= '1';
delay_2s <= '0';
delay_6s <= '0';
delay_count <= x"0";
elsif((delay_count = x"1") and AMARILLO_H= '1') then
delay_10s <= '0';
delay_2s <= '1';
delay_6s <= '0';
delay_count <= x"0";
elsif((delay_count = x"5") and ROJO_H='1') then
delay_10s <= '0';
delay_2s <= '0';
delay_6s <= '1';
delay_count <= x"0";
else
delay_10s <= '0';
delay_2s <= '0';
delay_6s <= '0';
end if;
end if;
end if;
end if;
end process;
-- create delay 1s
process(clk)
begin
if(rising_edge(clk)) then
counter_1s <= counter_1s + x"0000001";
if(counter_1s >= x"0000003") then -- x"0004" is for simulation
-- change to x"2FAF080" for 50 MHz clock running real FPGA
counter_1s <= x"0000000";
end if;
end if;
end process;
clk_1s_enable <= '1' when counter_1s = x"0003" else '0'; -- x"0002" is
for simulation
-- x"2FAF080" for 50Mhz clock on FPGA
end MaqEst_arch;

Tb_ Maq_Est
library ieee;
use ieee.std_logic_1164.all;

entity tb_MaqEst is
end tb_MaqEst;

architecture tb of tb_MaqEst is

component MaqEst
port (clk : in std_logic;
rst : in std_logic;
enable : in std_logic;
sal_estado : out std_logic_vector (1 downto 0);
luces : out std_logic_vector (2 downto 0));
end component;

signal clk : std_logic;


signal rst : std_logic;
signal enable : std_logic;
signal sal_estado : std_logic_vector (1 downto 0);
signal luces : std_logic_vector (2 downto 0);

constant clk_period: time := 100 ns;

begin
dut : MaqEst port map (clk => clk,
rst => rst,
enable => enable,
sal_estado => sal_estado,
luces => luces);

clk_process : process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;

stimuli : process
begin
enable <= '0';
--Estado de reset
rst<='0';
wait for 100 ns;
rst<='1';
--Simulación
enable <= '1'; wait for clk_period*100;
enable <= '1'; wait for clk_period*20;
enable <= '1'; wait for clk_period*20;
rst<='0';

enable <= '1'; wait for clk_period*20;


enable <= '0'; wait for clk_period*20;
enable <= '1'; wait for clk_period*20;
wait;
end process;

end tb;

Simulación

También podría gustarte