莫尔型状态机2.txt
上传用户:easylife05
上传日期:2013-03-21
资源大小:42k
文件大小:2k
源码类别:

VHDL/FPGA/Verilog

开发平台:

C/C++

  1. -- Moore State Machine with Concurrent Output Logic
  2. -- dowload from: www.fpga.com.cn & www.pld.com.cn
  3. library ieee;
  4. use ieee.std_logic_1164.all;
  5. entity moore1 is port(
  6.         clk, rst:       in std_logic;
  7.         id:             in std_logic_vector(3 downto 0);
  8.         y:              out std_logic_vector(1 downto 0));
  9. end moore1;
  10. architecture archmoore1 of moore1 is
  11.         type states is (state0, state1, state2, state3, state4);
  12.         signal state: states;
  13. begin
  14. moore: process (clk, rst)  --this process defines the next state only
  15.         begin
  16.                 if rst='1' then 
  17.                         state <= state0;
  18.                 elsif (clk'event and clk='1') then
  19.                         case state is
  20.                                 when state0 =>
  21.                                         if id = x"3" then
  22.                                                 state <= state1;
  23.                                         else
  24.                                                 state <= state0;
  25.                                         end if;
  26.                                 when state1 =>
  27.                                         state <= state2;
  28.                                 when state2 =>
  29.                                         if id = x"7" then
  30.                                                 state <= state3;
  31.                                         else
  32.                                                 state <= state2;
  33.                                         end if;
  34.                                 when state3 =>
  35.                                         if id < x"7" then 
  36.                                                 state <= state0;
  37.                                         elsif id = x"9" then
  38.                                                 state <= state4;
  39.                                         else
  40.                                                 state <= state3;
  41.                                         end if;
  42.                                 when state4 =>
  43.                                         if id = x"b" then
  44.                                                 state <= state0;
  45.                                         else
  46.                                                 state <= state4;
  47.                                         end if;
  48.                         end case;
  49.                 end if;
  50.         end process;
  51. --assign state outputs concurrently;
  52. y <= "00" when (state=state0) else
  53.      "10" when (state=state1 or state=state3) else
  54.      "11";
  55. end archmoore1;