2013-10-01 34 views
1

我正在为modelsim上的jk触发器编写vhdl代码,并且当我尝试模拟它时出现错误:错误:在时间0 ns时达到迭代限制。JK触发器在VHDL中调试迭代极限错误Modelsim

我不确定它是什么意思,但我已经查看了很多我的源代码中的错误没有成功。任何人都可以猜测问题可能是什么?

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触发器触发器下降沿触发]

看到图像:http://i.stack.imgur.com/J3m1J.gif

回答

0

迭代限制意味着你已经在你的设计创造了一个反馈环路和您所做的模拟器很生气!它无法解决循环。

使用定时过程来设置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; 
+0

请参阅图像 –

+0

尝试模拟JUST您的SR锁存器,看看您是否看到同样的错误。 – Russell

1

正如罗素所说,这个错误通常表明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
在eacy周期,在说明书的所有信号的值被计算。如果由于计算的结果在给定信号上发生事件,则传递给该信号的过程语句将恢复并将作为模拟周期的一部分执行。

在您的代码:

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. 

解决方案:
词根记忆你的设计顺序一个(即使用一个共时的时钟)。

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

+1

如果您在SRLatch端口声明中删除默认预设为QN并延迟分配给Q和QN的两个延迟不对称,则延迟分配的最短延迟路径最终将被设置。没有分配中的不对称延迟并且没有默认预设Q和QN将不断地来回切换。这证明亚稳态和克服它的一种方法。参见[SR闩锁](http://en.wikibooks.org/wiki/Digital_Circuits/Latches#SR_latch)第三段。 – user1155120

+0

@DavidKoontz谢谢。我修改了它。 – 2013-10-01 23:49:07

0
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; 

这是正确的代码