带莫尔_米勒输出的状态机.txt
上传用户:easylife05
上传日期:2013-03-21
资源大小:42k
文件大小:3k
源码类别:

VHDL/FPGA/Verilog

开发平台:

C/C++

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