4 Dataflow
4 Dataflow
Concatenation . Left-hand
side is a concatenation of a
scalar net and a vector net .
54
Regular continuous
assignmnet
Example
wire out ;
assign out = in1 & in2 ;
wire
4.2 Delays
Delay value control the time between the change in a right-hand-side
operand and when the new value is assigned to the left-hand-side.
55
Verilog Code
Declaration
I/O port
Delay in a
continuous
Call regular_delay
module
module stimulus;
wire OUT;
reg IN1, IN2;
initial
begin
IN1 = 0; IN2= 0;
#20 IN1=1; IN2= 1;
#40 IN1 = 0;
#40 IN1 = 1;
#5 IN1 = 0;
#150 $stop;
end
initial
$monitor("out", OUT, "in1", IN1, "in2",
IN2);
regular_delay rd1(OUT, IN1, IN2);
endmodule
56
Simulation Waveform
output out;
input in1, in2;
wire #10 out = in1 & in2;
endmodule
57
Call implicit_delay
module
initial
begin
IN1 = 0; IN2= 0;
#20 IN1=1; IN2= 1;
#40 IN1 = 0;
#40 IN1 = 1;
#5 IN1 = 0;
#150 $stop;
end
initial
$monitor("out", OUT, "in1", IN1, "in2",
IN2);
implicit_delay rd1(OUT, IN1, IN2);
endmodule
Simulation Waveform
58
No delay in a
output out;
input in1, in2;
continuous
assignment
module stimulus;
wire #10 OUT;
reg IN1, IN2;
initial
begin
IN1 = 0; IN2= 0;
#20 IN1=1; IN2= 1;
#40 IN1 = 0;
#40 IN1 = 1;
59
#5 IN1 = 0;
#150 $stop;
end
Show the result
Call net_declare
module
initial
$monitor("out", OUT, "in1", IN1, "in2",
IN2);
net_declare rd1(OUT, IN1, IN2);
endmodule
Simulation Waveform
4.3.1 Expressions
Expressions are constructs that combine operators and operands to
produce a result.
60
4.3.2 Operands
Operands can be any one of the data types. Some constructs will take
only certain types of operands.
count is an
integer operand
4.3.3 Operators
The operator act on the operands to produce desired results. Verilog
provides various types of operators.
Operator
Type
Arithmetic
Logical
Relational
Equality
Operator
Symbol
*
/
+
%
!
&&
||
>
<
>=
<=
==
!=
Operation
Performed
Multiply
Divide
Add
Subtract
Modulus
Logical negation
Logical and
Logical or
Greater than
Less than
Greater than or equal
Less than or equal
Equality
Inequality
61
Number of
Operands
Two
Two
Two
Two
Two
One
Two
Two
Two
Two
Two
Two
Two
Two
Bitwise
Reduction
Shift
Concatenation
Replication
Conditional
===
!==
~
&
|
^
^~ or ~^
&
~&
|
~|
^
^~ or ~^
>>
<<
{ }
{{}}
Case equality
Case inequality
Bitwise negation
Bitwise and
Betwise or
Bitwise xor
Bitwise xnor
Reduction and
Reduction nand
Reduction or
Reduction nor
Reduction xor
Reduction nxor
Right shift
Left shift
Concatenation
Replication
?:
Two
Two
One
Two
Two
Two
Two
One
One
One
One
One
One
Two
Two
Any number
Any number
Conditional
three
4.4 Examples
Dataflow 4-to-1 Multiplexer (Using Logic Equations)
Verilog Code
Port declarations from
the I/O diagram
Set assignment
function
62
module stimulus;
reg IN0, IN1, IN2, IN3;
reg S1, S0;
wire OUTPUT;
Instantiated the
multiplexer
initial
begin
choose IN0
choose IN1
choose IN2
choose IN3
S1 = 0; S0 = 0;
#1 $display("S1 = %b, S0 = %b,
OUTPUT = %b \n", S1, S0, OUTPUT);
S1 = 0; S0 = 1;
#1 $display("S1 = %b, S0 = %b,
OUTPUT = %b \n", S1, S0, OUTPUT);
S1 = 1; S0 = 0;
#1 $display("S1 = %b, S0 = %b,
OUTPUT = %b \n", S1, S0, OUTPUT);
S1 = 1; S0 = 1;
#1 $display("S1 = %b, S0 = %b,
OUTPUT = %b \n", S1, S0, OUTPUT);
63
end
endmodule
Simulation Waveform
Simulation Result
Verilog Code
64
module stimulus;
reg IN0, IN1, IN2, IN3;
reg S1, S0;
wire OUTPUT;
choose IN0
S1 = 0; S0 = 0;
#1 $display("S1 = %b, S0 = %b, OUTPUT = %b
\n", S1, S0, OUTPUT);
choose IN1
S1 = 0; S0 = 1;
#1 $display("S1 = %b, S0 = %b, OUTPUT = %b
\n", S1, S0, OUTPUT);
65
choose IN2
choose IN3
S1 = 1; S0 = 0;
#1 $display("S1 = %b, S0 = %b,
OUTPUT = %b \n", S1, S0, OUTPUT);
S1 = 1; S0 = 1;
#1 $display("S1 = %b, S0 = %b,
OUTPUT = %b \n", S1, S0, OUTPUT);
end
endmodule
Simulation Waveform
Simulation Result
66
Verilog Code
Define a 4-bit full adder
Stimulate inputs
module stimulus;
reg [3:0] A, B;
reg C_IN;
wire [3:0] SUM;
wire C_OUT;
fulladd4 FA1_4(SUM, C_OUT, A, B,
C_IN);
initial
begin
$monitor($time," A= %b, B=%b,
C_IN= %b,, C_OUT= %b, SUM=
%b\n", A, B, C_IN, C_OUT, SUM);
end
initial
begin
A = 4'd0; B = 4'd0; C_IN = 1'b0;
#5 A = 4'd3; B = 4'd4;
#5 A = 4'd2; B = 4'd5;
67
#5 A = 4'd2; B = 4'd5;
#5 A = 4'd9; B = 4'd9;
#5 A = 4'd10; B = 4'd15;
#5 A = 4'd10; B = 4'd5; C_IN = 1'b1;
end
endmodule
Simulation Waveform
Simulation Result
68
Verilog Code
module fulladd4(sum, c_out, a, b, c_in);
Inputs and outputs
Internal wires
compute the g
for each stage
Compute Sum
Assign carry
output
Instantiated the
4-bit full adder.
call it FA1_4
Setup the monitoring
for the signal values
Stimulate inputs
module stimulus;
reg [3:0] A, B;
reg C_IN;
wire [3:0] SUM;
wire C_OUT;
fulladd4 FA1_4(SUM, C_OUT, A, B, C_IN);
initial
begin
$monitor($time," A= %b, B=%b,
C_IN= %b,, C_OUT= %b, SUM= %b\n",
A, B, C_IN, C_OUT, SUM);
end
initial
begin
A = 4'd0; B = 4'd0; C_IN = 1'b0;
#5 A = 4'd3; B = 4'd4;
#5 A = 4'd2; B = 4'd5;
#5 A = 4'd9; B = 4'd9;
#5 A = 4'd10; B = 4'd15;
#5 A = 4'd10; B = 4'd5; C_IN = 1'b1;
end
endmodule
70
Simulation Waveform
Simulation Result
Verilog Code
Edge triggered D
flipflop
Inputs and outputs
Internal variables
Create a complement
of signal clear
Input latches
Output latch
Edge triggered
T-flipflop. Toggles
every clock cycle.
Instantiated the
edge triggered
DFF
Ripple counter
I/O ports
output [3:0] Q;
input clock, clear;
Instantiated the T
flipflops
72
Instantiated the
design block
module stimulus;
reg CLOCK, CLEAR;
wire [3:0] Q;
initial
$monitor($time, " Count Q = %b Clear=
%b", Q[3:0],CLEAR);
initial
$gr_waves( "clk", CLOCK,
"Clear", CLEAR,
"Q", Q[3:0],
"Q0", Q[0],
"Q1", Q[1],
"Q2", Q[2],
"Q3", Q[3]);
counter c1(Q, CLOCK, CLEAR);
Stimulate the
Clear Signal
Finish the
simulation at
time 200
initial
begin
CLEAR = 1'b1;
#34 CLEAR = 1'b0;
#200 CLEAR = 1'b1;
#50 CLEAR = 1'b0;
end
initial
begin
CLOCK = 1'b0;
forever #10 CLOCK = ~CLOCK;
end
initial
begin
73
#400 $finish;
end
endmodule
Simulation Waveform
Simulation Result
74