During training, when I was creating a 7-segment decoder in Verilog HDL,
I'm getting a "latch exists" warning on Quartus II.
Here is the warning message at that time.
I looked at the logic that was made at that time with the RTL Viewer.
If you look at the logic in the RTL Viewer, there is indeed a latch...
How did the latch get generated?
I don't remember writing a latch...
Since the 7-segment decoder mainly describes only case statements, I thought that was the only cause, and decided to compare it with the case descriptions that worked well in the past.
Then I found that the default was not written, so I added it.
The figure below shows the improved RTL Viewer with the default description.
Yes...that's the reason!
A single description of default in a case statement can change the circuit so far!
It's too delicate to handle...
By the way, when I looked at the compilation report, the number of logic elements (LE: capacity of FPGA) consumed by FPGA was different.
A case statement defines a condition and describes an expression to be executed, so if it doesn't cover all the conditions, it forms a latch by reasoning that it must hold the previous value.
If you don't include all the conditions in the default statement, it will generate latches trying to hold the previous values of the unwritten conditions.
It is important not to forget to write the default statement.
If you pay attention to warnings that are often overlooked, you may learn quite a bit.
By the way, during my training, I was constantly told that latches were bad,
It's almost the same symbolically and behaviorally, so why not a latch?
Even if you look at the above figure, the primitive levels can be seen together.
However, if you actually look at the structure of the latch, you can see that it is built with NAND and is fed back.
(Quartus II is amazing, you can see so far!)
I didn't know anything about latches, so I asked my senior!
Both latches and flip-flops are functions for holding data, but flip-flops take in data at the rising edge (or falling edge) of the clock, and latches repeatedly feed back the output and return it to the input. It seems that he is doing
The figure below shows the structure of the latch.
Also, since the feedback delay time varies depending on the length of the wiring, it seems that data cannot always be obtained at the same timing.
FPGAs and CPLDs that can be rewritten many times always have flip-flops in units called logic cells. It is that.