-1

我的 2x4 解码器代码:

`timescale 1ns/100ps
module decoder(in,out);
   input [1:0]in;
    output [3:0]out;
    reg [3:0]out;
always@(in)
    begin

            case(in)
                2'b00:out = 4'b0001;
                2'b01:out = 4'b0010;
                2'b10:out = 4'b0100;
                2'b11:out = 4'b1000;


                default:out = 4'b1111;
        endcase


        end
    endmodule

// **我已经为 2x4 解码器和测试台编写了行为代码。我在输出中看到的只是它在 11 处显示输出......这是 0011。我希望在输入发生变化时看到输出不断变化。

can any body show my mistake ??**

一段代码//

 `timescale 1ns / 100ps


        module decoder_t;

          reg [1:0]in;
          wire [3:0] out;



    decoder decoder1 ( .in(in),.out(out) );

    initial 
       begin

    #10 in=2'b00;
    #10 in=2'b01;
    #10 in=2'b10;
    #10 in=2'b11;


    #10 $stop;

       end

    endmodule
4

1 回答 1

2

Verilog 按预期运行。最好的猜测是用户正在观察 and 的值inout不是$stop之前的值。我的建议是添加一个$monitor声明来报告值的变化。

例如,在测试台中添加$monitor("%t: in:%b out:%b", $realtime, in, out);之前#10 in=2'b00;。然后日志文件将包括以下内容:

     0: in:xx out:xxxx
   100: in:00 out:0001
   200: in:01 out:0010
   300: in:10 out:0100
   400: in:11 out:1000

更新:波形转储

假设您要转储到所有版本的 IEEE Std 1364 和 IEEE Std 1800 中定义的标准值更改转储 (VCD) 文件。$dumpfile("dump.vcd"); $dumpvars;在驱动激励之前添加(即在 之前#10 in=2'b00;)。请参阅 IEEE Std 1364-1995 第 15 节(第 18 节了解 IEEE 1364 的较新版本)或IEEE Std 1800-2012(可从 IEEE 免费获得)第 21.7 节,了解所有$dump*系统任务的使用情况。

如果您使用不同的工具生成波形,请参阅手册。97% 的机会在驱动刺激之前需要调用系统任务的放置,就像$dumpvars$monitor.

于 2013-07-02T16:48:49.763 回答