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

VHDL/FPGA/Verilog

开发平台:

C/C++

  1. -- Moore State Machine with explicit state encoding
  2. -- dowload from: www.fpga.com.cn & www.pld.com.cn
  3. library ieee;
  4. use ieee.std_logic_1164.all;
  5. entity moore2 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 moore2;
  10. architecture archmoore2 of moore2 is
  11.         signal state: std_logic_vector(2 downto 0);
  12. -- State assignment is such that 2 LSBs are outputs
  13. constant state0: std_logic_vector(2 downto 0) := "000";
  14. constant state1: std_logic_vector(2 downto 0) := "010";
  15. constant state2: std_logic_vector(2 downto 0) := "011";
  16. constant state3: std_logic_vector(2 downto 0) := "110";
  17. constant state4: std_logic_vector(2 downto 0) := "111";
  18. begin
  19. moore: process (clk, rst) 
  20.         begin
  21.                 if rst='1' then 
  22.                         state <= state0;
  23.                 elsif (clk'event and clk='1') then
  24.                         case state is
  25.                                 when state0 =>
  26.                                         if id = x"3" then
  27.                                                 state <= state1;
  28.                                         else
  29.                                                 state <= state0;
  30.                                         end if;
  31.                                 when state1 =>
  32.                                         state <= state2;
  33.                                 when state2 =>
  34.                                         if id = x"7" then
  35.                                                 state <= state3;
  36.                                         else
  37.                                                 state <= state2;
  38.                                         end if;
  39.                                 when state3 =>
  40.                                         if id < x"7" then 
  41.                                                 state <= state0;
  42.                                         elsif id = x"9" then
  43.                                                 state <= state4;
  44.                                         else
  45.                                                 state <= state3;
  46.                                         end if;
  47.                                 when state4 =>
  48.                                         if id = x"b" then
  49.                                                 state <= state0;
  50.                                         else
  51.                                                 state <= state4;
  52.                                         end if;
  53.                                 when others =>
  54.                                         state <= state0;
  55.                         end case;
  56.                 end if;
  57.         end process;
  58. --assign state outputs (equal to state std_logics)
  59. y <= state(1 downto 0);
  60. end archmoore2;