Estoy tratando de escribir algún vhdl que detecte un patrón dado en una cadena de bits. El circuito debe generar 1 cuando encuentra el patrón "110" en el flujo de entrada. Mi entrada es "X" y mi salida es "Z".
Por alguna razón, cuando simulo los resultados, no obtengo ningún resultado para "Z". Simplemente se mantiene bajo. Esto es lo que tengo hasta ahora:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity checker is
Port ( clk : in STD_LOGIC;
x : in STD_LOGIC;
z : out STD_LOGIC);
end checker;
architecture Behavioral of checker is
type state_type is (S0, S1, S2);
signal pr_state: state_type := S0;
signal nx_state: state_type := S0;
begin
process(clk) begin
if (rising_edge(clk)) then
pr_state <= nx_state;
end if;
end process;
process(pr_state, nx_state) begin
case (pr_state) is
when S0 => z <= '0';
if (x = '1') then
nx_state <= S1;
else
nx_state <= S0;
end if;
when S1 => z <= '0';
if (x = '1') then
nx_state <= S2;
else
nx_state <= S1;
end if;
when S2 => z <= '1';
if (x = '0') then
nx_state <= S0;
else
nx_state <= S2;
end if;
when others => z <= '0';
end case;
end process;
end Behavioral;
¿Algún pensamiento? Agradecemos sus comentarios.
Código del banco de pruebas:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY checker_tb IS
END checker_tb;
ARCHITECTURE behavior OF checker_tb IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT checker
PORT(
clk : IN std_logic;
x : IN std_logic;
z : OUT std_logic
);
END COMPONENT;
--Inputs
signal clk : std_logic := '0';
signal x : std_logic := '0';
--Outputs
signal z : std_logic;
-- Clock period definitions
constant clk_period : time := 10 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: checker PORT MAP (
clk => clk,
x => x,
z => z
);
-- Clock process definitions
clk_process :process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
x_process :process
begin
x <= '1';
wait for 100ns;
x <= '1';
wait for 100ns;
x <= '0';
wait for 100ns;
end process;
stim_proc: process begin
wait for 100 ns;
wait for clk_period*10;
wait;
end process;
END;