OpenEdv-开源电子网

标题: 向数组内赋值,赋值不进去 [打印本页]

作者: liuhj123    时间: 2020-4-26 23:39
标题: 向数组内赋值,赋值不进去
各位老师好:我在学习新起点FPGA时,学到uart通信时,教程讲的是,将电脑通过串口发送下去的数据,直接在回传回来,我想在中间做一个缓存,例如,电脑通过串口下发一组数据,FPGA收到后,将数据先缓存到
数组内,数组内的每个元素做+1处理,得出的结果再回传给电脑,我程序是下面这样写的。为什么在仿真时buf_data这个数组内不能赋值呢?求各位老师帮助一下,谢谢!!!

module operate(
    input                                   clk,
    input                                   rst_n,
    input   [7:0]                           oper_data_in,
    input                                   oper_flag
);
reg                                         rise0;
reg                                         rise1;
wire                                        rise;
assign rise = (~rise) & rise0;

reg [7:0]                                   buf_data[0:5];
reg [5:0]                                   buf_cnt;
reg         [7:0]                           buff;
always @(posedge clk or negedge rst_n)begin
    if(!rst_n)begin
        rise0 <= 1'b0;
        rise1 <= 1'b0;
    end
    else begin
        rise0 <= oper_flag;
        rise1 <= rise0;
    end
end

always @(posedge clk or negedge rst_n)begin
    if(!rst_n)begin
        buff <= 8'd0;
    end
    else begin
        if(rise)begin
            buff <= oper_data_in;
            
        end
        else begin
            buf_data[0] <= buff;
        end
        
    end
end
endmodule

作者: QinQZ    时间: 2020-4-27 10:25
仿真还是比较方便找问题的。比如buf_data没有数据,那就去看buff有没有数据;如果buf没有数据,就看rise有没有上升沿,并且在上升沿的时候,oper_data_in的数据是不是正确等等。这样一步步找问题
作者: liuhj123    时间: 2020-4-27 23:55
QinQZ 发表于 2020-4-27 10:25
仿真还是比较方便找问题的。比如buf_data没有数据,那就去看buff有没有数据;如果buf没有数据,就看rise有 ...

module abc(
    input               clk,
    input               rst_n,
    output  reg [7:0]  aa,
    output  reg [7:0]   bb
   
);
reg     [7:0]   a;
reg     [7:0]   b;
reg [7:0]   cc[2:0] /*synthesis noprune*/;
reg [7:0]   dd[2:0]/*synthesis noprune*/;
always@(posedge clk or negedge rst_n)begin
    if(!rst_n)begin
        aa <= 8'd0;
        bb <= 8'd0;
        a <= 8'd0;
        b <= 8'd0;
    end
    else begin
        aa <= a + 1'b1;
        bb <= b + 1'b1;
        cc[0] <= aa;
        dd[1] <= bb;
    end
end
endmodule
我目前用的是quartus II 13.1版本,是破解,在使用signaltap IIf仿真过程中,对于reg wire
类型的变量,在仿真软件中不能正常显示,误以为程序编写有误,实际不是,不知道是因为
软件是破解版的有bug还是这是这个软件通病,上述程序,在不加 /*synthesis noprune*/这个语句时,在signaltap II仿真中是看不到数组变量值的,在增加了之后,其他代码都不变,可以正常看见数组内的数据变量值。
作者: liuhj123    时间: 2020-4-27 23:56
module abc(
    input               clk,
    input               rst_n,
    output  reg [7:0]  aa,
    output  reg [7:0]   bb
   
);
reg     [7:0]   a;
reg     [7:0]   b;
reg [7:0]   cc[2:0] /*synthesis noprune*/;
reg [7:0]   dd[2:0]/*synthesis noprune*/;
always@(posedge clk or negedge rst_n)begin
    if(!rst_n)begin
        aa <= 8'd0;
        bb <= 8'd0;
        a <= 8'd0;
        b <= 8'd0;
    end
    else begin
        aa <= a + 1'b1;
        bb <= b + 1'b1;
        cc[0] <= aa;
        dd[1] <= bb;
    end
end
endmodule
我目前用的是quartus II 13.1版本,是破解,在使用signaltap IIf仿真过程中,对于reg wire
类型的变量,在仿真软件中不能正常显示,误以为程序编写有误,实际不是,不知道是因为
软件是破解版的有bug还是这是这个软件通病,上述程序,在不加 /*synthesis noprune*/这个语句时,在signaltap II仿真中是看不到数组变量值的,在增加了之后,其他代码都不变,可以正常看见数组内的数据变量值。
作者: chaifuwu    时间: 2020-4-28 08:52
数据都存在buf_data的第0个字节处buf_data[0],后面的吧前面的覆盖了,
作者: liuhj123    时间: 2020-4-28 09:48
chaifuwu 发表于 2020-4-28 08:52
数据都存在buf_data的第0个字节处buf_data[0],后面的吧前面的覆盖了,

在仿真是,单次触发,不会被覆盖




欢迎光临 OpenEdv-开源电子网 (http://47.111.11.73/) Powered by Discuz! X3.4