我使用ps2键盘和basys2来模拟4层楼(潜艇、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和reqin_a22改为1,我真的尝试过很多东西,所以我非常感谢你的帮助。
发布于 2017-10-08 03:46:36
当一个reg被定义为没有顺序的始终块,并且没有为所有可能的分支分配一个确定的值时,就会发生级别敏感的锁存。例如,always @* if (en) q = d;是锁存器,因为q在en较低时没有被分配值。添加else q = q;仍然可以推断出锁存器。
一个按钮按下多盏灯的原因是启用逻辑不干净。cw的比特可能相隔几纳秒/皮克秒。此外,还存在与每个状态匹配cw的预调节延迟。在这两种情况下,都可能是故障的罪魁祸首。
最简单的解决方案是通过添加一个时钟使设计同步。
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 (通用)。
https://stackoverflow.com/questions/46625383
复制相似问题