【问题标题】:How to get rid of the error <variableName> is not constant while trying to do simple number comparison?如何在尝试进行简单的数字比较时摆脱错误 <variableName> is not constant?
【发布时间】:2022-01-20 22:45:24
【问题描述】:

我是 SystemVerilog 和 Basys3 的新手。我正在尝试学习七段显示。为此,我编写了一个简单的演示:

1- Take input from switches
2- From that Input, decide which seven segment output will be used with comparing numbers
3- Display on the seven segment display.

你可以看到我的代码。

module SevenSegmentNumber(input logic[3:0] inputFile, output logic [6:0] outputFile);
    
    if (inputFile == 3'b000) begin
        assign outputFile[6] = 0;
        assign outputFile[5] = 0;
        assign outputFile[4] = 0;
        assign outputFile[3] = 0;
        assign outputFile[2] = 0;
        assign outputFile[1] = 0;
        assign outputFile[0] = 1;
    end
    
    else if (inputFile == 3'b001) begin
            assign outputFile[6] = 1;
            assign outputFile[5] = 0;
            assign outputFile[4] = 0;
            assign outputFile[3] = 1;
            assign outputFile[2] = 1;
            assign outputFile[1] = 1;
            assign outputFile[0] = 1;
    end
    
    else if (inputFile == 3'b010) begin
            assign outputFile[6] = 0;
            assign outputFile[5] = 0;
            assign outputFile[4] = 1;
            assign outputFile[3] = 0;
            assign outputFile[2] = 0;
            assign outputFile[1] = 1;
            assign outputFile[0] = 0;
    end
endmodule

assign outputFile[n]是根据我在网上找到的七段显示是如何工作的硬编码的。

我的问题是 我无法比较输入文件是否等于 0 或 1 或 2

错误信息是:

inputFile 不是常量

我也尝试过用表单编码

inputFile == 0
inputFile == 1
inputFile == 2

这并没有解决我的问题。我该如何解决这个问题?

【问题讨论】:

    标签: verilog system-verilog fpga


    【解决方案1】:

    您的错误消息通知您inputFile 输入端口不能以这种方式使用,因为它是一个变量类型。您的代码看起来像是在使用隐式 generate 构造,它要求 inputFile 是常量类型,例如 parameter

    修复代码的一种方法是将if/else 语句放在程序块中。由于您描述的是组合逻辑,您可以使用always_comb。在这种情况下,不需要使用assign 关键字。

    module SevenSegmentNumber(input logic[3:0] inputFile, output logic [6:0] outputFile);
        
    always_comb begin
        outputFile = '0;
    
        if (inputFile == 3'b000) begin
            outputFile[6] = 0;
            outputFile[5] = 0;
            outputFile[4] = 0;
            outputFile[3] = 0;
            outputFile[2] = 0;
            outputFile[1] = 0;
            outputFile[0] = 1;
        end
        
        else if (inputFile == 3'b001) begin
            outputFile[6] = 1;
            outputFile[5] = 0;
            outputFile[4] = 0;
            outputFile[3] = 1;
            outputFile[2] = 1;
            outputFile[1] = 1;
            outputFile[0] = 1;
        end
        
        else if (inputFile == 3'b010) begin
            outputFile[6] = 0;
            outputFile[5] = 0;
            outputFile[4] = 1;
            outputFile[3] = 0;
            outputFile[2] = 0;
            outputFile[1] = 1;
            outputFile[0] = 0;
        end
    end
    
    endmodule
    

    请注意,我在块的顶部将 outputFile 初始化为 0。这避免了在合成时推断锁存器。您可以将 0 更改为对您的设计更有意义的东西(当输入不是 0、1 或 2 时,无论您的逻辑应该做什么)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-13
      • 2022-12-07
      • 1970-01-01
      • 2016-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多