0% found this document useful (0 votes)
122 views9 pages

Always Block

The document discusses always blocks in Verilog. It explains that always blocks allow for sequential execution of statements and run continuously with zero time execution. It describes the always block syntax and use of sensitivity lists. It differentiates between blocking and non-blocking assignments, explaining that blocking assignments complete before next statement while non-blocking schedules updates at end of time step. It provides examples and guidelines around using blocking vs non-blocking assignments when modeling different logic types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views9 pages

Always Block

The document discusses always blocks in Verilog. It explains that always blocks allow for sequential execution of statements and run continuously with zero time execution. It describes the always block syntax and use of sensitivity lists. It differentiates between blocking and non-blocking assignments, explaining that blocking assignments complete before next statement while non-blocking schedules updates at end of time step. It provides examples and guidelines around using blocking vs non-blocking assignments when modeling different logic types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

always Block

I Assign statements are good for for simple logic expressions.


I For complex behavior, we need a more powerful means of expression.
I Sequential paradigms (if, else, case, while) can describe
more complex behavior.
I Within the procedural block, always we can write statements that
are evaluated sequentially.
I This has nothing to do with the order in which the logic operates.
I Always blocks run continuously. Actions inside them take zero time
to execute.
always Block

I Always statement structure (old-school Verilog 2001)


always @(sensitivity list) <begin> <procedural statements> <end>

I Example:
module ao2_gate(
input a, b, c, d,
output logic y);

logic tmp1, tmp2;

always @(a,b,c,d) begin


tmp1 = a & b;
tmp2 = c & d;
y = tmp1 | tmp2;
end
endmodule
always Block

I Whenever a variable in the sensitivity list changes, the always block


wakes up and executes its enclosed statements.
I If variables are omitted from the sensitivity list, the block will not
wake up when you want it to.
I <begin>,<end> will be needed if multiple statements exist.
I Variables on the LHS inside the always block must be of type logic
or reg.
I Synthesis ignores the sensitivity list.

always @(a,b,c,d) begin


tmp1 = a & b;
tmp2 = c & d;
y = tmp1 | tmp2;
end
always Block

I reg or logic variables retain the last assigned value

reg tmp1, tmp2;


always @(a,b,c,d,e,f)
begin
y = a & b;
y = c & d;
y = e & f;
end

I y retains the value (e & f) when always block concludes.


always Block

Two types of procedural assignment statements are used within always


I Blocking:
I The blocking assignment operator is the equals sign ”=”
I So named because blocking assignments must evaluate RHS and
complete the assignment without interruption from any other
statement.
I The blocking assignment also blocks other following assignments until
the current one is done.
I Blocking statements execute in the order they are specified.
always Block

Two types of procedural assignment statements


I Nonblocking
I The nonblocking assignment operator is the less-than-or-equals-to
operator ”<=”
I The nonblocking assignment evaluates the RHS at the beginning of a
time step and schedules the LHS update for the end of the time step.
I Between the evaluation of the RHS and update of LHS, other
statements may execute.
I The nonblocking statement does not block any other statements from
being evaluated.
I Nonblocking execution has two parts:
I 1. Evaluate RHS at beginning of time step
I 2. Update LHS at end of time step
always Block
Blocking and non-blocking assignments
Blocking Assignments Used

module fbosc1(
output reg y1, y2;
input clk, rst);

//always blocks can execute in any order

//"A" procedural block


always @ (posedge clk, posedge rst)
if (rst) y1 = 0; //reset
else y1 = y2;

//"B" procedural block


always @ (posedge clk, posedge rst)
if (rst) y2 = 1; //preset
else y2 = y1;

endmodule
always Block
Blocking and non-blocking assignments
Nonblocking Assignments Used

module fbosc2(
output reg y1, y2;
input clk, rst);

//always blocks can execute in any order

//"A" procedural block


always @ (posedge clk, posedge rst)
if (rst) y1 <= 0; //reset
else y1 <= y2;

//"B" procedural block


always @ (posedge clk, posedge rst)
if (rst) y2 <= 1; //preset
else y2 <= y1;

endmodule
Coding Guidelines
Thanks to Cliff Cummings, Sunburst Design

I When modeling sequential logic, use nonblocking assignments.


I When modeling latches, use nonblocking assignments.
I When modeling combo logic with an always block, use blocking
assignments.
I When modeling both sequential and combo logic within the same
always block, use nonblocking assignments.
I Do not mix blocking and nonblocking assignments in the same
always block.
I Do not make assignments to the same variable from more than one
always block.
For more information, see:
Nonblocking Assignments in Verilog Synthesis, Coding Styles That Kill!
Available at: http://www.sunburst-design.com

You might also like