用VHDL设计一个双进程状态机

用VHDL设计一个双进程状态机,
状态0时如果输入“10”则转化为另一状态,否则输出‘1001’;
状态1时如果输入“11”则转化为下一状态,否则输出‘0101’;
状态2市如果输入“01”则转化为下一状态,否则输出‘1100’;
状态3时如果输入“00”则转化为状态0,否则输出'0010';
复位状态为0

VHDL设计一个双进程状态机,原程序如下(后面的图是仿真结果):

LIBRARY ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_arith.all;

use ieee.std_logic_unsigned.all;

entity dou_state is

port(clk,rst : in std_logic;

      din    : in std_logic_vector(1 downto 0);

      dout   : out std_logic_vector(3 downto 0));

end dou_state;

architecture arch of dou_state is

type state_type is (s0,s1,s2,s3);

signal state : state_type;

begin

P1: process(clk,rst)

begin

if rst='0' then

state <= s0;

dout  <= "0000";

elsif clk'event and clk='1' then

case state is

when s0 =>

   if din = "10" then

      state <= s1;

   else

      state <= s0;

      dout <= "1001";

   end if;

when s1 =>

   if din = "11" then

      state <= s2;

   else

      state <= s1;

      dout <= "0101";

   end if;

when s2 =>

   if din = "01" then

      state <= s3;

   else

      state <= s2;

      dout <= "1100";

    end if;

when s3 =>

   if din = "00" then

      state <= s0;

   else

      state <= s3;

      dout <= "0010";

   end if;

when others => 

   NULL;

end case;  

end if;

end process;   

end arch;

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-12-09
Library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use IEEE.std_logic_arith.all;

ENTITY S is
Port
(
clk : in std_logic;
rst_n : in std_logic;
data_in : in std_logic_vector(1 downto 0);
data_out : out std_logic_vector(3 downto 0)
);
end S;

architecture behav of S is

signal status : std_logic_vector(1 downto 0);

begin
process(clk,rst_n,data_in)
begin
if rst_n = '0' then
data_out <= "0000";
status <= "00";
else if clk'event and clk = '1' then
case status is
when "00" => if data_in = "10" then
status <= "01";
else
status <= "00";
data_out <= "1001";
end if;
when "01" => if data_in = "11" then
status <= "10";
else
status <= "01";
data_out <= "0101";
end if;
when "01" => if data_in = "01" then
status <= "11";
else
status <= "10";
data_out <= "1100";
end if;
when "00" => if data_in = "00" then
status <= "00";
else
status <= "11";
data_out <= "0010";
end if;
when others => status <= "00";
end case;
end if;
end if;
end process;
end behav;
相似回答