2013-10-01 31 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; 

這是正確的代碼