带同步复位的状态机.txt
上传用户:easylife05
上传日期:2013-03-21
资源大小:42k
文件大小:1k
源码类别:

VHDL/FPGA/Verilog

开发平台:

C/C++

  1. -- State Machine with Asynchronous Reset
  2. -- dowload from: www.fpga.com.cn & www.pld.com.cn
  3. library ieee;
  4. use ieee.std_logic_1164.all;
  5. entity stmch1 is
  6.     port(clk, in1, rst: in std_logic; out1: out std_logic);
  7. end stmch1;
  8. architecture behave of stmch1 is
  9.     type state_values is (sx, s0, s1);
  10.     signal state, next_state: state_values;
  11. begin
  12.  process (clk, rst)
  13.  begin
  14.         if rst = '1' then
  15.          state <= s0;
  16.         elsif rising_edge(clk) then
  17.             state <= next_state;
  18.         end if;
  19.  end process;
  20. process (state, in1)
  21.     begin
  22.         -- set defaults for output and state
  23.         out1 <= '0';
  24.        next_state <= sx; -- catch missing assignments to next_state
  25.         case state is
  26.             when s0 =>
  27.                 if in1 = '0' then
  28.                     out1 <='1';
  29.                     next_state <= s1;
  30.                 else
  31.                     out1 <= '0';
  32.                     next_state <= s0;
  33.                 end if;
  34.             when s1 =>
  35.                 if in1 = '0' then
  36.                     out1 <='0';
  37.                     next_state <= s0;
  38.                 else
  39.                     out1 <= '1';
  40.                     next_state <= s1;
  41.                 end if;
  42.             when sx =>
  43.                     next_state <= sx;
  44.             end case;
  45.         end process;
  46. end behave;