player55328 wrote:
I would suggest you add a default to your case statement just in case you get a situation you are not expecting.
When I read EEyE's post yesterday, I had the same thought initially, but I changed my mind.
First, the
if construction that he's using in a single
always block is correct. It could be expanded into 17 separate
always blocks and the structure would generate the expected logic behavior. That is, only when the condition is true is the register updated, and at all other times the register holds its last value.
Second, it is true that the
case statement in the second example, nested inside an
if statement, is missing the recommended
default clause that prevents the generation of inferred latches. However, since these two statements are inside a clocked
always block, there is no need to add the
default clause.
ElEctricEyE wrote:
That seems to be a good practice, but I'm not sure how I would go about that in this case.
I also have the same thought. I generally include a
default clause to all
case statements, and in particular, to
case statements in combinatorial
always blocks. However, I think this is an example where that general recommendation is not appropriate. In my opinion, adding a
default clause to this case statement will reduce the readability of the code.