📄 fsm.vhd
字号:
-------------------------------------------------------------------------------
-- --
-- Simple Cordic --
-- Copyright (C) 1999 HT-LAB --
-- --
-- Contact/Feedback : http://www.ht-lab.com/feedback.htm --
-- Web: http://www.ht-lab.com --
-- --
-------------------------------------------------------------------------------
-- --
-- This library is free software; you can redistribute it and/or --
-- modify it under the terms of the GNU Lesser General Public --
-- License as published by the Free Software Foundation; either --
-- version 2.1 of the License, or (at your option) any later version. --
-- --
-- This library is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- Lesser General Public License for more details. --
-- --
-- Full details of the license can be found in the file "copying.txt". --
-- --
-- You should have received a copy of the GNU Lesser General Public --
-- License along with this library; if not, write to the Free Software --
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --
-- --
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
ENTITY fsm IS
PORT(
clk : IN std_logic;
reset : IN std_logic; -- Active low reset
start : IN std_logic;
cnt : IN std_logic_vector (4 DOWNTO 0);
init : OUT std_logic;
load : OUT std_logic;
done : OUT std_logic);
END fsm ;
architecture synthesis of fsm is
type states is (s0,s1,s2,s3);
signal state,nextstate : states;
begin
Process (clk,reset) -- Process to create current state variables
begin
if (reset='0') then -- Reset State
state <= s0;
elsif (rising_edge(clk)) then
state <= nextstate; -- Set Current state
end if;
end process;
process(state,start,cnt)
begin
case state is
when s0 => -- Step 1 load regs
if start='1' then nextstate <= s1;
else nextstate <= s0; -- Wait for start signal
end if;
when s1 => -- latch result register
if cnt="11111" then nextstate <= s2; -- done
else nextstate <= s1; -- wait
end if;
when s2 =>
if start='0' then nextstate <= s0;
else nextstate <= s2; -- Wait for start signal
end if;
when others => nextstate <= s0;
end case;
end process;
process(state)
begin
case state is
when s0 =>done <= '0'; init <= '1'; load <= '0';
when s1 =>done <= '0'; init <= '0'; load <= '1';
when s2 =>done <= '1'; init <= '0'; load <= '0';
when others => done <= '-'; init <= '-'; load <= '-';
end case;
end process;
end synthesis;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -