Dataflow Modelling
Dataflow Modelling
• For small circuits, the gate-level modeling approach works very well
because the number of gates is limited and the designer can instantiate
and connect every gate individually.
• Gate-level modeling is very intuitive to a designer with a basic knowledge
of digital logic design.
• However, in complex designs the number of gates is very large, designers
can design more effectively if they concentrate on implementing the
function at a level of abstraction higher than gate level.
• Dataflow modeling provides a powerful way to implement a design.
• Verilog allows a circuit to be designed in terms of the data flow between
registers and how a design processes data rather than instantiation of
individual gates.
• Currently, automated tools are used to create a gate-level circuit from a
dataflow design description.
Continuous Assignments
• A continuous assignment is the most basic statement in dataflow
modeling
• Drive a value onto a net.
• This assignment replaces gates in the description of the circuit and
describes the circuit at a higher level of abstraction.
• The assignment statement starts with the keyword assign.
Continuous assignments characteristics:
• The left hand side of an assignment must always be a scalar or vector
net or a concatenation of scalar and vector nets.
• It cannot be a scalar or vector register.
• Continuous assignments are always active. The assignment
expression is evaluated as soon as one of the right-hand-side
operands changes and the value is assigned to the left-hand-side net.
• The operands on the right-hand side can be registers or nets or
function calls. Registers or nets can be scalars or vectors.
• Delay values can be specified for assignments in terms of time units.
Delay values are used to control the time when a net is assigned the
evaluated value.
Examples of Continuous Assignment
// Continuous assign. out is a net. i1 and i2 are nets.
assign out = i1 & i2;
endmodule
VERILOG code for Half adder
module ha(a,b,s,c);
input a,b;
output s,c;
assign {c,s} = a+b;
endmodule
VERILOG code for Half adder
module ha(a,b,s,c);
input a,b;
output s,c;
assign #10 s = a^b;
assign #20 c = a&b;
endmodule
VERILOG code for mux (2to1)
module mux2to1(a, b, s, y);
input s,a,b;
output y;
assign y = (~s&a)|(s&b);
endmodule
VERILOG code for mux (2to1)
module mux2to1(a, b, s, y);
input s,a,b;
output y;
wire s1,s2,s3;
assign s1 = ~s;
assign s2 = s1&a;
assign s3 = s&b;
assign y = s2|s3;
endmodule
VERILOG code for mux (2to1)
module mux2to1(a, b, s, y);
input s,a,b;
output y;
wire s1,s2,s3;
assign s1 = ~s;
assign s2 = s1&a;
assign s3 = s&b;
assign #10 y = s2|s3;
endmodule
VERILOG code for mux (2to1)
module mux2to1(a, b, s, y);
input s,a,b;
output y;
assign y = s? b:a;
endmodule
Verilog code for binary to gray code
converter
module binarytogray(b,g);
input [2:0] b;
output [2:0] g;
endmodule
Verilog code for binary to gray code
converter module btogtb;
module binarytogray(b,g);
reg [2:0]b;
input [2:0] b; wire [2:0]g;
output [2:0] g; btog b1(b,g);
initial b=00;
assign g[2]= b[2]; always #5 b = b+1;
assign g[1:0]= b[2:1] ^ b[1:0]; initial
begin
$monitor ($time , " b=%b, g=%b", b,g);
endmodule #50 $finish;
end
endmodule
Stimulus
0 b=000, g=000
5 b=001, g=001
10 b=010, g=011
15 b=011, g=010
20 b=100, g=110
25 b=101, g=111
30 b=110, g=101
35 b=111, g=100
40 b=000, g=000
45 b=001, g=001
Verilog code for binary to gray code
converter
module binarytogray (b, g);
parameter n=2 ;
input [n:0] b;
output [n:0] g;
assign g[n]=b[n];
assign g[n-1:0]=b[n:1]^b[n-1:0];
endmodule
Verilog code for 4-bit Ripple carry adder
module rippleadder(a, b, cin, s, cout);
input [3:0] a;
input [3:0] b;
input cin;
output [3:0] s;
output cout;
wire [4:0]c;
assign c[0]=cin;
assign s[3:0]=a[3:0]^b[3:0]^c[3:0];
assign c[4:1]=(a[3:0]&b[3:0])|(c[3:0]&b[3:0])|(a[3:0]&c[3:0]);
assign cout=c[4];
endmodule
4-bit Ripple carry Adder
module fulladd4(sum, c_out, a, b, c_in);
output out;
input i0, i1, i2, i3;
input s1, s0;
output out;
input i0, i1, i2, i3;
input s1, s0;