Está en la página 1de 6

-- Code your design here

library IEEE;

use IEEE. STD_LOGIC_1164. ALL;

entity PF is

Port (

Entrada: in std_logic_vector (5 downto 0);

Salida: out std_logic_vector (4 downto 0)

);

end PF;

architecture Behavioral of PF is

--------------------------------------------------------------------

signal EstadoActual, EstadoSiguiente: std_logic_vector (2 downto 0) := "001";

--------------------------------------------------------------------

CambiaEstados: process (Entrada)

begin

case EstadoActual is

when "001" => -- Derecha

IF (Entrada = "100000") THEN EstadoSiguiente <= "001";

ELSIF (Entrada = "010000") THEN EstadoSiguiente <= "010";

ELSIF (Entrada = "001000") THEN EstadoSiguiente <= "011";

ELSIF (Entrada = "000100") THEN EstadoSiguiente <= "100";

ELSIF (Entrada = "000010") THEN EstadoSiguiente <= "101";

ELSIF (Entrada = "000001") THEN EstadoSiguiente <= "110";

END IF;

when "010" => -- Izquierda

IF (Entrada = "100000") THEN EstadoSiguiente <= "001";

ELSIF (Entrada = "010000") THEN EstadoSiguiente <= "010";


ELSIF (Entrada = "001000") THEN EstadoSiguiente <= "011";

ELSIF (Entrada = "000100") THEN EstadoSiguiente <= "100";

ELSIF (Entrada = "000010") THEN EstadoSiguiente <= "101";

ELSIF (Entrada = "000001") THEN EstadoSiguiente <= "110";

END IF;

when "011" => -- Adelante

IF (Entrada = "100000") THEN EstadoSiguiente <= "001";

ELSIF (Entrada = "010000") THEN EstadoSiguiente <= "010";

ELSIF (Entrada = "001000") THEN EstadoSiguiente <= "011";

ELSIF (Entrada = "000100") THEN EstadoSiguiente <= "100";

ELSIF (Entrada = "000010") THEN EstadoSiguiente <= "101";

ELSIF (Entrada = "000001") THEN EstadoSiguiente <= "110";

END IF;

when "100" => -- Retroceder

IF (Entrada = "100000") THEN EstadoSiguiente <= "001";

ELSIF (Entrada = "010000") THEN EstadoSiguiente <= "010";

ELSIF (Entrada = "001000") THEN EstadoSiguiente <= "011";

ELSIF (Entrada = "000100") THEN EstadoSiguiente <= "100";

ELSIF (Entrada = "000010") THEN EstadoSiguiente <= "101";

ELSIF (Entrada = "000001") THEN EstadoSiguiente <= "110";

END IF;

when "101" => -- Parar

IF (Entrada = "100000") THEN EstadoSiguiente <= "001";

ELSIF (Entrada = "010000") THEN EstadoSiguiente <= "010";

ELSIF (Entrada = "001000") THEN EstadoSiguiente <= "011";


ELSIF (Entrada = "000100") THEN EstadoSiguiente <= "100";

ELSIF (Entrada = "000010") THEN EstadoSiguiente <= "101";

ELSIF (Entrada = "000001") THEN EstadoSiguiente <= "110";

END IF;

when "110" => -- Bateria

IF (Entrada = "100000") THEN EstadoSiguiente <= "001";

ELSIF (Entrada = "010000") THEN EstadoSiguiente <= "010";

ELSIF (Entrada = "001000") THEN EstadoSiguiente <= "011";

ELSIF (Entrada = "000100") THEN EstadoSiguiente <= "100";

ELSIF (Entrada = "000010") THEN EstadoSiguiente <= "101";

ELSIF (Entrada = "000001") THEN EstadoSiguiente <= "110";

END IF;

when others =>

EstadoSiguiente <= "001";

end case;

EstadoActual <= EstadoSiguiente;

SendSignals: process (EstadoActual)

begin

case EstadoActual is

when "001" =>

Salida <= "01010";

when "010" =>

Salida <= "00101";

when "011" =>


Salida <= "01001";

when "100" =>

Salida <= "00110";

"00110";

when "101" =>

Salida <= "00000";

when "110" =>

Salida <= "10000";

when others =>

Salida <= "00000";

end case;

end process;

end Behavioral;

--Testbench for OR gate

Tibrary IEEE;
use IEEE.std_logic_1164.all;

entity testbench is

-- empty

end testbench;

architecture tb of testbench is

-- DUT component

component PF is

port(

Entrada: in std_logic_vector (5 downto 0);

Salida: out std_logic_vector (4 downto 0));

end component;

signal Entrada_in: std_logic_vector (5 downto 0);

signal Salida_out: std_logic_vector (4 downto 0);

begin

-- Connect DUT

DUT: PF port map(Entrada_in, Salida_out);

stimulus : process

begin

--wait for period;

Entrada_in <= "100000";

wait for 1 ns;

assert(Salida_out <= "01010") report "Estado 1 incorrecto" severity error;

Entrada_in <= "010000";

wait for 1 ns;

assert (Salida_out <= "00101") report "Estado 2 incorrecto" severity error;

Entrada_in <= "001000";

wait for 1 ns;

assert (Salida_out <= "01001") report "Estado 3 incorrecto" severity error;


Entrada_in < "000100";

wait for 1 ns;

assert (Salida_out <= "00110") report "Estado 4 incorrecto" severity error;

Entrada_in <= "000010";

wait for 1 ns;

assert(Salida_out <= "00000") report "Estado 5 incorrecto" severity error;

Entrada_in <= "000001";

wait for 1 ns;

assert(Salida_out <= "10000") report "Estado 6 incorrecto" severity error;

wait;

end process stimulus;

end tb;

También podría gustarte