📄 state_graph.vhd
字号:
library ieee;
use ieee.std_logic_1164.all;
entity state_graph is
port(
st:in std_logic;
--连接到外部输入信号,st=‘1’表示命令开始运算
clk:in std_logic;
--连接时钟输入信号
overflow:out std_logic;
--连接到外部输出信号,overflow=‘1’表示溢出
load:out std_logic;
--输出信号,控制mux18_9
c:in std_logic;
--输入信号,由diag_c模块产生。只在状态1时使用,从而决定这个除法是否溢出。
diag,su_en, sh_en:out std_logic;
--这四个输出信号是在外部时钟的上升沿时产生的,且是顺序产生的。它们的作用是使判断、相减和移位按顺序执行。
isover:out std_logic);
--通知外部,整个除法运算进行完,取出商和余数
end state_graph;
architecture behavioral of state_graph is
signal state :integer range 0 to 5;
--表示状态,状态0,1,2 ,3,4,5
signal input:std_logic;
--内部信号送到移位寄存器srg,作用:输入为1时新的状态开始
signal update:std_logic;
--表示一个状态的结束,在时钟上升沿的到来进入下个状态
component srg4
--移位寄存器srg的声明。
port(clk:in std_logic;
input:in std_logic;
diag,su_en,sh_en,update:out std_logic);
end component;
begin
state_m:process(clk,state,st,c,update)
begin
if clk'event and clk='1' then
--时钟上升沿执行状态的转换
case state is
when 0=>
if(st='1') then load<='1';state<=1;input<='1';
else state<=0;input<='0';
end if;
--状态0,st=‘1’时开始进入下个状态
when 1=>isover<='0';load<='0';
if(c='1')then state<=0;overflow<='1';
end if;
if(c='0') then
if update='1' then state<=2;input<='1';else state<=1;input<='0'; end if;
end if;
--状态1,只有在update=‘1’才进入状态2。
when 2|3|4=>isover<='0';load<='0';
if update='1' then state<=state+1;input<='1';else input<='0';end if;
--状态2,3,4,
when 5=>load<='0';
if update='1' then input<='0';isover<='1';state<=0;else input<='0';isover<='0';end if;
--状态5
when others =>null;
end case;
end if;
end process state_m;
u1:srg4 port map(clk,input,diag,su_en,sh_en,update);
--口映射srg, 它的作用是规定比较、相减和移位的时间顺序,还有状态的改变不能相减的前面。
end behavioral;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -