Behavioral Modelling and TimingIn Verilog, Behavioral models contain procedural statements, which control the simulation and manipulate variables of the data types. These statements are contained within the procedures. Each of the procedures has an activity flow associated with it. During the behavioral model simulation, all the flows defined by the always and initial statements start together at simulation time zero. The initial statements are executed once, and the always statements are executed repetitively. Example The register variables a and b are initialized to binary 1 and 0 respectively at simulation time zero. The initial statement is completed and not executed again during that simulation run. This initial statement is containing a begin-end block of statements. In this begin-end type block, a is initialized first, followed by b. Procedural AssignmentsProcedural assignments are for updating integer, reg, time, and memory variables. There is a significant difference between a procedural assignment and continuous assignment, such as: 1. Continuous assignments drive net variables, evaluated, and updated whenever an input operand changes value. The procedural assignments update the value of register variables under the control of the procedural flow constructs that surround them. 2. The right-hand side of a procedural assignment can be any expression that evaluates to a value. However, part-selects on the right-hand side must have constant indices. The left-hand side indicates the variable that receives the assignment from the right-hand side. The left-hand side of a procedural assignment can take one of the following forms:
Delay in AssignmentIn a delayed assignment, Δt time units pass before the statement is executed, and the left-hand assignment is made. With an intra-assignment delay, the right side is evaluated immediately, but there is a delay of Δt before the result is placed in the left-hand assignment. If another procedure changes a right-hand side signal during Δt, it does not affect the output. Synthesis tools do not support delays. Syntax An assignment has the following syntax, such as: Blocking AssignmentsA blocking procedural assignment statement must be executed before executing the statements that follow it in a sequential block. The statement does not prevent the execution of statements that follow it in a parallel block. Syntax The following syntax is for a blocking procedural assignment, such as:
Non-blocking (RTL) AssignmentsThe non-blocking procedural assignment is used to schedule assignments without blocking the procedural flow. We can use the non-blocking procedural statement whenever we want to make several register assignments within the same time step without regard to order or dependence upon each other. Syntax The following syntax is for a non-blocking procedural assignment:
When the simulator encounters a non-blocking procedural assignment, the simulator evaluates and executes the non-blocking procedural assignment in two steps: Step 1: The simulator evaluates the right-hand side and schedules the new value assignment at a time specified by a procedural timing control. Step 2: At the end of the time step, when the given delay has expired, or the appropriate event has taken place, the simulator executes the assignment by assigning the value to the left-hand side. ConditionsThe conditional statement or if-else statement is used to decide whether a statement is executed. Syntax The syntax is as follows:
Case StatementThe case statement is a unique multi-way decision statement that tests whether an expression matches several other expressions, and branches accordingly. The case statement is useful for describing, for example, the decoding of a microprocessor instruction. Syntax The case statement has the following syntax:
The case statement differs from the multi-way if-else-if construct in two essential ways, such as: 1. The conditional expressions in the if-else-if construct are more general than comparing one expression with several others, as in the case statement. 2. The case statement provides a definitive result when there are x and z values in an expression. Looping StatementsThere are four types of looping statements. They are used to controlling the execution of a statement zero, one, or more times. 1. Forever continuously executes a statement. 2. Repeat executes a statement a fixed number of times. 3. While executes a statement until expression becomes false, if the expression starts false, the statement is not executed at all. 4. For controls execution of its associated statements by a three-step process are: Step 1: Executes an assignment normally used to initialize a variable that controls the number of loops executed. Step 2: Evaluates an expression. Suppose the result is zero, then the for loop exits. And if it is not zero, for loop executes its associated statements and then performs step 3. Step 3: Executes an assignment normally used to modify the loop control variable's value, then repeats step 2. Syntax The following are the syntax rules for the looping statements, such as: Delay ControlsVerilog handles the delay controls in the following ways, such as: 1. Delay Control The execution of a procedural statement can be delay-controlled by using the following syntax: The following example delays the execution of the assignment by 10-time units. Execution of the assignment delays by the amount of simulation time specified by the value of the expression. 2. Event Control The execution of a procedural statement can be synchronized with a value change on a net or register, or the occurrence of a declared event, by using the following event control syntax: *<SCALAR_EVENT_EXPRESSION> is an expression that resolves to a one-bit value. Value changes on nets and registers can be used as events to trigger the execution of a statement. This is known as detecting an implicit event. Verilog syntax also used to detect change based on the direction of the change, which is toward the value 1 (posedge) or the value 0 (negedge). The behavior of posedge and negedge for unknown expression values are:
ProceduresAll procedures in Verilog are specified within one of the following four Blocks.
Initial Blocks The initial and always statements are enabled at the beginning of the simulation. The initial blocks execute only once, and its activity dies when the statement has finished. Syntax The following syntax is for the initial statement: Example The following example illustrates the use of the initial statement for the initialization of variables it the starting of simulation. Another usage of the initial Blocks is the specification of waveform descriptions that execute once to provide stimulus to the central part of the circuit being simulated. Always Blocks The always blocks repeatedly executes. Its activity dies only when the simulation is terminated. There is no limit to the number of initial and always blocks defined in a module. Syntax The always statement repeats continuously throughout the whole simulation run. The syntax for the always statement is given below The always statement is only useful when used in conjunction with some form of timing control because of its looping nature. Task and Function Tasks and functions are procedures that are enabled by one or more places in other procedures. Next TopicVerilog Module |