微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Verilog垃圾输入不会导致垃圾输出

如何解决Verilog垃圾输入不会导致垃圾输出

我正在用verilog编写一个简单的控制单元。像这样。

module controlUnit(
    output reg  wreg,input  wire [5:0] op,func
);
    // wreg sub-handles. Beware: wreg is 0 if any of these s high
    wire isBranch = (op[5:3] == 3'b0) & (|op[2:0]); 
    wire isstrWrd = op == 6'b101011;
    wire isJumpReg = (op == 6'd0) & (func == 6'b001000);

    // wreg handle
    always @(*) begin
        if(isBranch | isstrWrd | isJumpReg) 
            wreg <= op == 6'b000011;
        else
            wreg <= 1'b1;
    end
endmodule

module testbench;
    integer i;
    wire out;
    reg [11:0] in;

    controlUnit CU0(
        .wreg(out),.op(in[11:6]),.func(in[5:0])
    );

    initial begin
        $dumpfile("test.vcd");
        $dumpvars(0,testbench);

        #4 in = 0;
        for(i=0; i<1024; i=i+1) begin
            #1 in = i;
        end
        #1 in = 10'hXX;    // Garbage input here
        #1000;
    end
endmodule

但是,在仿真中,当输入变为垃圾时,wreg信号为稳定的逻辑高电平。我已经在iverilog-10 / GTKwave和Vivado 2019.1。中看到了这种行为。以下是波形:

Garbage as input,but logic HIGH as output.

那为什么呢?

解决方法

您只需将12个输入位中的10个设置为UnwindOperation unwindOperation = Aggregation.unwind("barcodes"); ProjectionOperation projectStage = Aggregation.project() .and("_id").as("productId") .and("title").as("productTitle") .and("variation").as("productVariation") .and("barcodes.title").as("barcodeTitle") .and("barcodes.value").as("barcodeValue") .and("barcodes.type").as("barcodeType") .and("barcodes.codeStandard").as("codeStandard") .and("barcodes.quantity").as("quantity") .and("barcodes.status").as("status"); SortOperation sortOperation = Aggregation.sort(Sort.by(Sort.Direction.DESC,"productTitle")); Aggregation agg = Aggregation.newAggregation(unwindOperation,projectStage,sortOperation); AggregationResults<BarcodeAggregateList> results = mongoTemplate.aggregate(agg,"product",BarcodeAggregateList.class); ; 2个MSB为0。您应该将所有输入信号都设置为x。这可能与您的问题无关,但我认为这正是您的意图。更改:

x

收件人:

    #1 in = 10'hXX;    // Garbage input here

#1 in = {12{1'bx}}; // Garbage input here 中的信号为if(isBranch | isStrWrd | isJumpReg)时,x为假,并执行if,将else设置为1({{ 1}}),而不是wreg。这回答了以下问题:为什么在所有输入均为wreg <= 1'b1时,Verilog仿真器将x分配给1。这就是模拟器设计的工作方式。


当输入为wreg时,使用三进制运算符等效代码会将x设置为wreg

x

请注意,对于组合逻辑,建议使用阻塞分配(x)。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。