SlideShare a Scribd company logo
1
Verilog HDL
2
Modules and Ports:
The SR latch has S and R as the input
ports and Q and Qbar as the output
ports. The SR latch and its stimulus can
be modeled as shown in Example 4-1.
Example 4-1 Components of SR
Latch(Design):
module SR_latch(Q, Qbar, Sbar, Rbar);
output Q, Qbar; //Port declarations
input Sbar, Rbar;
nand n1(Q, Sbar, Qbar);
nand n2(Qbar, Rbar, Q);
endmodule
Stimulus block
3
 // Module name and port list // Stimulus module
module Top;
wire q,qbar;
reg set, reset;
SR_latch m1(q, qbar, ~set, ~reset);
initial
begin
$monitor($time, " set = %b, reset= %b, q=
%bn",set,reset,q);
set = 0; reset = 0;
#5 reset = 1;
#5 reset = 0;
#5 set = 1;
end
endmodule
Port Declarations
4
1.module fulladd4(sum, c_out, a, b, c_in); // port declarations section
output[3:0] sum;
output c_out;
input [3:0] a, b;
input c_in;//End port declarations section
...
<module internals>
...
endmodule
2.Example 4-4 Port Declarations for DFF
module DFF(q, d, clk, reset);
output q;
reg q; // Output port q holds value; therefore it is declared as reg.
input d, clk, reset;
...
...
endmodule
Port Declaration
5
Note that the module fulladd4 in Example 4-3 can be
declared using an ANSI C style syntax to specify the ports
of that module. Each declared port provides the complete
information about the port.
Example 4-5 shows this alternate syntax. This syntax
avoids the duplication of naming the ports in both the
module definition statement and the module port list
definitions. If a port is declared but no data type is
specified, then, under specific circumstances, the signal
will default to a wire data type.
Example 4-5 ANSI C Style Port Declaration Syntax
module fulladd4(output reg [3:0] sum,
output reg c_out,
input [3:0] a, b, //wire by default
input c_in); //wire by default
...
<module internals>
...
6
Connecting ports by name
7
 For large designs where modules have, say, 50 ports,
remembering the order of the ports in the module
definition is impractical and error-prone.
 Verilog provides the capability to connect external
signals to ports by the port names, rather than by
position.
 // Instantiate module fa_byname and connect signals
to ports by name
fulladd4 fa_byname(.c_out(C_OUT), .sum(SUM),
.b(B),.c_in(C_IN),
.a(A),);
 // Instantiate module fa_byname and connect signals to
ports by name
fulladd4 fa_byname(.sum(SUM), .b(B), .c_in(C_IN),
5.1.4 Examples
 1. Gate-level multiplexer:
 We will design a 4-to-1 multiplexer with 2 select
signals. Multiplexers serve a useful purpose in logic
design. They can connect two or more sources to a
single destination. They can also be used to
implement Boolean functions.
Figure 5-4. 4-to-1 Multiplexer
8
4-t0-1 multiplexer
Figure 5-5. Logic Diagram for Multiplexer
9
Verilog Description of 4-t0-1
Multiplexer
module mux4_to_1 (out, i0, i1, i2, i3, s1, s0); // Port list
output out; // Port declarations from the I/O diagram
input i0, i1, i2, i3;
input s1, s0;
wire s1n, s0n; // Internal wire declarations
wire y0, y1, y2, y3;
not (s1n, s1); // Gate instantiations Create s1n and s0n
signals.
not (s0n, s0);
and (y0, i0, s1n, s0n); // 3-input and gates instantiated
and (y1, i1, s1n, s0);
and (y2, i2, s1, s0n);
and (y3, i3, s1, s0);
or (out, y0, y1, y2, y3); // 4-input or gate instantiated
endmodule
10
Stimulus for Multiplexer
module stimulus; // Define the stimulus module (no
ports)
reg IN0, IN1, IN2, IN3; // Declare variables to inputs
reg S1, S0;
wire OUTPUT; // Declare output wire
Mux4_to_1 mymux(OUTPUT, IN0, IN1, IN2, IN3, S1,
S0);
initial
Begin
IN0 = 1; IN1 = 0; IN2 = 1; IN3 = 0;
#1 $display("IN0= %b, IN1= %b, IN2= %b,
IN3=%bn",IN0,IN1,IN2,IN3);
S1 = 0; S0 = 0;
#1 $display("S1 = %b, S0 = %b, OUTPUT = %b n",
11
Stimulus for multiplexer
S1 = 0; S0 = 1; // choose IN1
#1 $display("S1 = %b, S0 = %b, OUTPUT = %b n",
S1, S0, OUTPUT);
S1 = 1; S0 = 0; // choose IN2
#1 $display("S1 = %b, S0 = %b, OUTPUT = %b n",
S1, S0, OUTPUT);
S1 = 1; S0 = 1; // choose IN3
#1 $display("S1 = %b, S0 = %b, OUTPUT = %b n",
S1, S0, OUTPUT);
end
endmodule
12
Output of simulation
The output of the simulation is shown below. Each
combination of the select signals is tested.
IN0= 1, IN1= 0, IN2= 1, IN3= 0
S1 = 0, S0 = 0, OUTPUT = 1
S1 = 0, S0 = 1, OUTPUT = 0
S1 = 1, S0 = 0, OUTPUT = 1
S1 = 1, S0 = 1, OUTPUT = 0
13
6.5 Examples
We describe the multiplexer, using dataflow statements
Method 1: logic equation
 We can use assignment statements instead of gates to
