2014-03-04 78 views
-1

我正在設計使用分層結構化Verilog的移位寄存器。我設計了一個D觸發器,以及一個使用3個選擇輸入的8至1多路複用器。現在我試圖將它們放在一起以獲得完整的移位寄存器,但是不管選擇輸入如何,我的輸出只會給出「XXXX」。使用結構化Verilog的移位寄存器設計

我想我對自己在做什麼有正確的想法,但是我的verilog中肯定有錯誤。這裏是我有:

翻轉的FIp代碼

module D_Flip_Flop(
input D, 
input clk, 
output Q, Q_bar 
); 

wire a,b,c,d; 

nand(a,D,b); 
nand(b,a,clk,d); 
nand(c,a,d); 
nand(d,c,clk); 
nand(Q,d,Q_bar); 
nand(Q_bar,b,Q); 

endmodule 

8至1個多路複用器的兩個

module shiftRegister_struct(
input clk, 
input [2:0]S, 
input [3:0]L, 
output reg [3:0]V 
); 

wire a,b,c,d; 
wire V_bar[3:0]; 

Mux8to1 stage3(S[2:0],V[3],V[0],V[2],1'b0,V[2],V[3],V[2],L[3],a); 
Mux8to1 stage2(S[2:0],V[2],V[3],V[1],V[3],V[1],V[3],V[1],L[2],b); 
Mux8to1 stage1(S[2:0],V[1],V[2],V[0],V[2],V[1],V[2],V[1],L[1],c); 
Mux8to1 stage0(S[2:0],V[0],V[1],V[3],V[1],1'b0,V[1],1'b0,L[0],d); 

D_Flip_Flop stage3b(a,clk,V[3],V_bar[3]); 
D_Flip_Flop stage2b(b,clk,V[2],V_bar[2]); 
D_Flip_Flop stage1b(c,clk,V[1],V_bar[1]); 
D_Flip_Flop stage0b(d,clk,V[0],V_bar[0]); 

end module 

任何思考什麼可能被擰

module Mux8to1(
input [2:0]S, 
input A,B,C,D,E,F,G,H, 
output Out 
); 

wire a,b,c,d,e,f,g,h; 

and(a, A,~S[2],~S[1],~S[0]); 
and(b, B,~S[2],~S[1],S[0]); 
and(c, C,~S[2],S[1],~S[0]); 
and(d, D,~S[2],S[1],S[0]); 
and(e, E,S[2],~S[1],~S[0]); 
and(f, F,S[2],~S[1],S[0]); 
and(g, G,S[2],S[1],~S[0]); 
and(h, H,S[2],S[1],S[0]); 

or(Out, a,b,c,d,e,f,g,h); 


endmodule 

分層組合我的輸出?輸出是V [3:0]。

謝謝!

編輯:

我還應該包括我的測試臺代碼:

module Shift_Test_Bench; 

// Inputs 
reg [2:0] S; 
reg [3:0] L; 
reg clk; 

integer i; 
integer j; 

// Outputs 
wire [3:0] V; 

// Instantiate the Unit Under Test (UUT) 
shiftRegister_struct uut (
    .clk(clk), 
    .S(S), 
    .L(L), 
    .V(V) 
); 

initial begin 
    // Initialize Inputs 
    S = 7; 
    L = 3; 
    clk = 1; 


    // Wait 100 ns for global reset to finish 
    #100; 

    // Add stimulus here 

    for(i = 0; i < 16; i = i+1) 
    begin 
     S = i; 

     for(j = 0; j < 2; j = j+1) 
      begin 
      clk = !clk; 
      #5; 
      end 

    end 




end 

endmodule 
+0

你得到了你的答案,然後你「刪除」這個問題?爲什麼? – nguthrie

回答

0

你有你的D_Flip_Flop模塊中的接線錯誤。當我模擬測試平臺的,我得到了編譯器警告:

Implicit wire 'f' does not have any driver, please make sure this is 
    intended. 

    Implicit wire 'e' does not have any driver, please make sure this is 
    intended. 

下面是幾行:

nand(Q,d,f); 
nand(Q_bar,b,e); 
+0

好抓!現在f已被替換爲Q_bar,並且e已被替換爲Q.我可以使用模塊輸出變量作爲輸入和函數嗎? – Riley

+0

將模塊輸出信號連接到模塊內的nand實例輸入是合法的。 – toolic

+0

好吧,我修正了那個問題,但我仍然得到我的變量的所有XXXX輸出... – Riley

0

你缺少一個復位條件,同步或異步的。你的觸發器有一個未知的值,並且從未達到已知狀態,因爲數據輸入取決於觸發器的輸出。通過添加復位可以將觸發器置於與其輸出無關的已知狀態(V/V_bar)。

在這種情況下,添加同步更容易。只需添加一些2對1複用器和一個新的復位引腳。

Mux2to1 syncrst3(a_d,a,1'b0,reset); 
// ... 
D_Flip_Flop stage3b(a_d,clk,V[3],V_bar[3]); 
// ...