data_input_1信号在在S3的情况下过早为0,会导致current_state不让培能进入S4状态.data_input_1必须值到下一个时钟周期开始时也为1,保证next_state最终为S4,这样才能在上升沿加载到current_state寄存器中,因此这个设计对于前导码之后第1位为0是失效的,第一位为1则可以运行,你可以做个实验验证一下.
解决方案:用个寄存器先对输入信号同步采样一下.
VHDL设计一拆做个双进程状态机,原程序如下(后面的图是仿真结果):
LIBRARY ieee
use ieee.std_logic_1164.all
use ieee.std_logic_arith.all
use ieee.std_logic_unsigned.all
entity dou_state is
port(clk,rst : in std_logic
din : in std_logic_vector(1 downto 0)
dout : out std_logic_vector(3 downto 0))
end dou_state
architecture arch of dou_state is
type state_type is (s0,s1,s2,s3)
signal state : state_type
begin
P1: process(clk,rst)
begin
if rst='0' then
state <= s0
dout <= "0000"
elsif clk'event and clk='1' then
case state is
when s0 =>
if din = "10" then
state <= s1
else
state <= s0
dout <= "1001"
end if
when s1 =>
if din = "11" then
state <= s2
else
state <= s1
dout <= "0101"
脊御扮end 樱灶if
when s2 =>
if din = "01" then
state <= s3
else
state <= s2
dout <= "1100"
end if
when s3 =>
if din = "00" then
state <= s0
else
state <= s3
dout <= "0010"
end if
when others =>
NULL
end case
end if
end process
end arch
elsestate <= Idle
dataout<=0
else后面两条语察吵磨句就要败斗碰猜用begin end
else begin
state <= Idle
dataout<=0
end
这样才对
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)