if statement latches

When designing circuits, you must think first in terms of circuits:

I want this logic gate
I want a combinational blob of logic that has these inputs and produces these outputs
I want a combinational blob of logic followed by a set of flip-flops
What you must not do is write the code first, then hope it generates a proper circuit.

If (cpu_overheated) then shut_off_computer = 1;
If (~arrived) then keep_driving = ~gas_tank_empty;

Always if2 - HDLBits (01xz.net)

 1 // synthesis verilog_input_version verilog_2001
 2 module top_module (
 3     input      cpu_overheated,
 4     output reg shut_off_computer,
 5     input      arrived,
 6     input      gas_tank_empty,
 7     output reg keep_driving  ); //
 8 
 9     always @(*) begin
10         if (cpu_overheated)
11            shut_off_computer = 1;
12         else 
13             shut_off_computer=1'b0;
14     end
15 
16     always @(*) begin
17         if (~arrived)
18            keep_driving = ~gas_tank_empty;
19         else
20             keep_driving=1'b0;   //没有懂这个原理,还要再看
21     end
22 
23 endmodule

 再写:

根据这道题再复习一下latch锁存器、register寄存器、flipflop触发器

二、8【FPGA】Verilog中锁存器(Latch)原理、危害及避免_verilog latch-CSDN博客

当你在FPGA开发时想组合出纯组合逻辑电路(没有时钟控制端),但有时候你的代码最后综合出的结果却是“组合逻辑电路+锁存器(触发器)”。这说明在你的Verilog代码中有保持不变的情况,这种“保持输出不变”的行为意味着需要记住当前的状态,由于组合逻辑中的门电路是无法储存状态的,此时代码综合后就会产生锁存器(Latch),来储存产生的状态。这就是组合逻辑中产生Latch的主要原因。
在组合逻辑电路的always中,if-else语句中不能缺少else;case语句中条件不能够完全列举或缺少default;在if-else和case中均不能出现变量自己将值赋给自己。这三种情况综合后会产生latch

posted @ 2023-04-19 23:58  江左子固  阅读(20)  评论(0)    收藏  举报