I'm trying to write some vhdl that detects a given pattern in a string of bits. The circuit should output 1 when it finds the pattern "110" in the input stream. My input is "X" and my output is "Z".
For some reason when I simulate the results, I'm not getting any output for "Z". It just stays low. This is what I have so far:
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;
Any thoughts? Appreciate your feedback.
Test bench Code:
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;
x_process
should probably be clocked by theclk
signal; as it is, your stimulus bits are 10 times the length of your clock period. \$\endgroup\$