状态机状态类型的定义与QuatUSii 能否综合出状态图的问题
library IEEE;use ieee.std_logic_1164.all;
entity test_moore_fsm is
port(
clk : instd_logic;
rst_n : instd_logic;
w_i : instd_logic;
z_o : out std_logic
);
end test_moore_fsm;
architecture rtl of test_moore_fsm is
--type state is (IDLE,S0,S1);
--signal curr_state,next_state :state;
constant IDLE:std_logic_vector (1 downto 0) := "00";
constant S0 :std_logic_vector (1 downto 0) := "01";
constant S1 :std_logic_vector (1 downto 0) := "10";
signal curr_state : std_logic_vector(1 downto 0);
signal next_state : std_logic_vector(1 downto 0);
begin
--state register
process(clk )
begin
if rising_edge(clk) then
if rst_n='0' then
curr_state <= IDLE;
else
curr_state <= next_state;
end if;
end if;
end process;
-- state change
process(curr_state)
begin
casecurr_state is
when IDLE =>
if w_i='1' then
next_state <= S0;
else
next_state <= IDLE;
end if;
when S0 =>
if w_i='1' then
next_state <= S1;
else
next_state <= IDLE;
end if;
when S1 =>
if w_i='1' then
next_state <= S1;
else
next_state <= IDLE;
end if;
when others => next_state <= IDLE;
end case;
end process;
-- state output
process(curr_state)
begin
casecurr_state is
when IDLE => z_o <= '0';
when S0 => z_o <= '0';
when S1 => z_o <= '1';
when others => z_o <= '0';
end case;
end process;
end rtl;
Quatus II 软件提供了状态图的查看 功能。如下图,当整体编译完成后,可以点击state machine viewer 进行查看 编写的状态机 是否正确。但如果编写VHDL状态的定义 不同时,Quatus II 是无法综合出状态图出来的。
以下比较几种状态 定义 的结果:
第一种:
constant IDLE:std_logic_vector (1 downto 0) := "00";
constant S0 :std_logic_vector (1 downto 0) := "01";
constant S1 :std_logic_vector (1 downto 0) := "10";
signal curr_state : std_logic_vector(1 downto 0);
signal next_state : std_logic_vector(1 downto 0);
状态定义为constant,而状态转换的变量又为signal ,结果综合就无法输出状态图,quatus II 将其视为普通信号赋值处理。当然RTL_viewer 还是可以实现的。
第二种:
type state is (IDLE,S0,S1);
signal curr_state,next_state :state;
此时我们觉得当状态类型与状态转换的中间量一致时,可以输出状态图
再看看第三种写法:
signal IDLE:std_logic;
signal S0 :std_logic;
signal S1 :std_logic;
signal curr_state: std_logic;
signal next_state: std_logic;
此时状态类型与状态转换的中间量一致,可是此时却无法输出状态图
而反过来查看编译报告的时候发现 能够输出的状态图的 显示 耗费了资源,
而不能输出的状态图的 显示 没有耗费资源,
所以看来用VHDL 写状态机,定义状态的类型还有特定的写法。但具体为什么还不清楚~~~
再参考参考 Verilog 的写法 ,它是能够输出状态图的
parameter IDLE = 2'b00;
parameter S0 = 2'b01;
parameter S1 = 2'b10;
reg curr_state;
reg next_state;
reg z_o;
其过程也是将一个 常数(应该等同VHDL 的constant吧) 赋值给一个寄存器(应该等同VHDL 的signal吧)这与第一种写法大体是一样的! 那为什么就输不出状态图呢?
希望高手指点~~~~
由于这里编辑的时候插图比较麻烦,我已经将其整理成一个word 文档 共享在附件中!!!有兴趣的可以看看
页:
[1]