【问题标题】:I am getting unknown value when doing a 4 bit shifter verilog (gate level)执行 4 位移位器 verilog(门级)时,我得到未知值
【发布时间】:2020-10-10 05:38:02
【问题描述】:

我正在尝试使用门级实现 4 位右移器,但由于某种原因我得到了未知的结果,我的多路复用器工作正常,但是当我为我的移位器尝试测试台时,它会返回如下内容:

a=0010 b=01 c=0000
a=1111 b=01 c=00xx

请帮忙!!!!非常感谢

module mux2(a,b,sel,c);
output c;
input a,b,sel;
wire net0,net1,net2;
not m1(net0,sel);
and m2(net1,a,net0);
and m3(net2,b,sel);
or m4(c,net1,net2);
endmodule
module mux4(a,sel,c);
output c;
input [1:0]sel;
input[3:0]a;
wire mux_1,mux_2;
mux2 m1(a[3],a[2],sel[0],mux_1);
mux2 m2(a[1],a[0],sel[0],mux_2);
mux2 m3(mux_1,mux_2,sel[1],c);
endmodule

module shift4bitright(c,a,b);
output [3:0]c;
input [3:0]a;
input [1:0]b;
wire [3:0]d=4'h0,d1=4'h0,d2=4'h0,d3=4'h0;
assign d[0]=a[3];
assign d1[0]=a[2]; assign d1[1]=a[3];
assign d2[0]=a[1]; assign d2[1]=a[2]; assign d2[2]=a[3];
assign d3[0]=a[0]; assign d3[1]=a[1];assign d3[2]=a[2];assign d3[3]=a[3];
mux4 m1(d,b,c[3]);
mux4 m2(d1,b,c[2]);
mux4 m3(d2,b,c[1]);
mux4 m4(d3,b,c[0]);
endmodule

`timescale 10ns/1ns
module shift4bitright_tb;
wire [3:0]c;
reg [3:0]a;
reg [1:0]b;
shift4bitright s1(.c(c),.a(a),.b(b));
initial begin
$monitor("a=%b b=%b c=%b",a,b,c);
a=4'h2;
b=2'd1;
#50
a=4'hf;
b=2'd1;
end
endmodule

【问题讨论】:

    标签: verilog system-verilog fpga modelsim


    【解决方案1】:

    这个语句声明了一个wire 类型的信号d 以及它的驱动锥(不是初始值),在这种情况下是一个常数0:

    wire [3:0]d=4'h0;
    

    就在它的下方,还有另一个a[3]在驾驶d[0]

    assign d[0]=a[3];
    

    这会创建一个多驱动逻辑,因此会出现x

    要解决它,将其更改为:

    wire [3:0] d;
    assign d = {3'h0, a[3]};
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-24
      • 1970-01-01
      • 1970-01-01
      • 2013-05-12
      相关资源
      最近更新 更多