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

VHDL/FPGA/Verilog

开发平台:

C/C++

  1. -- Mealy State Machine with Registered 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.         y:              out std_logic_vector(1 downto 0));
  9. end mealy1;
  10. architecture archmealy of mealy1 is
  11.         type states is (state0, state1, state2, state3, state4);
  12.         signal state: states;
  13. begin
  14. moore: process (clk, rst) 
  15.         begin
  16.                 if rst='1' then 
  17.                         state <= state0;
  18.                         y <= "00";
  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.                                                 y <= "10";
  25.                                         else
  26.                                                 state <= state0;
  27.                                                 y <= "00";
  28.                                         end if;
  29.                                 when state1 =>
  30.                                         state <= state2;
  31.                                         y <= "11";
  32.                                 when state2 =>
  33.                                         if id = x"7" then
  34.                                                 state <= state3;
  35.                                                 y <= "10";
  36.                                         else
  37.                                                 state <= state2;
  38.                                                 y <= "11";
  39.                                         end if;
  40.                                 when state3 =>
  41.                                         if id < x"7" then 
  42.                                                 state <= state0;
  43.                                                 y <= "00";
  44.                                         elsif id = x"9" then
  45.                                                 state <= state4;
  46.                                                 y <= "11";
  47.                                         else
  48.                                                 state <= state3;
  49.                                                 y <= "10";
  50.                                         end if;
  51.                                 when state4 =>
  52.                                         if id = x"b" then
  53.                                                 state <= state0;
  54.                                                 y <= "00";
  55.                                         else
  56.                                                 state <= state4;
  57.                                                 y <= "11";
  58.                                         end if;
  59.                         end case;
  60.                 end if;
  61.         end process;
  62. end archmealy;