fpga系列 HDL:verilog 常见错误与注意事项 Continuous Assignment error+ non-constant loop error+Initial 语句为不可综合的结构

连续赋值错误 Error (10219): Verilog HDL Continuous Assignment error

  • 错误 Error (10219): Verilog HDL Continuous Assignment error 不能将一个连续赋值(continuous assignment)应用于具有寄存器(reg)类型的对象。
  • 在Verilog中,连续赋值使用 assign 关键字,它只能用于连接型(net type)变量(如 wire 类型、SystemVerilog 中增加的logic 类型)。

错误示例

// 定义顶层模块
module top (
    input wire clk,          // 时钟信号
    output reg [DATA_WIDTH-1:0] data_out // 数据输出
);

// 参数定义
parameter DATA_WIDTH = 8;   // 数据宽度,根据需要调整

// 内部信号声明
wire [DATA_WIDTH-1:0] q_sig;

// 将顶层模块的端口连接到内部信号
assign data_out = q_sig;//  Error (10219): Verilog HDL Continuous Assignment error at ***.v(36): object "data_out" on left-hand side of assignment must have a net type

// 实例化
//…………

endmodule

修正

// 定义顶层模块
module top (
    input wire clk,         
    output wire [DATA_WIDTH-1:0] data_out // 数据输出变为wire
);

parameter DATA_WIDTH = 8;  

wire [DATA_WIDTH-1:0] q_sig;

assign data_out = q_sig;

// 实例化
//…………

endmodule

非固定循环错误 Error (10119): Verilog HDL Loop Statement error at ***.v(95): loop with non-constant loop condition must terminate within 250 iterations

错误示例

修改循环次数
for (i = 0; i < DEPTH; i = i + 1) begin
    if (bPeak) begin
        peak_index = i;
        next_state = CHECK_A;
        i = DEPTH - 1; // 这里修改了循环次数
    end
end
early break 带有中途退出逻辑的循环
for (j = 1; j < 12; j = j + 1) begin
    if (data_buffer[(i+j) % DEPTH] > data_buffer[i]) begin
        bPeak = 0;
        j = 12; // 希望实现 break;
    end
end

Initial 语句为不可综合的结构

  • Initial Block Misuse in Synthesizable Code
  • 综合工具通常(有时可以)不支持 initial 块(仅用于仿真),这里进行了讨论

错误示例

module top (
    input wire clk,
    input wire reset,
    input wire [7:0] a,
    output reg [7:0] b,
    output reg [7:0] c
);
	initial begin
		 b = 8'b1; 
	     c = 8'b1; 
	end
    always @(posedge clk or posedge reset) begin
        if (reset) begin
            b = 8'b101;   
            c = 8'b111;  
        end else begin
            c = a;   
        end
    end
endmodule

在这里插入图片描述

  • 如果注释掉b = 8'b101;RTL结构如下(可以看到inital并没有被综合):

在这里插入图片描述

修正

  • 在综合代码中,用复位逻辑代替 initial 块。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值