为什么我的代码总是触发case语句中的默认条件?

问题描述 投票:0回答:1

我正在学习 Verilog 并尝试构建一个 32 位 Galois LFSR,抽头位于位位置 32、22、2 和 1。

这是我的代码:

module top_module(
    input clk,
    input reset,    // Active-high synchronous reset to 32'h1
    output [31:0] q
); 
    always @(posedge clk) begin
        if (reset)
            q <= 32'h1;
        else begin
            integer i;
            for (i=0; i<32; i=i+1) begin
                case (i)
                    0 : q[i] <= q[0] ^ q[i+1];
                    1 : q[i] <= q[0] ^ q[i+1];
                    21 : q[i] <= q[0] ^ q[i+1];
                    31 : q[i] <= q[0];
                    default : q[i] <= q[i+1];
                endcase
            end
        end
    end
endmodule

我面临以下错误:

Error (10232): Verilog HDL error at top_module.v(17): index 32 cannot fall outside the declared range [31:0] for vector "q" File: /home/h/work/hdlbits.14205831/top_module.v Line: 17

很可能是因为,当 i=31 时,它会触发

case
语句的默认条件,但它不应该这样做,因为我已经为此创建了一个单独的条件。

有人可以告诉我我做错了什么吗?

我粘贴HDLBits网页链接: https://hdlbits.01xz.net/wiki/Lfsr32

case verilog hdl
1个回答
0
投票

Verilog 代码很好。 HDLBits 网站使用的工具有一个错误:

Info: *******************************************************************
Info: Running Quartus Prime Shell
    Info: Version 20.1.1 Build 720 11/11/2020 SJ Lite Edition
    Info: Copyright (C) 2020  Intel Corporation. All rights reserved.

您可以尝试在联系页面上将此问题报告为错误。

您需要找到另一种方法来编写代码才能在该网站上运行它。或者,您可以使用其他模拟器,例如 EDA Playground 上的模拟器。

这是解决该错误的一种痛苦方法。变化:

                default : q[i] <= q[i+1];

至:

                2,3,4,5,6,7,8,9,
                10,11,12,13,14,15,16,17,18,19,
                20,22,23,24,25,26,27,28,29,30 : q[i] <= q[i+1];

我也尝试过使用

case/inside
语法,但 Quartus 工具也不支持。

© www.soinside.com 2019 - 2024. All rights reserved.