Vous êtes sur la page 1sur 2

Walddys Emmanuel Dorrejo Cspedes

1044068

MODULO
entity Modulo is
Port (
sEntrada: IN std_logic; --Seal de entrada.
CLK: IN std_logic; --Seal de reloj.
sResetH: IN std_logic; --Seal de inicializacin
sSalida: out std_logic_vector (1 downto 0)); --Salida
end Modulo;
architecture Behavioral of Modulo is
--Declaracin del tipo asociado a los estados.
TYPE TipoEstados IS (E0, E1, E2, E3);
--Seales auxiliares para la codificacin del
--estado actual y siguiente.
SIGNAL tEstadoActual, tEstadoSiguiente: TipoEstados;
begin
-- Proceso dedicado a la lgica de estado:
LOGICA_ESTADO: Process(tEstadoActual, sEntrada)
Begin
case (tEstadoActual) is
when E0 =>
if (sEntrada = '1') then tEstadoSiguiente <= E1;
else tEstadoSiguiente <= E3;
End if;
when E1 =>
if (sEntrada = '1') THEN tEstadoSiguiente <= E2;
else tEstadoSiguiente <= E0;
End if;
when E2 =>
if (sEntrada = '1') THEN tEstadoSiguiente <= E3;
else tEstadoSiguiente <= E1;
End if;
when E3 =>
if (sEntrada = '1') THEN tEstadoSiguiente <= E0;
else tEstadoSiguiente <= E2;
End if;
end case;
end process LOGICA_ESTADO;
-- Proceso dedicado a la Memoria de Estado
MEM_ESTADO: Process(CLK, sResetH,tEstadoSiguiente)
Begin
--Inicializacin con RESET_H (Cuando se resetee volvera al estado 0 o inicial)
If (sResetH ='1') Then tEstadoActual <= E0;
Elsif(rising_edge(CLK)) then tEstadoActual <= tEstadoSiguiente;
End if;
end process MEM_ESTADO;

--Zona concurrente dedicada a modelar la


--lgica de salida.
sSalida <= "00" When (tEstadoActual = E0 and sEntrada = '1') else
"01" When (tEstadoActual = E1 and sEntrada = '1') else
"10" When (tEstadoActual = E2 and sEntrada = '1') else
"11" When (tEstadoActual = E3 and sEntrada = '1') else
"00";
-- sSalida = f(Estado, entrada) => Mquina de Mealy.
end Behavioral;

TESTBENCH
-- En el modulo programamos que cada ves que haya un rising_edge el estado pase al siguiente
CLK_process :process
begin
CLK <= '0';
wait for CLK_period/2;
CLK <= '1';
wait for CLK_period/2;
end process;
-- La entrada tendra un valor cada rising_edge
stim_proc: process
begin
sEntrada <= '1'; sResetH <= '0';
wait for CLK_period*10;
sEntrada <= '1'; sResetH <= '0';
wait for CLK_period*10;
sEntrada <= '0'; sResetH <= '0';
wait for CLK_period*10;
sEntrada <= '0'; sResetH <= '0';
wait for CLK_period*10;
sResetH <= '1';
wait;
end process;

Vous aimerez peut-être aussi