FPGA Verilog编译时警告Warning (10230): truncated value with size 32 to match size of target (3)

完整警告:

Warning (10230): Verilog HDL assignment warning at digital_clock.v(75): truncated value with size 32 to match size of target 

原因:

在写Verilog的计数程序时,很多人或者很多教程都是这样写:

always @(posedge clk or negedge rst_n)begin
    if(!rst_n)begin
        cnt <= 0;
    end
    else if(add_cnt)begin
        if(end_cnt)
            cnt <= 0;
        else
            cnt <= cnt + 1;
    end
end

其中  cnt <= cnt + 1;  中的1没有指定位宽,系统会自动分配32位位宽,这样会比较浪费资源,所以编译会警告。

解决:

写成   cnt <= cnt + 1'b1;  就好了。

改后为:

always @(posedge clk or negedge rst_n)begin
    if(!rst_n)begin
        cnt <= 0;
    end
    else if(add_cnt)begin
        if(end_cnt)
            cnt <= 0;
        else
            cnt <= cnt + 1'b1;
    end
end

猜你喜欢

转载自blog.csdn.net/qq_33231534/article/details/104856297