为什么我的verilog代码总是触发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 fpga 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.
© www.soinside.com 2019 - 2024. All rights reserved.