【问题标题】:JK Flip Flop Debugging Iteration Limit error in VHDL ModelsimVHDL Modelsim中的JK触发器调试迭代限制错误
【发布时间】:2013-10-03 02:20:05
【问题描述】:

我正在为 modelsim 上的 jk-flip-flop 编写 vhdl 代码,当我尝试对其进行模拟时出现错误:错误:在时间 0 ns 达到迭代限制。

我不确定这意味着什么,但我已经查看了我的大部分源代码中的错误,但没有成功。谁能猜出问题出在哪里?

library ieee;
use ieee.std_logic_1164.all;


entity SRlatch is
port(S,R:in bit; Q : inout bit ; QN : inout bit := '1');
end SRlatch;

architecture structural of SRlatch is
begin
Q <=  S nand QN;
QN <= R nand Q;
end;


entity JKFlipFlopStruct is
port(J,K,clk : in bit ; Q : inout bit ; QN : inout bit);
end JKFlipFlopStruct;

architecture structural of JKFlipFlopStruct is

  component SRlatch is
   port(S,R:in bit; Q : inout bit ; QN : inout bit := '1');
  end component;

  signal J0,K0,J1,K1,J2,K2 : bit;

begin

  J0 <= not ( J and QN and clk) );
  K0 <= not ( K and Q and clk) );

  f1 : SRlatch port map ( J0,K0,J1,K1 );

  J2 <= not ( J1 and (not clk) );
  K2 <= not ( K1 and (not clk) );
  f2 : SRlatch port map ( J2,K2,Q,QN );

end structural;

[JK Flop 负边沿触发]

见图片:http://i.stack.imgur.com/J3m1J.gif

【问题讨论】:

    标签: vhdl


    【解决方案1】:

    正如 Russell 所说,这个错误通常表明 ModelSim 陷入了无限循环。在 VHDL 中,当一个信号被放置在敏感度列表中并且这个信号在这个过程中被改变时,就会发生这种情况。

    一个简单的例子:

    process (sig)
    begin
      sig <= not sig;
    end;
    

    您的问题也在这种情况下。但也有一些区别。

    1.对于任何并发的信号赋值语句,都有一个等价的过程语句,含义相同。(详见VHDL LRM 93 $9.5

    所以,在你的代码中,

    J0 <= not ( J and QN and clk) );  
    

    的简写符号
    process
    begin
       J0 <= not ( J and QN and clk) );
       wait on J, QN, clk;
    end process;
    

    process (J, QN, clk)
    begin
        J0 <= not ( J and QN and clk) );
    end process;
    

    其他并发语句同理。

    2。关于仿真周期(参见 VHDL LRM 93 $12.6.4 和Delta Delays
    在每个周期中,计算描述中所有信号的值。如果作为该计算的结果,在给定信号上发生了事件,则对该信号敏感的过程语句将恢复并作为模拟周期的一部分执行。

    在您的代码中:

    f2 : SRlatch port map ( J2,K2,Q,QN );
    

    这是等效的过程:

    process (J2, K2)
    begin
       Q <=  J2 nand QN;
       QN <= K2 nand Q; 
    end process;
    

    与其他进程一起构成无限循环。
    例如,

    the J-K Flip-Flop is stable @ 100 ns + 0 delta time
    J or K or clk changes       @ 100 ns + 0 delta time
    J0 or K0          \ ---
    J1 or K1              |__ cost several delta times
    J2 or K2              |   Suppose that Q changes @ 100 ns + 3 delta time
    Q or QN  changes  / ---     
    Then the value of K0 will change again!!
    This result in a infinite loop becase 100 ns + n delta time = 100 ns. Time never advanceds.
    

    解决方案:
    1.使您的设计成为一个顺序设计(即使用同步时钟)。

    process (clk)
    begin
        if (rising_edge(clk)) then
            -- signal assignment
        end if;
    end process;  
    

    2.使用延迟分配。所以,在 SRlatch.vhd 中,你应该写

    Q <=  S nand QN after 1 ns;
    QN <= R nand Q after 2 ns;
    

    非对称延迟用于确保QQN 先设置,然后反馈设置另一个。

    另请参考类似问题:Debugging Iteration Limit error in VHDL Modelsim

    【讨论】:

    • 如果您在 SRLatch 端口声明中删除对 QN 的默认预设,并使分配给 Q 和 QN 的两个延迟不对称,那么通过延迟分配,最短的延迟路径最终将被设置。没有分配中的不对称延迟,也没有默认预设 Q 和 QN 会不断地来回切换。这证明了亚稳态和克服它的一种方法。见SR latch,第三段。
    • @DavidKoontz 谢谢。我已经修改过了。
    【解决方案2】:

    迭代限制意味着你在设计中创建了一个反馈循环,你让模拟器很生气!它无法解决循环。

    使用时钟进程设置 J0 和 K0。

    jk_flippy_floppy : process (clk)
    begin
      if rising_edge(clk) then
         J0 <= not ( J and QN );
         K0 <= not ( K and Q  );
      end if;
    end process jk_flippy_floppy;
    

    【讨论】:

    • 尝试模拟您的 SR Latch 以查看您是否看到相同的错误。
    【解决方案3】:
    library ieee;
    use ieee.std_logic_1164.all;
    
    entity SRlatch is
      port(S,R:in bit; Q : inout bit := '0' ; QN : inout bit := '1');
    end SRlatch;
    
    architecture structural of SRlatch is
    begin
      Q <=  S nand QN;
      QN <= R nand Q;
    end structural;
    
    entity JKFlipFlopStruct is
      port(J,K,clk : in bit ; Q : inout bit ; QN : inout bit:= '1');
    end JKFlipFlopStruct;
    
    architecture structural of JKFlipFlopStruct is
    
      component SRlatch is
       port(S,R:in bit; Q : inout bit ; QN : inout bit := '1');
      end component;
    
      signal J1 : bit;
      signal J0,K0,K1,J2,K2 : bit:= '1';
    
    begin
    
      J0 <= not ( J and QN and (not clk) );
      K0 <= not ( K and Q and (not clk) );
    
      f1 : SRlatch port map ( J0,K0,J1,K1 );
    
      J2 <= not ( J1 and clk );
      K2 <= not ( K1 and clk );
    
      f2 : SRlatch port map ( J2,K2,Q,QN );
    
    end structural;
    

    这是正确的代码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多