State Diagram
State Diagram
AIM:
To design a finite string recognizer which has an output z. the output is asserted whenever the
sequence …010…is recorded , as long as …100..is not seen.
DESIGN:
A sequence recognizer checks for a particular sequence and gives an output accordingly.
This design checks for z sequences and the program terminates once ‘100’ is detected. The
state diagram and state table are drawn. code is written in vhdl module.
STATE DIAGRAM:
SSSSS
So/
sssSS
0
0 SSS 1
SSSSS
S1/ SSSSS
S4/
sssSS
0 sssSS 1
0
SSS SSS
1
0
1
SSSSS
S2/ SSSSS
S5/
sssSS
0 sssSS
0
SSS SSS
SSSSS
S3/ SSSSS
S6/
sssSS
1 sssSS
0 1/0
SSS SSS
STATE TABLE:
PRESENTSTATE NEXTSTATE OUTPUT
A B C
X=0 A BX=1 C A X=0 B C X=1
0 0 0 0 0 0 1 0 0 0 0
0 0 1 0 0 1 0 1 0 0 0
0 1 0 0 1 1 1 0 0 0 1
0 1 1 1 1 0 0 1 0 0 0
1 0 0 1 1 0 1 0 0 0 0
1 0 1 1 1 0 0 1 0 0 0
1 1 0 1 1 0 1 1 0 0 0
1 1 1 d d d d d d d d
library IEEE;
use IEEE.std_logic_1164.all;
entity string_detector is
Port ( x,clk : in STD_LOGIC;
y : out STD_LOGIC);
end string_detector;
begin
process(x,clk)
variable a: std_logic_vector (2 downto 0) :="000";
variable b: std_logic:='1';
variable c: std_logic:='0';
begin
c:='0';
if a="010" then
c:='1';
end if;
if a="100" then
b:='0';
end if;
y<=b and c;
end process;
end Behavioral;
library IEEE;
use IEEE.std_logic_1164.all;
--use std.env.finish;
entity testbench is
end entity testbench;
architecture tb of testbench is
component string_detector is
port(
x,clk: in std_logic;
y: out std_logic);
end component;
begin
process
begin
clk<='1';
a_in <='0'; wait for 10ns;
--assert (q_out='0') report to_string(q_out) severity note;
clk<='0'; wait for 1ns;
clk<='1';
a_in <='1' ; wait for 10ns;
-- assert (q_out='0') report to_string(q_out) severity note;
clk<='0'; wait for 1ns;
clk<='1';
a_in <= '0' ; wait for 10ns;
-- assert (q_out='1') report to_string(q_out) severity note;
clk<='0'; wait for 1ns;
clk<='1';
a_in <= '1' ; wait for 10ns;
-- assert (q_out='1') report to_string(q_out) severity note;
clk<='0'; wait for 1ns;
clk<='1';
a_in <= '1' ; wait for 10ns;
-- assert (q_out='1') report to_string(q_out) severity note;
clk<='0'; wait for 1ns;
clk<='1';
a_in <= '0' ; wait for 10ns;
-- assert (q_out='1') report to_string(q_out) severity note;
clk<='0'; wait for 1ns;
clk<='1';
a_in <= '1' ; wait for 10ns;
--assert (q_out='1') report to_string(q_out) severity note;
clk<='0'; wait for 1ns;
clk<='1';
a_in <= '0' ; wait for 10ns;
-- assert (q_out='0') report to_string(q_out) severity note;
clk<='0'; wait for 1ns;
clk<='1';
a_in <= '0' ; wait for 10ns;
-- assert (q_out='0') report to_string(q_out) severity note;
clk<='0'; wait for 1ns;
clk<='1';
-- assert (false) report "Test done." severity note;
wait for 10ns ;
--finish;
end process;
end tb;
OUTPUT: