module encoder (op, in, clock, reset);
//$display("We are in initial procedural block");
input [15:0] in;
input clock, reset;
output [3:0] op;
wire [15:0] in;
wire clock, reset;
reg [3:0] op;
always @ ( posedge clock)
begin
$display("We are in initial procedural block");
if (reset)
begin
$display("we are in the reset condition");
op = 0;
end
else
begin
case(in)
16'h0002: #1 op = 4'b0001;
16'h0004: #1 op = 4'b0010;
16'h0008: #1 op = 4'b0011;
16'h0010: #1 op = 4'b0100;
16'h0012: #1 op = 4'b0101;
16'h0014: #1 op = 4'b0110;
16'h0018: #1 op = 4'b0111;
16'h0020: #1 op = 4'b1000;
16'h0022: #1 op = 4'b1001;
16'h0024: #1 op = 4'b1010;
16'h0028: #1 op = 4'b1011;
16'h0030: #1 op = 4'b1100;
16'h0032: #1 op = 4'b1101;
16'h0034: #1 op = 4'b1110;
16'h0038: #1 op = 4'b1111;
16'h0040: #1 op = 4'b0000;
default : $display("DEFAULT!!!");
endcase
end
end
endmodule
module encoder_tb;
input in, reset, clock;
output op;
reg [15:0] in = 16'h0000;
reg reset, clock;
wire [3:0] op;
//internal variable
reg [15:0] incremental_value = 16'h0002;
initial
begin
$monitor("time = %g,\tclock = %d,\tin = %h,\top = %b",
$time, reset, in, op );
$display("We are in initial procedural block");
in = 0;
reset = 0;
clock = 0;
op = 0;
#1 clock = !clock;
#10 reset = !reset;
#5 in = in + incremental_value;
#100 $finish;
end
always
begin
#1 clock = !clock;
#10 reset = !reset;
#5 in = in + incremental_value;
end
encoder_tb test_bench ( .op(op), .in(in), .clock(clock), .reset(reset) );
// Waveform Generation
initial
begin
$dumpfile("encoder.vcd");
$dumpvars(0,op,in,clock,reset);
end
endmodule
我试图创建一个 16 位输入到 4 位输出编码器。我能够编译我的代码而没有任何错误,但是在 [ iverilog encoder_tb.v -o encoder
] & [ vvp encoder vcd
] 命令之后,即使我已经给出$monitor
了$display
任何我能想到的语句,它也没有给我任何东西。我无法调试这个。