model the logic equations of the multiplexer (see
Example 6-2). Notice that everything is same as the gate-
level Verilog description except that computation of out is
done by specifying one logic equation by using operators
instead of individual gate instantiations.
Example 6-2 4-to-1 Multiplexer, Using Logic Equations
// Module 4-to-1 multiplexer using data flow. logic equation
Compare to gate-level model
module mux4_to_1 (out, i0, i1, i2, i3, s1, s0);
output out;
input i0, i1, i2, i3;
input s1, s0;
assign out = (~s1 & ~s0 & i0)|(~s1 & s0 & i1) |(s1 & ~s0
& i2) |(s1 & s0 & i3) ; ////Logic equation for out
endmodule
14
Method 2: conditional operator
 There is a more concise way to specify the 4-to-1
multiplexers. Conditional Operator.
 Example 6-3 4-to-1 Multiplexer, Using Conditional
Operators
 // Module 4-to-1 multiplexer using data flow. Conditional
operator.
module multiplexer4_to_1 (out, i0, i1, i2, i3, s1, s0);
output out; // Port declarations from the I/O diagram
input i0, i1, i2, i3;
input s1, s0;
assign out = s1 ? ( s0 ? i3 : i2) : (s0 ? i1 : i0) ;
// Use nested conditional operator
endmodule
15
7.9 Examples(Behavioral
Description)
7.9.1 4-to-1 Multiplexer
 Example 7-35 Behavioral 4-to-1 Multiplexer
module mux4_to_1 (out, i0, i1, i2, i3, s1, s0);
output out; // Port declarations from the I/O diagram
input i0, i1, i2, i3;
input s1, s0;
reg out; //output declared as register
always @(s1 or s0 or i0 or i1 or i2 or i3)
begin
case ({s1, s0})
2'b00: out = i0;
2'b01: out = i1;
2'b10: out = i2;
2'b11: out = i3;
default: out = 1'bx;
endcase
end
endmodule
16
Gate instantiation
 More than two inputs can be specified in a gate instantiation.
Gates with more than two inputs are instantiated by simply
adding more input ports in the gate instantiation (see Example
5-1). Verilog automatically instantiates the appropriate gate.
17
5.1.2 Buf/Not Gates
 Two basic buf/not gate primitives are provided in
Verilog.
 The symbols for these logic gates are shown in
