Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于结构Verilog输出的移位寄存器设计_Verilog_Flip Flop_Mux - Fatal编程技术网

基于结构Verilog输出的移位寄存器设计

基于结构Verilog输出的移位寄存器设计,verilog,flip-flop,mux,Verilog,Flip Flop,Mux,我正在使用分层结构的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);

我正在使用分层结构的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

您的D_触发器模块中存在接线错误。当我模拟您的测试台时,我得到了编译器警告:

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

您缺少同步或异步的重置条件。您的触发器有一个未知值,并且永远不会达到已知状态,因为数据输入依赖于触发器输出。通过添加复位,可以将触发器置于与输出V/V_条无关的已知状态

在这种情况下,添加一个同步文件会更容易。只需添加一些2对1的多路复用器和一个新的复位引脚

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