您的位置:首页 > 其它

FPGA组合逻辑之注意项

2016-01-29 18:30 489 查看
先上代码:
always @(*)begin
        if(recie_tlp_fifo_ren & recie_tlp_fifo_rdata[TLP_SOP])begin
                  if({recie_tlp_fifo_rdata[TLP_FMT_1D +:2],recie_tlp_fifo_rdata[TLP_TYPE_1D+:5]}==MWR_3DW)
                           word_3d_type = 3'b001;
                  else if({recie_tlp_fifo_rdata[TLP_FMT_1D +:2],recie_tlp_fifo_rdata[TLP_TYPE_1D+:5]}==MRB_3DW)
                           word_3d_type = 3'b010;
                  else
                           word_3d_type = 3'b100;
         end 
end

你们觉得这样写对吗?当初用chipscope在板子上调试时word_3d_type值为3‘b111或3’b110等其它情况,当时以为是distri
fifo不稳定导致的,后改为block fifo还是这样,而直接改为时序逻辑又会增加很多判断条件,无奈请教之,才知道,组合逻辑必须要将else补充完整,不能出现不确定状态和环路状态(即word_3d_type = word_3d_type,当然时序逻辑可以这样),否则导致程序出错,后改为如下方法
always @(posedge clk_125m) begin
recie_tlp_fifo_ren_1d <= recie_tlp_fifo_ren;

end

always @(posedge clk_125m) begin
recie_tlp_fifo_rdata_1d <= recie_tlp_fifo_rdata;

end

always @(posedge clk_125m) begin
if(recie_tlp_fifo_ren & recie_tlp_fifo_rdata[TLP_SOP])begin
if({recie_tlp_fifo_rdata[TLP_FMT_1D +:2],recie_tlp_fifo_rdata[TLP_TYPE_1D +:5]}==MWR_3DW)
word_3d_type <= 3'b001;
else if({recie_tlp_fifo_rdata[TLP_FMT_1D +:2],recie_tlp_fifo_rdata[TLP_TYPE_1D +:5]}==MRB_3DW) 
word_3d_type <= 3'b010;
else
word_3d_type <= 3'b100;
end

end

然后再根据word_3d_type 判断recie_tlp_fifo_ren_1d与recie_tlp_fifo_rdata_1d情况。
提示:对于提前获取关键信息,这种打拍方法是非常可取的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: