always block

always block can be of 2 types:
1. Combinatorial always block 
2. Sequential always block

Combinatorial always block:
1. It should contain only blocking statements, meaning each blocking statement inside an always block is executed consequentially top to bottom.
2. If we have multiple always blocks, we might feel that all always blocks run concurrently, which is true when a hardware is implemented, but for simulation, the always blocks are executed one after another only.
3. It could have simple assignment from a boolean or arithmetic on RHS to a LHS variable.
4. It could contain complex statement blocks too, like an if, case, for, while

5. if block in combinatorial always block:
Syntax:
if (condition)
begin
...
end
else if (condition)
begin
...
end
else
begin
...
end

Note: The conditions are executed as well as implemented to a hardware with a priority. This is the main difference between a case and if block.

6. for loop blocks in combinatorial always block:
Syntax:
for({i,j}=0; i<16 amp="" i="" j="" p="">begin
...
end

Note: All statements inside a for loop are expanded to the extreme values before the design is synthesized to a circuit. For instance in the following example:
for(i=0; i<8 i="i+1)</p">begin
   data_o[i] = data1[i] + data2[i] ;
end

Here, in the example, since it is given that i goes from 0 to 7 in increments of 1, the above single statement will be expanded for all possible values of 'i' before synthesis to a hardware. This example was just to give you insights on how a synthesis tool looks at your HDL code.
Food for thought: Think hardware!

7. while loop in a combinatorial always block:
Syntax:
while(condition)
begin
...
end

Note: The internal working is same as a for loop, only that updation of condition won't be as straight forward. for and while blocks are only to save coding space.

8. case block in combinatorial always block:
I will explain this on next page.


Sequential always blocks:
1. It should contain only non-blocking statements, meaning each blocking statement inside an always block is executed consequentially top to bottom.
Working for non-blocking statements in an always block: All statements inside an always block are executed concurrently, meaning, all statement's RHS expression is evaluated, after which only the computed values are assigned to their respective LHS parallelly.
For example,
always@(posedge clk)
begin
data_int <= data1 + data2;
data_o <= data_int + data1 ;
end

Here, if initially data1=3 and data2=4, data_int=2 => during execution, first RHS of each statement is calculated, 7 and 5 (using nonupdated values), post which, all values are assigned to their LHS counterpart. So, on execution, data_int = 7 and data_o = 5.

2. if and case block in sequential always block: Similar as combinatorial always block

3. for and while loops in sequential always block: Avoid these blocks in sequential always block.











Comments

Popular posts from this blog

What should you expect in an VLSI interview as a fresher

The struggle to enter VLSI industry is for real