Figure 5-2.
Figure 5-2. Buf and Not Gates
18
4-Bit Ripple carry Full adder
module fulladd4(sum, c_out, a, b, c_in); // Define a
4-bit FA
output [3:0] sum; // I/O port declarations
output c_out;
input[3:0] a, b;
input c_in;
wire c1, c2, c3;
fulladd fa0(sum[0], c1, a[0], b[0], c_in);
fulladd fa1(sum[1], c2, a[1], b[1], c1);
fulladd fa2(sum[2], c3, a[2], b[2], c2);
fulladd fa3(sum[3], c_out, a[3], b[3], c3);
endmodule
Figure 5-7. 4-bit Ripple Carry Full Adder
19
1-bit Full adder
Example 5-7 Verilog Description for 1-bit Full Adder
module fulladd(sum, c_out, a, b, c_in); // Define a 1-
bit FA
output sum, c_out; // I/O port declarations
input a, b, c_in;
wire s1, c1, c2; // Internal nets
xor (s1, a, b); // Instantiate logic gate primitives
and (c1, a, b);
xor (sum, s1, c_in);
and (c2, s1, c_in);
xor (c_out, c2, c1);
endmodule
20
Example 5-9 Stimulus for 4-bit Ripple Carry Full Adder
module stimulus; // Define the stimulus (top level module)
reg [3:0] A, B; // Set up variables
reg C_IN;
wire [3:0] SUM;
wire C_OUT;
// Instantiate the 4-bit full adder. call it FA1_4
fulladd4 FA1_4(SUM, C_OUT, A, B, C_IN);
// Set up the monitoring for the signal values
initial
begin
$monitor($time," A= %b, B=%b, C_IN= %b, --- C_OUT=
%b, SUM= %bn",A, B, C_IN, C_OUT, SUM);
end
initial
21
Stimulus code for 4-bit Ripple carry full adder
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
22
The output of the simulation is shown below.
0 A= 0000, B=0000, C_IN= 0, --- C_OUT= 0, SUM=
0000
5 A= 0011, B=0100, C_IN= 0, --- C_OUT= 0, SUM=
0111
10 A= 0010, B=0101, C_IN= 0, --- C_OUT= 0, SUM=
0111
15 A= 1001, B=1001, C_IN= 0, --- C_OUT= 1, SUM=
0010
20 A= 1010, B=1111, C_IN= 0, --- C_OUT= 1, SUM=
1001
25 A= 1010, B=0101, C_IN= 1,, C_OUT= 1, SUM=
0000
23
Method 2: full adder with carry
lookahead
module fulladd4(sum, c_out, a, b, c_in);
output [3:0] sum; // Inputs and outputs
output c_out;
input [3:0] a,b;
input c_in;
wire p0,g0, p1,g1, p2,g2, p3,g3; // Internal wires
wire c4, c3, c2, c1;
24
assign p0 = a[0] ^ b[0], // compute the p for each stage
p1 = a[1] ^ b[1],
p2 = a[2] ^ b[2],
p3 = a[3] ^ b[3];
assign g0 = a[0] & b[0], // compute the g for each stage
g1 = a[1] & b[1],
g2 = a[2] & b[2],
g3 = a[3] & b[3];
assign c1 = g0 | (p0 & c_in), // compute the carry for each
stage
c2 = g1 | (p1 & g0) | (p1 & p0 & c_in),
c3 = g2 | (p2 & g1) | (p2 & p1 & g0) | (p2 & p1 & p0 &
c_in),
c4 = g3 | (p3 & g2) | (p3 & p2 & g1) | (p3 & p2 & p1 & g0)
|(p3 & p2 & p1 & p0 & c_in);
assign sum[0] = p0 ^ c_in, // Compute Sum
sum[1] = p1 ^ c1,
sum[2] = p2 ^ c2,
sum[3] = p3 ^ c3;
assign c_out = c4; // Assign carry output
 REFERANCE SOURCE
 Verilog HDL by samir palnitkar 2nd edition

More Related Content

Similar to mod-4.pptx

Nefrock勉強会 in大岡山「FPGAでゲーム機を作ろう!の会」Day4
Nefrock勉強会 in大岡山「FPGAでゲーム機を作ろう!の会」Day4Nefrock勉強会 in大岡山「FPGAでゲーム機を作ろう!の会」Day4
Nefrock勉強会 in大岡山「FPGAでゲーム機を作ろう!の会」Day4
Kaku Tomohiro
 
8255.ppt
8255.ppt8255.ppt
Fpga 04-verilog-programming
Fpga 04-verilog-programmingFpga 04-verilog-programming
Fpga 04-verilog-programming
Malik Tauqir Hasan
 
Task i
Task iTask i
Task i
Darshil Shah
 
Microprocessor Basics 8085-8255 ch-5
Microprocessor Basics 8085-8255 ch-5Microprocessor Basics 8085-8255 ch-5
Microprocessor Basics 8085-8255 ch-5
Neelam Kapoor
 
Embedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programmingEmbedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programming
Ikhwan_Fakrudin
 
vlsi design using verilog presentaion 1
vlsi design using verilog   presentaion 1vlsi design using verilog   presentaion 1
vlsi design using verilog presentaion 1
MANDHASAIGOUD1
 
Verilog_Overview.pdf
Verilog_Overview.pdfVerilog_Overview.pdf
Verilog_Overview.pdf
QuangHuyDo3
 
Verilog Lecture2 thhts
Verilog Lecture2 thhtsVerilog Lecture2 thhts
Verilog Lecture2 thhts
Béo Tú
 
8 bit single cycle processor
8 bit single cycle processor8 bit single cycle processor
8 bit single cycle processor
Dhaval Kaneria
 
VERILOG CODE
VERILOG CODEVERILOG CODE
VERILOG CODE
Dhaval Kaneria
 
verilog
verilogverilog
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdf
forwardcom41
 
Verilog VHDL code Parallel adder
Verilog VHDL code Parallel adder Verilog VHDL code Parallel adder
Verilog VHDL code Parallel adder
Bharti Airtel Ltd.
 
knowledge in daily life.ppt
knowledge in daily life.pptknowledge in daily life.ppt
knowledge in daily life.ppt
SunilSharma941036
 
Verilog 語法教學
Verilog 語法教學 Verilog 語法教學
Verilog 語法教學
艾鍗科技
 
# peripheral registers .equ PWR_BASE0x40007000 .equ PWR_CR0x00 .docx
# peripheral registers  .equ PWR_BASE0x40007000    .equ PWR_CR0x00  .docx# peripheral registers  .equ PWR_BASE0x40007000    .equ PWR_CR0x00  .docx
# peripheral registers .equ PWR_BASE0x40007000 .equ PWR_CR0x00 .docx
mayank272369
 
Digital system design practical file
Digital system design practical fileDigital system design practical file
Digital system design practical file
Archita Misra
 
8255_Ppi new
8255_Ppi new8255_Ppi new
8255_Ppi new
Monica Gunjal
 
Assic 6th Lecture
Assic 6th LectureAssic 6th Lecture
Assic 6th Lecture
babak danyal
 

Similar to mod-4.pptx (20)

Nefrock勉強会 in大岡山「FPGAでゲーム機を作ろう!の会」Day4
Nefrock勉強会 in大岡山「FPGAでゲーム機を作ろう!の会」Day4Nefrock勉強会 in大岡山「FPGAでゲーム機を作ろう!の会」Day4
Nefrock勉強会 in大岡山「FPGAでゲーム機を作ろう!の会」Day4
 
8255.ppt
8255.ppt8255.ppt
8255.ppt
 
Fpga 04-verilog-programming
Fpga 04-verilog-programmingFpga 04-verilog-programming
Fpga 04-verilog-programming
 
Task i
Task iTask i
Task i
 
Microprocessor Basics 8085-8255 ch-5
Microprocessor Basics 8085-8255 ch-5Microprocessor Basics 8085-8255 ch-5
Microprocessor Basics 8085-8255 ch-5
 
Embedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programmingEmbedded system (Chapter 3) io_port_programming
Embedded system (Chapter 3) io_port_programming
 
vlsi design using verilog presentaion 1
vlsi design using verilog   presentaion 1vlsi design using verilog   presentaion 1
vlsi design using verilog presentaion 1
 
Verilog_Overview.pdf
Verilog_Overview.pdfVerilog_Overview.pdf
Verilog_Overview.pdf
 
Verilog Lecture2 thhts
Verilog Lecture2 thhtsVerilog Lecture2 thhts
Verilog Lecture2 thhts
 
8 bit single cycle processor
8 bit single cycle processor8 bit single cycle processor
8 bit single cycle processor
 
VERILOG CODE
VERILOG CODEVERILOG CODE
VERILOG CODE
 
verilog
verilogverilog
verilog
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdf
 
Verilog VHDL code Parallel adder
Verilog VHDL code Parallel adder Verilog VHDL code Parallel adder
Verilog VHDL code Parallel adder
 
knowledge in daily life.ppt
knowledge in daily life.pptknowledge in daily life.ppt
knowledge in daily life.ppt
 
Verilog 語法教學
Verilog 語法教學 Verilog 語法教學
Verilog 語法教學
 
# peripheral registers .equ PWR_BASE0x40007000 .equ PWR_CR0x00 .docx
# peripheral registers  .equ PWR_BASE0x40007000    .equ PWR_CR0x00  .docx# peripheral registers  .equ PWR_BASE0x40007000    .equ PWR_CR0x00  .docx
# peripheral registers .equ PWR_BASE0x40007000 .equ PWR_CR0x00 .docx
 
Digital system design practical file
Digital system design practical fileDigital system design practical file
Digital system design practical file
 
8255_Ppi new
8255_Ppi new8255_Ppi new
8255_Ppi new
 
Assic 6th Lecture
Assic 6th LectureAssic 6th Lecture
Assic 6th Lecture
 

Recently uploaded

原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
ydzowc
 
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
upoux
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...
Prakhyath Rai
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
MadhavJungKarki
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
aryanpankaj78
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
AjmalKhan50578
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 08 Doors and Windows.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 08 Doors and Windows.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 08 Doors and Windows.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 08 Doors and Windows.pdf
Yasser Mahgoub
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
VANDANAMOHANGOUDA
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
UReason
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
Yasser Mahgoub
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
171ticu
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
Prakhyath Rai
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
PKavitha10
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
Paris Salesforce Developer Group
 

Recently uploaded (20)

原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
 
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...Software Engineering and Project Management - Software Testing + Agile Method...
Software Engineering and Project Management - Software Testing + Agile Method...
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 08 Doors and Windows.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 08 Doors and Windows.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 08 Doors and Windows.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 08 Doors and Windows.pdf
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
 

mod-4.pptx

  • 2. 2 Modules and Ports: The SR latch has S and R as the input ports and Q and Qbar as the output ports. The SR latch and its stimulus can be modeled as shown in Example 4-1. Example 4-1 Components of SR Latch(Design): module SR_latch(Q, Qbar, Sbar, Rbar); output Q, Qbar; //Port declarations input Sbar, Rbar; nand n1(Q, Sbar, Qbar); nand n2(Qbar, Rbar, Q); endmodule
  • 3. Stimulus block 3  // Module name and port list // Stimulus module module Top; wire q,qbar; reg set, reset; SR_latch m1(q, qbar, ~set, ~reset); initial begin $monitor($time, " set = %b, reset= %b, q= %bn",set,reset,q); set = 0; reset = 0; #5 reset = 1; #5 reset = 0; #5 set = 1; end endmodule
  • 4. Port Declarations 4 1.module fulladd4(sum, c_out, a, b, c_in); // port declarations section output[3:0] sum; output c_out; input [3:0] a, b; input c_in;//End port declarations section ... <module internals> ... endmodule 2.Example 4-4 Port Declarations for DFF module DFF(q, d, clk, reset); output q; reg q; // Output port q holds value; therefore it is declared as reg. input d, clk, reset; ... ... endmodule
  • 5. Port Declaration 5 Note that the module fulladd4 in Example 4-3 can be declared using an ANSI C style syntax to specify the ports of that module. Each declared port provides the complete information about the port. Example 4-5 shows this alternate syntax. This syntax avoids the duplication of naming the ports in both the module definition statement and the module port list definitions. If a port is declared but no data type is specified, then, under specific circumstances, the signal will default to a wire data type. Example 4-5 ANSI C Style Port Declaration Syntax module fulladd4(output reg [3:0] sum, output reg c_out, input [3:0] a, b, //wire by default input c_in); //wire by default ... <module internals> ...
  • 6. 6
  • 7. Connecting ports by name 7  For large designs where modules have, say, 50 ports, remembering the order of the ports in the module definition is impractical and error-prone.  Verilog provides the capability to connect external signals to ports by the port names, rather than by position.  // Instantiate module fa_byname and connect signals to ports by name fulladd4 fa_byname(.c_out(C_OUT), .sum(SUM), .b(B),.c_in(C_IN), .a(A),);  // Instantiate module fa_byname and connect signals to ports by name fulladd4 fa_byname(.sum(SUM), .b(B), .c_in(C_IN),
  • 8. 5.1.4 Examples  1. Gate-level multiplexer:  We will design a 4-to-1 multiplexer with 2 select signals. Multiplexers serve a useful purpose in logic design. They can connect two or more sources to a single destination. They can also be used to implement Boolean functions. Figure 5-4. 4-to-1 Multiplexer 8
  • 9. 4-t0-1 multiplexer Figure 5-5. Logic Diagram for Multiplexer 9
  • 10. Verilog Description of 4-t0-1 Multiplexer module mux4_to_1 (out, i0, i1, i2, i3, s1, s0); // Port list output out; // Port declarations from the I/O diagram input i0, i1, i2, i3; input s1, s0; wire s1n, s0n; // Internal wire declarations wire y0, y1, y2, y3; not (s1n, s1); // Gate instantiations Create s1n and s0n signals. not (s0n, s0); and (y0, i0, s1n, s0n); // 3-input and gates instantiated and (y1, i1, s1n, s0); and (y2, i2, s1, s0n); and (y3, i3, s1, s0); or (out, y0, y1, y2, y3); // 4-input or gate instantiated endmodule 10
  • 11. Stimulus for Multiplexer module stimulus; // Define the stimulus module (no ports) reg IN0, IN1, IN2, IN3; // Declare variables to inputs reg S1, S0; wire OUTPUT; // Declare output wire Mux4_to_1 mymux(OUTPUT, IN0, IN1, IN2, IN3, S1, S0); initial Begin IN0 = 1; IN1 = 0; IN2 = 1; IN3 = 0; #1 $display("IN0= %b, IN1= %b, IN2= %b, IN3=%bn",IN0,IN1,IN2,IN3); S1 = 0; S0 = 0; #1 $display("S1 = %b, S0 = %b, OUTPUT = %b n", 11
  • 12. Stimulus for multiplexer S1 = 0; S0 = 1; // choose IN1 #1 $display("S1 = %b, S0 = %b, OUTPUT = %b n", S1, S0, OUTPUT); S1 = 1; S0 = 0; // choose IN2 #1 $display("S1 = %b, S0 = %b, OUTPUT = %b n", S1, S0, OUTPUT); S1 = 1; S0 = 1; // choose IN3 #1 $display("S1 = %b, S0 = %b, OUTPUT = %b n", S1, S0, OUTPUT); end endmodule 12
  • 13. Output of simulation The output of the simulation is shown below. Each combination of the select signals is tested. IN0= 1, IN1= 0, IN2= 1, IN3= 0 S1 = 0, S0 = 0, OUTPUT = 1 S1 = 0, S0 = 1, OUTPUT = 0 S1 = 1, S0 = 0, OUTPUT = 1 S1 = 1, S0 = 1, OUTPUT = 0 13
  • 14. 6.5 Examples We describe the multiplexer, using dataflow statements Method 1: logic equation  We can use assignment statements instead of gates to model the logic equations of the multiplexer (see Example 6-2). Notice that everything is same as the gate- level Verilog description except that computation of out is done by specifying one logic equation by using operators instead of individual gate instantiations. Example 6-2 4-to-1 Multiplexer, Using Logic Equations // Module 4-to-1 multiplexer using data flow. logic equation Compare to gate-level model module mux4_to_1 (out, i0, i1, i2, i3, s1, s0); output out; input i0, i1, i2, i3; input s1, s0; assign out = (~s1 & ~s0 & i0)|(~s1 & s0 & i1) |(s1 & ~s0 & i2) |(s1 & s0 & i3) ; ////Logic equation for out endmodule 14
  • 15. Method 2: conditional operator  There is a more concise way to specify the 4-to-1 multiplexers. Conditional Operator.  Example 6-3 4-to-1 Multiplexer, Using Conditional Operators  // Module 4-to-1 multiplexer using data flow. Conditional operator. module multiplexer4_to_1 (out, i0, i1, i2, i3, s1, s0); output out; // Port declarations from the I/O diagram input i0, i1, i2, i3; input s1, s0; assign out = s1 ? ( s0 ? i3 : i2) : (s0 ? i1 : i0) ; // Use nested conditional operator endmodule 15
  • 16. 7.9 Examples(Behavioral Description) 7.9.1 4-to-1 Multiplexer  Example 7-35 Behavioral 4-to-1 Multiplexer module mux4_to_1 (out, i0, i1, i2, i3, s1, s0); output out; // Port declarations from the I/O diagram input i0, i1, i2, i3; input s1, s0; reg out; //output declared as register always @(s1 or s0 or i0 or i1 or i2 or i3) begin case ({s1, s0}) 2'b00: out = i0; 2'b01: out = i1; 2'b10: out = i2; 2'b11: out = i3; default: out = 1'bx; endcase end endmodule 16
  • 17. Gate instantiation  More than two inputs can be specified in a gate instantiation. Gates with more than two inputs are instantiated by simply adding more input ports in the gate instantiation (see Example 5-1). Verilog automatically instantiates the appropriate gate. 17
  • 18. 5.1.2 Buf/Not Gates  Two basic buf/not gate primitives are provided in Verilog.  The symbols for these logic gates are shown in Figure 5-2. Figure 5-2. Buf and Not Gates 18
  • 19. 4-Bit Ripple carry Full adder module fulladd4(sum, c_out, a, b, c_in); // Define a 4-bit FA output [3:0] sum; // I/O port declarations output c_out; input[3:0] a, b; input c_in; wire c1, c2, c3; fulladd fa0(sum[0], c1, a[0], b[0], c_in); fulladd fa1(sum[1], c2, a[1], b[1], c1); fulladd fa2(sum[2], c3, a[2], b[2], c2); fulladd fa3(sum[3], c_out, a[3], b[3], c3); endmodule Figure 5-7. 4-bit Ripple Carry Full Adder 19
  • 20. 1-bit Full adder Example 5-7 Verilog Description for 1-bit Full Adder module fulladd(sum, c_out, a, b, c_in); // Define a 1- bit FA output sum, c_out; // I/O port declarations input a, b, c_in; wire s1, c1, c2; // Internal nets xor (s1, a, b); // Instantiate logic gate primitives and (c1, a, b); xor (sum, s1, c_in); and (c2, s1, c_in); xor (c_out, c2, c1); endmodule 20
  • 21. Example 5-9 Stimulus for 4-bit Ripple Carry Full Adder module stimulus; // Define the stimulus (top level module) reg [3:0] A, B; // Set up variables reg C_IN; wire [3:0] SUM; wire C_OUT; // Instantiate the 4-bit full adder. call it FA1_4 fulladd4 FA1_4(SUM, C_OUT, A, B, C_IN); // Set up the monitoring for the signal values initial begin $monitor($time," A= %b, B=%b, C_IN= %b, --- C_OUT= %b, SUM= %bn",A, B, C_IN, C_OUT, SUM); end initial 21
  • 22. Stimulus code for 4-bit Ripple carry full adder 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 22
  • 23. The output of the simulation is shown below. 0 A= 0000, B=0000, C_IN= 0, --- C_OUT= 0, SUM= 0000 5 A= 0011, B=0100, C_IN= 0, --- C_OUT= 0, SUM= 0111 10 A= 0010, B=0101, C_IN= 0, --- C_OUT= 0, SUM= 0111 15 A= 1001, B=1001, C_IN= 0, --- C_OUT= 1, SUM= 0010 20 A= 1010, B=1111, C_IN= 0, --- C_OUT= 1, SUM= 1001 25 A= 1010, B=0101, C_IN= 1,, C_OUT= 1, SUM= 0000 23
  • 24. Method 2: full adder with carry lookahead module fulladd4(sum, c_out, a, b, c_in); output [3:0] sum; // Inputs and outputs output c_out; input [3:0] a,b; input c_in; wire p0,g0, p1,g1, p2,g2, p3,g3; // Internal wires wire c4, c3, c2, c1; 24
  • 25. assign p0 = a[0] ^ b[0], // compute the p for each stage p1 = a[1] ^ b[1], p2 = a[2] ^ b[2], p3 = a[3] ^ b[3]; assign g0 = a[0] & b[0], // compute the g for each stage g1 = a[1] & b[1], g2 = a[2] & b[2], g3 = a[3] & b[3]; assign c1 = g0 | (p0 & c_in), // compute the carry for each stage c2 = g1 | (p1 & g0) | (p1 & p0 & c_in), c3 = g2 | (p2 & g1) | (p2 & p1 & g0) | (p2 & p1 & p0 & c_in), c4 = g3 | (p3 & g2) | (p3 & p2 & g1) | (p3 & p2 & p1 & g0) |(p3 & p2 & p1 & p0 & c_in); assign sum[0] = p0 ^ c_in, // Compute Sum sum[1] = p1 ^ c1, sum[2] = p2 ^ c2, sum[3] = p3 ^ c3; assign c_out = c4; // Assign carry output
  • 26.  REFERANCE SOURCE  Verilog HDL by samir palnitkar 2nd edition