Thanks All, your answers made it very clear to me.
But I just had one more doubt while reading the replies above.
Why do only asynchronous logic create latches and not the synchronous
ones?
Well, as Tricky mentioned, registers can also be considered latches as
well...but I think what you're looking for is a bit more practical
answer for why.
The short answer though is that what you've stated is somewhat
backwards. The answer to the question "Why do only asynchronous logic
create latches and not the synchronous ones?" is "Latches are used to
implement combinatorial processes that feedback on themselves whereas
registers are used to implement edge sensitive processes." The more
detailed answer is coming up.
A small example like the ones above would be really appreciated.
The following code might not be the typical form one sees for a latch
or a register, but it was chosen to illustrate the point.
[1] y <= x when (C = '1'); -- Example of code that creates a latch:
[2] y <= x when (C = '1' and C'event); -- Example of code that creats
a flip flop:
Obviously, the only source code difference between [1] and [2] is the
inclusion of "C'event". VHDL defines that C'event equates to 'any
time signal C changes'. Focusing just on synthesis of digital logic
here, the phrase 'any time signal C changes' means that signal C must
have
- Changed from a high to low (i.e. 1 to 0)
- Changed from a low to high (i.e. 0 to 1)
So now one can say that "C = '1' and C'event" equates to "C is 1 and C
has changed from either low to high or from high to low". But if "C
is 1" is true, then obviously C must have changed from low to high.
So now you can look at the condition "C = '1' and C'event" and
conclude that C must have had an a rising edge occur.
Now look at the condition in [1]. Here you don't have the "C'event"
condition, it is simply "C = '1'". This is true whenever signal C is
high (i.e. a logic 1). This condition *starts* at the rising edge of
C, but it is not a small interval of time, rather it is true frmo the
rising edge of C up to the point where the falling edge of C occurs.
Now look at the left part of the assignment in [2], "y <= x" in
addition to what you now now about the "C = '1' and C'event" logic.
What this means is that the signal x will only be copied over to y
during the small interval of time when the rising edge of signal C is
occurring. The digital logic primitive that samples a signal at the
rising edge of some other input signal and stores that result is a
flip flop (also known as register).
Now look at the left part of the assignment in [1], "y <= x" in
addition to what you now now about the "C = '1'" logic. What this
means is that the signal x will only be copied over to y during the
interval when signal C is high. In particular, if C is high, then any
change to x will immediately show up on y, you don't need to wait for
a rising edge on C. The digital logic primitive that samples a signal
as long as some other input signal is high and stores that result is a
transparent latch (or simply a latch).
To bring it all around to wrap it up then, it is simply the appearance
of the C'event in an outermost "if" statement in a process [3] that
causes the synthesis software to say "Ah ha! I need to put in a flip
flop here". Since a flip flop is chosen, the process is a synchronous
process. If a process does not have a C'event in an outermost "if"
statement, rather just a "C = '1'" form that causes the synthesis
software to say "Ah ha! I need to put in (or cobble together from
logic) a transparent latch here". Since a latch is chosen, the
process is a combinatorial process.
The pattern matching on the source code by the synthesis tool that
results in what I called "Ah ha!..." is typically called inferring.
Therefore, one can look at things like [1] and say something like
"synthesis will infer a latch to implement [1]" and "synthesis will
infer a flip flop to implement [2]"
Kevin Jennings
[3] The C'event can also be obscured somewhat. The preferred form
for writing a clocked process would use "if rising_edge(C) then...".
The IEEE standard libraries define the function "rising_edge" and that
definition includes the C'event. It is slightly more complicated than
just "C = '1' and C'event" but that complication has to do with
simulation (where metavalues of 'X', '-', 'Z' are valid) not synthesis
(where the value of any signal is either 0 or 1.