出现警告没法找不到原因
时间:10-02
整理:3721RD
点击:
module decoder
(
num, num_seg
);
input[3:0] num;
output[7:0] num_seg;
reg[7:0] num_seg;
always @(num)
begin
case(num[3:0])
4'd0 : num_seg = 8'b1100_0000;
4'd1 : num_seg = 8'b1111_1001;
4'd2 : num_seg = 8'b1010_0100;
4'd3 : num_seg = 8'b1011_0000;
4'd4 : num_seg = 8'b1001_1001;
4'd5 : num_seg = 8'b1001_0010;
4'd6 : num_seg = 8'b1000_0010;
4'd7 : num_seg = 8'b1111_1000;
4'd8 : num_seg = 8'b1000_0000;
4'd9 : num_seg = 8'b1001_0000;
endcase
end
endmodule
Warning (10240): Verilog HDL Always Construct warning at decoder.v(10): inferring latch(es) for variable "num_seg", which holds its previous value in one or more paths through the always construct
Warning: Latch decoder:u3|num_seg[0] has unsafe behavior
运行是没有问题,就是会有这个警告,有没有遇到过这个问题的朋友呢
(
num, num_seg
);
input[3:0] num;
output[7:0] num_seg;
reg[7:0] num_seg;
always @(num)
begin
case(num[3:0])
4'd0 : num_seg = 8'b1100_0000;
4'd1 : num_seg = 8'b1111_1001;
4'd2 : num_seg = 8'b1010_0100;
4'd3 : num_seg = 8'b1011_0000;
4'd4 : num_seg = 8'b1001_1001;
4'd5 : num_seg = 8'b1001_0010;
4'd6 : num_seg = 8'b1000_0010;
4'd7 : num_seg = 8'b1111_1000;
4'd8 : num_seg = 8'b1000_0000;
4'd9 : num_seg = 8'b1001_0000;
endcase
end
endmodule
Warning (10240): Verilog HDL Always Construct warning at decoder.v(10): inferring latch(es) for variable "num_seg", which holds its previous value in one or more paths through the always construct
Warning: Latch decoder:u3|num_seg[0] has unsafe behavior
运行是没有问题,就是会有这个警告,有没有遇到过这个问题的朋友呢
就是有锁存器啊。
你的case语句没写全,又没default语句,你想写的组合电路就会生成锁存器。
default语句没有写全,是另一个警告,应该不是这个原因,但是我如果把clk加进去,然后写成always @(posedge clk),这个问题就没有了
你把default放进去试一下,保证这个也会没有。
好的,我会试一下的,多谢帮忙
原代码是组合逻辑,你列出的警告就是提示case语句不完全,会产生锁存器; 加入“always @(posedge clk)”,即时钟上升沿触发,这时是时序逻辑,本身就具有锁存上一状态的功能,所以不会有警告。
多谢,初学入门,好像书上提到这是常见错误
