How to know if this piece of code is for a sequential or a combinational circuit?enter image description here
-
1\$\begingroup\$ Look for some 'always @ ()' documentation. You may just find your answer. \$\endgroup\$Vicente Cunha– Vicente Cunha2020年06月09日 11:21:44 +00:00Commented Jun 9, 2020 at 11:21
-
1\$\begingroup\$ Is there any feedback? \$\endgroup\$Dave Tweed– Dave Tweed2020年06月09日 12:00:54 +00:00Commented Jun 9, 2020 at 12:00
2 Answers 2
This will synthesize to sequential logic. If b
is 1
, then output will become 01
. Consider the case when both the inputs a
and b
are 0
. No condition of your code is satisfied, which means that the output will be unchanged. This implies that we are storing previous value, for which a latch is required. This occurs due to incomplete if else statements, that is, all the cases are not covered.
You can find out if a circuit is combinational if the circuit does not depend on previous states. Also a combinational circuit is time independent. In case that one of those conditions are not met, your circuit is sequential.
Regarding verilog code, one way to find out the combinational part from your module is to see the always block and its sensitivity list.
Always@ (*) block is used to describe combinational logic and logic gates. The star (*) represents the sensitivity list specifies which signals should trigger the elements inside the always@ block to be updated. Also a rule of thumb is to use only blocking assignments in an always@(*) block (e.g OUT = A & B).
Concerning your verilog code, there is a CLK signal in your sensitivity list and non-blocking assignments are used (which are used only in sequential logic circuits). However, I would say that your code is combinational because it is not synchronized with clk signal and the ouput is changed according to a or b inputs and the output does not depend on previous state (such as q <= ~q). In Verilog, if you want to create sequential logic use a clocked always block with nonblocking assignments. If you want to create combinational logic use an always block with blocking assignments
-
\$\begingroup\$ @panterhei , "Always@ (*) block is used to describe combinational logic and logic gates' - Even latches can be built using always @(*) block. \$\endgroup\$Shashank V M– Shashank V M2020年06月14日 12:41:44 +00:00Commented Jun 14, 2020 at 12:41
-
1\$\begingroup\$ Your first sentence is correct, but your final conclusion is wrong. Consider what happens in OP's code if both
a
andb
are 0. \$\endgroup\$The Photon– The Photon2020年06月15日 04:43:59 +00:00Commented Jun 15, 2020 at 4:43 -
\$\begingroup\$ Yes, you are right ! \$\endgroup\$pantarhei– pantarhei2020年06月15日 09:28:51 +00:00Commented Jun 15, 2020 at 9:28
Explore related questions
See similar questions with these tags.