如果声明在vhdl中没有按预期工作

时间:2014-11-04 00:04:30

标签: vhdl

以下是描述FSM的代码的一部分。

clk_process : process
  begin
wait until clk'event ;
if(clk ='0') then
  if( state = s2) then
  state <= nextstate;
  end if;
elsif clk='1' then
  state <= nextstate;
end if;  
end process clk_process;
即使clk =&#39; 0&#39;正在执行

state&lt; = nextstate语句,state = s2和clk事件已发生。 任何人都可以解释为什么这种奇怪的行为应该。我该做什么不能做我想做的事。

感谢名单

编辑1:

library ieee;
use ieee.std_logic_1164.all;

entity machine is
  port(clk : in std_logic; out1,out2 : out std_logic);
  end entity;

architecture behave of machine is
  type statetype is (s0,s1,s2,s3,s4);
  signal state,nextstate : statetype :=s0;
  begin    
--    nextstate<=s0;
  comb_process: process(state)
  begin
    case state is
    when s0 =>
      nextstate <= s1;
    when s1 =>
      nextstate <=s2;
      out1 <= '1';
      out2 <= '1';
    when s2 =>
      if(clk ='0') then
        nextstate <= s3;
        out2 <='1';
      else
        nextstate <=s2;
        out1<='0';
        out2<='0';
      end if;
    when s3 =>
      nextstate <= s4;
    when s4=>
      nextstate <= s1;
    end case;
  end process comb_process;
  clk_process : process
  begin
    wait until clk'event ;
    if(clk ='0') then
      if( state = s2) then
      state <= nextstate;
      end if;
    elsif clk='1' then
      state <= nextstate;
    end if;
  end process clk_process;
end behave;

这是我的完整代码。我想要做的是当状态是S2时它应该是正边缘和负边缘触发

1 个答案:

答案 0 :(得分:0)

您的代码问题似乎是您的状态机在state = s1nextstate = s2时会卡住。到达此时,下一个上升时钟沿将导致clk_process块更改state <= s2。这将导致您的comb_process块在clk = '1'时触发,从而导致nextstate <= s2state等于nextstate后,comb_process将永远不会再次触发。

如果您不关心FSM使用的状态位数,您可以简单地为每个时钟转换事件创建一个状态。