1

我正在使用分层结构 Verilog 设计一个移位寄存器。我设计了一个 D 触发器和一个使用 3 个选择输入的 8 比 1 多路复用器。我试图将它们放在一起以获得完整的移位寄存器,但无论选择输入如何,我的输出都只给出“XXXX”。

触发器代码

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

两者的层次结合

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

关于可能会破坏我的输出的任何想法?输出是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
4

2 回答 2

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);   
于 2014-03-04T21:47:09.920 回答
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]);
// ...
于 2014-03-05T00:03:36.587 回答