锁存警告是由于ps2键盘verilog中的带有码字的case语句引起的



我使用ps2键盘和basys2来模拟行为四层楼(1、2和3层)中的两部电梯

此代码保存每个电梯的内部要求,cw是来自ps2键盘的码字

定义的参数是模拟中使用的键(ps2键盘键)的码字ps2键盘代码

module reg_in2(
input [7:0] cw,
output reg[3:0] reqin_a1,
output reg[3:0] reqin_a2
);
parameter a1_sub =  8'h6b;
parameter a1_1 = 8'h6c;
parameter a1_2  = 8'h75;
parameter a1_3 = 8'h7d;
parameter a2_sub = 8'h70 ;
parameter a2_1 = 8'h69 ;
parameter a2_2 = 8'h72 ;
parameter a2_3 = 8'h7A ;
initial
begin
reqin_a1 = 4'b0;
reqin_a2 = 4'b0;
end
always@(cw)
begin
case(cw)
a1_sub: reqin_a1[0] = 1;
a1_1: reqin_a1[1] = 1;
a1_2: reqin_a1[2] = 1;
a1_3: reqin_a1[3] = 1;
a2_sub: reqin_a2[0] = 1; 
a2_1: reqin_a2[1] = 1;
a2_2: reqin_a2[2] = 1;
a2_3: reqin_a2[3] = 1;
default: begin
reqin_a1 = reqin_a1;
reqin_a2 = reqin_a2;
end
endcase
end
endmodule

我得到的唯一警告是(对于reqin_a1和reqin_a2的每一位)

Found 1-bit latch for signal <reqin_a1_0>. Latches may be generated from incomplete case or if statements. We do not recommend the use of latches in FPGA/CPLD designs, as they may lead to timing problems.
The value init of the FF/Latch 0 hinder the constant cleaning in the block reqin_a1_3.
You should achieve better results by setting this init to 1.
Gated clock. Clock net
req_in1/reqin_a2_1_cmp_eq0000 is sourced by a combinatorial pin. This is not
good design practice. Use the CE pin to control the loading of data into the
flip-flop.

我的问题不是错误,而是Basys2的意外行为,我正在使用LED检查reqin_a1和reqin_a2值。当我按下ps2键盘中的一些设计键时,不止一个led灯亮起。示例:我在ps2键盘上按2(参数a2_2),reqin_a2[0]和reqin_a2*2]变为1我真的尝试了很多东西,所以我真的很感激的帮助

reg在非连续始终块中定义,并且未分配给所有可能分支的确定值时,会发生级别敏感锁存。例如always @* if (en) q = d;是锁存器,因为当en为低时q没有被分配值。添加else q = q;仍将推断锁存。

按下按钮时多个指示灯亮起的原因是启用逻辑不干净。CCD_ 6的比特可能相隔几纳秒/皮秒到达。还有将CCD_ 7匹配到每个状态的中止延迟。这两种情况都可能是故障的罪魁祸首。

最简单的解决方案是通过添加时钟来使设计同步。

always @(posedge clock)
begin
case(cw)
a1_sub: reqin_a1[0] <= 1;
a1_1: reqin_a1[1] <= 1;
// ...
a2_2: reqin_a2[2] <= 1;
a2_3: reqin_a2[3] <= 1;
// Note default is not required
endcase
end

有意创建闩锁时,请保持启用逻辑干净。最好来自时钟源。并使用非阻塞分配<=。尽量保持锁存逻辑尽可能简单。我建议为每个锁存启用信号设置一个单独的始终块。闩锁通常是无意的。让任何阅读您的代码和合成器的人都能轻松识别有意的闩锁。使用注释(仅限人工)、杂注(特定于工具)或启用SystemVerilog并使用always_latch(通用)。

最新更新