Transcript
Page 1: Verilog  HDL (Behavioral Modeling)

Verilog HDLVerilog HDL(Behavioral Modeling)(Behavioral Modeling)

Bilal Saqib

Page 2: Verilog  HDL (Behavioral Modeling)

Behavioral ModelingBehavioral Modeling

Page 3: Verilog  HDL (Behavioral Modeling)

Structured ProceduresStructured Procedures

Page 4: Verilog  HDL (Behavioral Modeling)

In One ModuleIn One Module

A module may contain multiple always statements and multiple initial statements. Each statement starts a separate control flow and starts execution at time 0.

Page 5: Verilog  HDL (Behavioral Modeling)

Initial statementInitial statement

An initial statement executes only once and begins its execution at start of simulation which is at time 0.

Syntax : initial[timing_control] procedural_statement

Page 6: Verilog  HDL (Behavioral Modeling)

Always statementAlways statement

An always statement executes repeatedly and also begins its execution at start of simulation which is at time 0.

Syntax : always [timing_control]

procedural_statement

Page 7: Verilog  HDL (Behavioral Modeling)

where a procedural_statement is one of :procedural_assignment ( blocking or

non_blocking)procedural_continuous _assignment conditional_statementcase_statementloop_statementwait_statementdisable_statementevent_triggersequential_blockparallel_blocktask_enable (user

Page 8: Verilog  HDL (Behavioral Modeling)

Procedural BlocksProcedural Blocks

Procedural Blocks are constructed from the following components.◦Procedural Assignment Statements◦High-Level Constructs

Page 9: Verilog  HDL (Behavioral Modeling)

Procedural AssignmentsProcedural Assignments

Page 10: Verilog  HDL (Behavioral Modeling)

Procedural Execution ControlProcedural Execution Control

Execution of Procedural Blocks can be specified in different ways◦Simple Delays: #<delay>

Specify delay before and after execution for a number of time steps.

◦Edge-Sensitive Controls: always @ (<edge><signal>) Execution occurs only at a signal edge. Optional

keywords “posedge” or “negedge” can be used to specify signal edge for execution.

Page 11: Verilog  HDL (Behavioral Modeling)

NonBlocking v Blocking NonBlocking v Blocking AssignmentsAssignments

Page 12: Verilog  HDL (Behavioral Modeling)

NonBlocking v Blocking NonBlocking v Blocking AssignmentsAssignments

Page 13: Verilog  HDL (Behavioral Modeling)

Continuous assignment vs Continuous assignment vs Procedural assignmentProcedural assignment

Procedural assignment

◦ Occurs inside an always statement or an initial statement.

◦ Execution is with respect to other statements surrounding it.

◦ Drives registers.◦ Uses “ = “ or “ < = “

assignment symbol.◦ No assign keyword

Continuous assignment

◦ Occurs within a module.◦ Executes concurrently

with other statements ; executes whenever there is a exchange of value in an operand on its right-hand side.

◦ Drives nets.◦ Uses “ = “ assignment

symbol.◦ Uses assign keyword

Page 14: Verilog  HDL (Behavioral Modeling)

Block statementsBlock statements

A block statement provides a mechanism to group two or more statements to act syntactically like a single statement. There are two kinds of blocks in Verilog HDL. These are :

◦ Sequential block ( begin…end ) : Statements are executed sequentially in the given order.

◦ Parallel block ( fork … join ) : Statements in this block execute concurrently.

Page 15: Verilog  HDL (Behavioral Modeling)

Sequential blockSequential block

Statements in a sequential block execute in sequence.

Syntax : begin [ : block_id { declarations} ] procedural_statement (s)end

Page 16: Verilog  HDL (Behavioral Modeling)

Parallel blockParallel block

Statements in a parallel block execute in concurrently.

Syntax : fork [ : block_id { declarations} ] procedural_statement (s)join

Page 17: Verilog  HDL (Behavioral Modeling)

Conditional Statements: if elseConditional Statements: if else

Page 18: Verilog  HDL (Behavioral Modeling)

Conditional Statements: caseConditional Statements: case

Page 19: Verilog  HDL (Behavioral Modeling)

casex and casezcasex and casez

Page 20: Verilog  HDL (Behavioral Modeling)

Looping Statements: repeat

Page 21: Verilog  HDL (Behavioral Modeling)

Looping Statements: while

Page 22: Verilog  HDL (Behavioral Modeling)

Looping Statements: forever

Page 23: Verilog  HDL (Behavioral Modeling)

Looping Statements: for

Page 24: Verilog  HDL (Behavioral Modeling)

ExampleExample

module FA_Seq (A , B , Cin , Sum, Cout) ; input A , B, Cin ; output Sum, Cout ; reg Sum, Cout ; reg T1, T2, T3 ; always

@ ( A or B or Cin ) begin

Sum = ( A ^ B ) ^ Cin ;T1 = A & Cin ;T2 = B & Cin ;T3 = A & B;Cout = ( T1 | T2 ) | T3 ;

endendmodule