Verilog程序帮助2x4解码器
Verilog program help 2x4 decoder
我是 verilog 的新手,正在尝试使用数组对此图进行编码。
2x4 图
到目前为止我有这个,但我没有得到我正在寻找的输出。
module DecoderMod(s, o); // module definition
input [0:1] s;
output [0:1] o;
wire [0:1] snot;
not(snot[1], s1);
not(snot[0], s0);
and(o[0], snot[1], snot[0]);
and(o[1], snot[1], s[0]);
and(o[2], s[1] , snot[0]);
and(o[3], s[1] , s[0]);
endmodule
module TestMod;
reg [0:1] s;
wire [0:3] o;
DecoderMod my_decoder(s, o); // create instance
initial begin
$monitor("%0d\t%b\t%b", $time, s, o);
$display("Time s o");
$display("--------------");
end
initial begin
s[1] = 0; s[0] = 0;#1;
s[1] = 0; s[0] = 1;#1;
s[1] = 1; s[0] = 0;#1;
s[1] = 1; s[0] = 1;
end
endmodule
我明白了:
Time s o
--------------------
0 00 x000
1 01 xx00
2 10 x0x0
3 11 xxx1
但我想要这个:
Time s o
--------------------
0 00 1000
1 01 0100
2 10 0010
3 11 0001
我做错了什么?
您在 not
实例中使用 s0
和 s1
,它们应该是:
not(snot[1], s[1]);
not(snot[0], s[0]);
我是 verilog 的新手,正在尝试使用数组对此图进行编码。
2x4 图
到目前为止我有这个,但我没有得到我正在寻找的输出。
module DecoderMod(s, o); // module definition
input [0:1] s;
output [0:1] o;
wire [0:1] snot;
not(snot[1], s1);
not(snot[0], s0);
and(o[0], snot[1], snot[0]);
and(o[1], snot[1], s[0]);
and(o[2], s[1] , snot[0]);
and(o[3], s[1] , s[0]);
endmodule
module TestMod;
reg [0:1] s;
wire [0:3] o;
DecoderMod my_decoder(s, o); // create instance
initial begin
$monitor("%0d\t%b\t%b", $time, s, o);
$display("Time s o");
$display("--------------");
end
initial begin
s[1] = 0; s[0] = 0;#1;
s[1] = 0; s[0] = 1;#1;
s[1] = 1; s[0] = 0;#1;
s[1] = 1; s[0] = 1;
end
endmodule
我明白了:
Time s o
--------------------
0 00 x000
1 01 xx00
2 10 x0x0
3 11 xxx1
但我想要这个:
Time s o
--------------------
0 00 1000
1 01 0100
2 10 0010
3 11 0001
我做错了什么?
您在 not
实例中使用 s0
和 s1
,它们应该是:
not(snot[1], s[1]);
not(snot[0], s[0]);