Coe133l Drill-5 Behavioral Modeling
Coe133l Drill-5 Behavioral Modeling
SCHOOL OF EE-ECE-CpE
Behavioral Modeling
DRILL 5
ROSEMARIE PELLEGRINO
PROFESSOR
I. DISCUSSION
The primary mechanisms for modeling the behavior of a design are the
following two statements:
Initial statement
Always statement
An initial statement executes only once and begins its execution at start of
simulation which is at time 0.
initial [timing_control] procedural_statement
An always statement executes repeatedly and also begins its execution at
start of simulation which is at time 0.
always [timing_control] procedural_statement
2
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.
One-Way Selection:
if (condition)
statements;
Two-Way Selection (if-else):
if (condition)
statements;
else
statements;
Nested if (if-else-if):
if (condition)
statements;
3
else if (condition)
statements;
else
statements;
Case construct
A case statement is a multi-way conditional branch. It has the following
syntax:
case ( case_expr )
case_item_expr { case_item_expr } : procedural_statement
…
…
[ default : procedural_statement ]
endcase
The case construct has two important variations: casex and casez
4
II. Drill Exercises
1. Design a Verilog behavioural model of a sequence detector using D flip-flops.
5
module circuit_ff(input clk, reset, x, output y);
wire OR1, OR2, AND1, AND2, AND3;
wire A, B, Bnot;
not (Bnot, B);
flip_flop ff1(clk, reset, OR1, A);
flip_flop ff2(clk, reset, OR2, B);
and (AND1,A,x), (AND2,B,x), (AND3,Bnot,x), (AND4,A,B);
or (OR1, AND1,AND2), (OR2,AND1,AND3);
and (y,B,A);
endmodule
module testff;
reg clk, reset,d;
wire q;
circuit_ff cff(clk, reset, d, q);
initial begin
clk=0; reset=1; d=0;
$monitor("clk=%b reset=%b d=%b q=%b",clk,reset,d,q);
end
initial begin
forever #1 clk=~clk;
end
initial fork
#1 reset=0;
#2 d=1;
#3 reset=1;
#4 reset=0;
#5 d=0;
#8 d=1;
#10 $finish;
join
endmodule
6
2. Create a behavioural description of an eight-to-one line multiplexer.
7
module testMux();
reg [7:0] x;
reg [2:0] select;
wire m_out;
8
3. Create an HDL model of the operation of a sequential circuit based from the
given state diagram:
0/0 1/0
0/1
00 10
0/1
1/0 0/1 1/0
01 1/0 11
The program below is formulated based from the given diagram above.
Compile the file then save it as drill5_3.vl
9
module state_diagram(
output reg y_out,
input x_in, clock, reset
);
module sdiag;
wire t_y_out;
reg t_x_in, t_clock, t_reset;
state_diagram sd(t_y_out, t_x_in, t_clock, t_reset);
initial #200 $finish;
initial begin
t_clock=0;
forever #5 t_clock=~t_clock;
10
end
initial fork
$monitor($time,,"reset=%b clock=%b x=%b y=%b" ,t_reset, t_clock,
t_x_in, t_y_out);
t_reset=0;
#2 t_reset=1;
#87 t_reset=0;
#89 t_reset=1;
#10 t_x_in=1;
#30 t_x_in=0;
#40 t_x_in=1;
#50 t_x_in=0;
#52 t_x_in=1;
#54 t_x_in=0;
#70 t_x_in=1;
#80 t_x_in=1;
#70 t_x_in=0;
#90 t_x_in=1;
#100 t_x_in=0;
#120 t_x_in=1;
#160 t_x_in=0;
#170 t_x_in=1;
join
endmodule
11
III. Programming Exercise
12
IV. Review Questions
1. How is race condition experienced in Verilog HDL programming?
In Verilog certain type of assignments or expression are scheduled for
execution at the same time and order of their execution is not
guaranteed. This means they could be executed in any order and the
order could be change from time to time.
A Verilog race condition occurs when two or more statements that are
scheduled to execute in the same simulation time-step, would give
different results when the order of statement execution is changed, as
permitted by the IEEE Verilog Standard.
To avoid race conditions, it is important to understand the scheduling
of Verilog blocking and nonblocking assignments.
13
process created by an initial block. There is no way to terminate the
process created by an always block.
5. What are sensitivity lists? How do they affect the entire behavioural
model description of a program?
A simple always block runs forever it means as it touches the “end”
again starts from beginning. The sensitivity list controls when the
statements in an always block are evaluated. The sensitivity list must
include all input signals used by an always block to properly model
combinational logic. It is easy to inadvertently omit an input signal from
14
the sensitivity list, which can lead to simulation and synthesis
mismatches.
15