verilog hdl - web.cs.hacettepe.edu.trbbm231/files/verilog_tutorial.pdf1. implement a 1-bit full...
TRANSCRIPT
![Page 1: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/1.jpg)
Verilog HDL A Brief Introduction
https://web.cs.hacettepe.edu.tr/~bbm231/ https://piazza.com/hacettepe.edu.tr/fall2020/bbm231233
Fall 2020
![Page 2: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/2.jpg)
Outline
● Introduction
● Hardware Description Languages
● Different Levels of Abstraction
● Getting Started With Verilog
● Verilog Language Features
● Test benches and Simulation
![Page 3: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/3.jpg)
Introduction
As digital and electronic circuit designs grew in size and complexity, capturing a large design at the gate level of abstraction with schematic-based design became
● Too complex,● Prone to error, ● Extremely time-consuming.
Complex digital circuit designs require a lot more time for development, synthesis, simulation and debugging.
Solution? Computer Aided Design (CAD) tools
Nowadays, billions of transistors per chip!
Moore’s Law?
● Based on Hardware Description Languages
![Page 4: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/4.jpg)
Hardware Description Language (HDL)
HDLs are specialized computer languages used to program electronic and digital logic circuits.
● High level languages with which we can specify our HW to analyze its design before actual fabrication.
● Verilog● VHDL
Two most popular HDLs: Other popular HDLs:
● SystemC● SystemVerilog● ...
![Page 5: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/5.jpg)
Design Flow (Simplified)
Some other steps in design:
● Simulation to verify the design (at different levels)
● Formal verification
● etc.
Design Idea
Chip / Board
Behavioral Design
Datapath Design
Logic Design
Physical Design
Manufacturing
![Page 6: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/6.jpg)
Different Levels of Abstraction
Behavioral vs. Structural Design
● Behavioral: the highest level of abstraction - specifying the functionality in terms of its behavior (e.g. Boolean equations, truth tables, algorithms, code, etc.).
● Structural: a netlist specification of components and their interconnections (e.g. gates, transistors, even functional modules).
WHAT, not HOW.
a collection of registers linked by
combinational logic
We will use both.
Gate
Switch
RTLBoolean
LoopsProcesses
![Page 7: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/7.jpg)
Different Levels of Abstraction
● Behavioral modeling:
● Structural modeling:
Example: Full Adder
FAA
B
Cin
Sum
Cout
Truth table
module full_adder(x,y,cin,s,cout);input x,y,cin;output s,cout;wire s1,c1,c2,c3;xor(s1,x,y);xor(s,cin,s1);and(c1,x,y);and(c2,y,cin);and(c3,x,cin);or(cout,c1,c2,c3);
endmodule
Circuit diagram
Verilog module with
structural design
In terms of Boolean
expressions
![Page 8: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/8.jpg)
Getting StartedWith Verilog
Describing a digital system as a set of modules
Module 1module …
endmodule
Module 2
Module 3
Module 2
Module 4
Module 4
Module 4
Module 4
● Modules can have interfaces to other modules (instantiation = creating a copy).
● Modules are connected using nets.Ess
ential C
omponents
of Veril
og code
![Page 9: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/9.jpg)
What can we do?
● Simulation to verify the system (test benches)
● Synthesis to map to hardware (low-level primitives, ASIC, FPGA)
We’ll be doing this.
![Page 10: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/10.jpg)
Open source or commercial software available
Commercial CAD tools
Specific software (e.d. Xilinx ISE or Vivado)
Development Process
Verilog Module(s)
SIMULATION
Evaluate Result
Testbench
ASIC
SYNTHESIS
Verilog Module(s)
FPGA
![Page 11: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/11.jpg)
Verilog Language Features
Operators
![Page 12: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/12.jpg)
Verilog Language Features
Operators
Evaluates to True or False
![Page 13: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/13.jpg)
Verilog Language Features
Operators
Operate on numbers, return True or False
![Page 14: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/14.jpg)
Verilog Language Features
Operators
Operate on bits, return a
value that is also a bit.
![Page 15: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/15.jpg)
Verilog Language Features
Operators
Reduction, conditional, concatenation, and replication operators also available.
![Page 16: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/16.jpg)
Verilog Language Features
Verilog supports 4 value levels:
Data Values
Value Level Represents
0 Logic 0 state
1 Logic 1 state
x Unknown logic state
z High impedance state
● All unconnected nets are set to ‘z’.● All register variables are set to ‘x’.
![Page 17: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/17.jpg)
Verilog Language Features
Module - the basic unit of hardware in Verilog
● Cannot contain definitions of other modules,● Can be instantiated within another module - hierarchy of modules.
Differe
nt than
callin
g a fu
nction
in progra
mm
ing lang.
Every instantiation
adds to
area!
Temporary connections (wires)
module module_name (list_of_ports);
input/output declarations
Local net declarations
Parallel statements
endmoduleWhy parallel?
Module 1
Module 2
Module 4
Module 4
![Page 18: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/18.jpg)
Verilog Language FeaturesModule example: A simple AND function
Assign statement: assign var = expression;
● used typically for combinational circuits.● continuous assignment● LHS must be “net” type var (usually “wire”)● RHS can be both “register” or “net” type
Is this a structural or
behavioral description?
Not synced
with clock!
![Page 19: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/19.jpg)
Verilog Language Features
Module example 2: A 2-level combinational circuit
This is also a
behavioral description.
![Page 20: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/20.jpg)
Verilog Language Features
A variable can be:
A. Net○ Must be continuously driven,○ Cannot be used to store a value,○ Models connections between continuous assignments and instantiations,○ 1-bit values by default, unless declared as vectors explicitly.○ Default value of a net is “Z” - high impedance state.
B. Register○ Retains the last value assigned to it,○ Usually used to represent storage elements (sometimes in combinational circuits),○ May or may not map to a HW register during synthesis.○ Default value of a reg data type is “X”.
Data Types
wire, wor, wand, tri, supply0, supply1, etc.
reg, integer, real, time
![Page 21: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/21.jpg)
Verilog Language Features
net example:
A.
Data Types
Is this a valid design?
![Page 22: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/22.jpg)
Verilog Language Features
net example:
A.
Data Types
Wrong design!For these inputs, f will
be indeterminate!
![Page 23: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/23.jpg)
Verilog Language Features
net example - correct design:
A.
Data Types
![Page 24: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/24.jpg)
Verilog Language Features
net example 2:
A.
Data Types
Is this a structural or
behavioral description?
![Page 25: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/25.jpg)
Verilog Language Features
reg example:
● Declaration explicitly specifies the size (default is 1-bit):○ reg x, y; // 1-bit register variables○ reg [7:0] bus; // An 8-bit bus
● Treated as an unsigned number in arithmetic expressions.
● MUST be used when modeling actual sequential HW, e.g. counters, shift registers, etc.
● Two types of assignments possible:○ A = B + C;○ A <= B + C;
Data Types
A must be a reg type var
For 2’s comp. signed
use integer data type
![Page 26: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/26.jpg)
Verilog Language Features
reg example - 32-bit counter with synchronous reset:
Data Types
Otherwise: compiler error
Because we must have a reg type var at LHS
Any variable assigned within the always block must be of type reg.
How to fix this?
If rst is
high, reset
occurs at the positiv
e
edge of the next clock.
![Page 27: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/27.jpg)
reg example - solution: 32-bit counter with asynchronous reset:
Verilog Language Features Data Types
Reset occurs whenever rst goes high.
![Page 28: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/28.jpg)
Verilog Language Features
Integer example:
● General purpose register data type,● 2’s complement signed integer in arithmetic expressions,● Default size is 32 bits.
○ wire [15:0] X, Y;○ integer C;○ C = X + Y;
Data Types
Other register data types: real, time.
Synthesis tool deduces that C is 17 bits (16 bits + a carry)
![Page 29: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/29.jpg)
Verilog Language Features
Vectors
● Both Net or reg type variables can be declared as vectors: multiple bit widths
● Specifying width with: [MSB:LSB]
![Page 30: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/30.jpg)
Verilog Language Features
Vectors
● Parts of a vector can be addressed and used in an expression:
Multi-dimensional arrays and memories also possible.
![Page 31: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/31.jpg)
Verilog Language Features
Constant Values
● Sized or unsized form,● Syntax:
○ <size>’<base><number>● Examples:
![Page 32: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/32.jpg)
Verilog Language Features
Parameters
● Constants with a given name,● Size deduced from the constant value itself:
![Page 33: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/33.jpg)
Verilog Language Features
Predefined Logic Gates
● Can be instantiated within a module to create a structural design.
Remember that Verilog
supports 4 value levels.
![Page 34: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/34.jpg)
Verilog Language Features
List of Some Primitive Gates
●
Number of inputs
can be arbitrary.
A 5-input AND gate
There are also other gates with
tristate control
● Output ports must be connected to a net
● Input ports may be either net or reg type vars
![Page 35: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/35.jpg)
Verilog Language Features
Two Ways to Specify Connectivity During Module Instantiation
Connectivity of the signal lines between two modules can be specified in 2 ways:
● Positional Association (Implicit)○ Parameters listed in the same order as in the original module description.
● Explicit Association○ Parameters explicitly listed in arbitrary order.
Module 2Module 1
Module 2
`include "module2_name.v"
![Page 36: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/36.jpg)
● Positional Association Example - Full Adder Using Half Adder Module
Verilog Language Features
Half Adder
Full Adder
Half Adder
Half AdderS
A
B
Cin Cout
A
B
S
Carry
![Page 37: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/37.jpg)
● Positional Association Example - Full Adder Using Half Adder Module
Verilog Language Features
Half AdderA
B
S
Carry
G1
G2
What is the equivalent behavioral design?
![Page 38: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/38.jpg)
● Positional Association Example - Full Adder Using Half Adder Module
Verilog Language Features
Half AdderA
B
S
Carry
=
G1
G2
![Page 39: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/39.jpg)
● Positional Association Example - Full Adder Using Half Adder Module
Verilog Language Features
w2
w1 w3
How do we use the half_adder module to implement a full adder?
Note the port order
![Page 40: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/40.jpg)
● Positional Association Example - Full Adder Using Half Adder Module
Verilog Language Features
w2
w1 w3
Note the port order
![Page 41: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/41.jpg)
● Explicit Association Example - Full Adder Using Half Adder Module
Verilog Language Features
w2
w1 w3
Ports are explicitly specified - order is
not important
Less chance for errors
![Page 42: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/42.jpg)
Verilog Language Features
Combinational vs. Sequential Circuits
Combinational: The output only depends on the present input.
Sequential: The output depends on both the present input and the previous output(s) (the state of the circuit).
![Page 43: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/43.jpg)
Verilog Language Features
Combinational vs. Sequential Circuits
Sequential logic: Blocks that have memory elements: Flip-Flops, Latches, Finite State Machines.● Triggered by a ‘clock’ event.
○ Latches are sensitive to level of the signal.○ Flip-flops are sensitive to the transitioning of clock
Combinational constructs are not sufficient. We need new constructs:
● always ● initial
![Page 44: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/44.jpg)
Verilog Language Features
Sequential Circuits
Whenever the event in the sensitivity list occurs, the statement is executed.
Remember our
counter example
![Page 45: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/45.jpg)
Verilog Language Features
Sequential Circuits
● Sequential statements are within an ‘always’ block,
● The sequential block is triggered with a change in the sensitivity list,
● Signals assigned within an always block must be declared as reg,
○ The values are preserved (memorized) when no change in the sensitivity list.
● We do not use ‘assign’ within the always block.
![Page 46: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/46.jpg)
Difference
between
Synchronous
and
Asynchronous
Sequential
Circuits
![Page 47: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/47.jpg)
Verilog Language Features
32-bit counter with synchronous reset:
Sequential Circuits
Otherwise: compiler error
Any variable assigned within the always block must be of type reg.
How to fix this?
If rst is
high, reset
occurs at the positiv
e
edge of the next clock.
Because we must have a reg type var at LHS
![Page 48: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/48.jpg)
Solution: 32-bit counter with asynchronous reset:
Verilog Language Features Sequential Circuits
Reset occurs whenever rst goes high.
![Page 49: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/49.jpg)
Verilog Language Features
Sequential Circuits
Blocking statements allow
sequential descriptions
![Page 50: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/50.jpg)
How to Simulate Verilog Module(s)
Testbench: provides stimulus to Unit-Under-Test (UUT) to verify its functionality, captures and analyzes the outputs.
Requirements:Inputs and outputs need to be connected to the test bench
Unit Under Test (UUT)
TESTBENCH
MonitorStimulus
![Page 51: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/51.jpg)
How to Simulate Verilog Module(s) Example
Suppose we want to design
and simulate this circuit.
We can choose either behavioral or structural design.
![Page 52: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/52.jpg)
How to Simulate Verilog Module(s) Example
Let’s choose structural design:
Which gates do we need, and what will the connections be?
![Page 53: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/53.jpg)
How to Simulate Verilog Module(s) Example
Let’s choose structural design:
![Page 54: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/54.jpg)
How to Simulate Verilog Module(s) Example
Let’s choose structural design:
![Page 55: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/55.jpg)
How to Simulate Verilog Module(s) Example
Let’s choose structural design:
![Page 56: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/56.jpg)
How to Simulate Verilog Module(s) Example
Now we need to provide stimulus and
monitor the outputs - TESTBENCH
Let’s choose structural design:
![Page 57: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/57.jpg)
How to Simulate Verilog Module(s) Example
Unit Under Test
TESTBENCH
Saved as function_Y.v
Saved as function_Y_testbench.v
Include the module to be tested.
`include “function_Y.v”
![Page 58: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/58.jpg)
How to Simulate Verilog Module(s) Example
Unit Under Test
TESTBENCH
Saved as function_Y.v
Saved as function_Y_testbench.v
Vars MUST be declared as regOutput as wire
`include “function_Y.v”
![Page 59: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/59.jpg)
How to Simulate Verilog Module(s) Example
Unit Under Test
TESTBENCH
Saved as function_Y.v
Saved as function_Y_testbench.v
Initialize Unit
Under Test (UUT)
`include “function_Y.v”
![Page 60: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/60.jpg)
How to Simulate Verilog Module(s) Example
Unit Under Test
TESTBENCH
Saved as function_Y.v
Saved as function_Y_testbench.v
initial block - gets executed once
`include “function_Y.v”
![Page 61: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/61.jpg)
How to Simulate Verilog Module(s) Example
Unit Under Test
TESTBENCH
Stimulus
Saved as function_Y.v
Saved as function_Y_testbench.v
`include “function_Y.v”
![Page 62: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/62.jpg)
How to Simulate Verilog Module(s) Example
Results can be viewed as waveforms:
![Page 63: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/63.jpg)
How to Simulate Verilog Module(s) Example
We can also monitor the changes and print them to the console using $monitor:
We can also use $dumpfile to dump variable changes to a file.
![Page 64: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/64.jpg)
Short Practice Example 1Implement a the circuit given below using structural design approach.
![Page 65: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/65.jpg)
Short Practice Example 1Implement a the circuit given below using structural design approach.
![Page 66: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/66.jpg)
Short Practice Example 1Implement a the circuit given below using structural design approach.
![Page 67: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/67.jpg)
Short Practice Example 1Implement a the circuit given below using structural design approach.
![Page 68: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/68.jpg)
Short Practice Example 1Implement a the circuit given below using structural design approach.
![Page 69: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/69.jpg)
Short Practice Example 1Implement a the circuit given below using structural design approach.
![Page 70: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/70.jpg)
Short Practice Example 1Implement a testbench for the Simple_Circuit.
`include “Simple_Circuit.v”
![Page 71: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/71.jpg)
Short Practice Example 1Implement a testbench for the Simple_Circuit.
`include “Simple_Circuit.v”
![Page 72: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/72.jpg)
Short Practice Example 1Implement a testbench for the Simple_Circuit.
`include “Simple_Circuit.v”
![Page 73: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/73.jpg)
Short Practice Example 1Implement a testbench for the Simple_Circuit.
`include “Simple_Circuit.v”
![Page 74: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/74.jpg)
Short Practice Example 1Implement a testbench for the Simple_Circuit.
`include “Simple_Circuit.v”
![Page 75: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/75.jpg)
Short Practice Example 1Implement a testbench for the Simple_Circuit.
`include “Simple_Circuit.v”
![Page 76: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/76.jpg)
Short Practice Example 1Implement a testbench for the Simple_Circuit.
Is the delay in ms, ns…?
`include “Simple_Circuit.v”
![Page 77: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/77.jpg)
Short Practice Example 1Implement a testbench for the Simple_Circuit.
You should specify the timescale`include “Simple_Circuit.v”
![Page 78: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/78.jpg)
Short Practice Example 2Implement the circuit specified by the given Boolean equations using behavioral design approach.
![Page 79: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/79.jpg)
Short Practice Example 2Implement the circuit specified by the given Boolean equations using behavioral design approach.
![Page 80: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/80.jpg)
Short Practice Example 2Implement the circuit specified by the given Boolean equations using behavioral design approach.
![Page 81: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/81.jpg)
Short Practice Example 2Implement the circuit specified by the given Boolean equations using behavioral design approach.
![Page 82: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/82.jpg)
Short Practice Example 2Implement the circuit specified by the given Boolean equations using behavioral design approach.
Think about how a
TESTBENCH would look like
![Page 83: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/83.jpg)
Questions?
![Page 84: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/84.jpg)
Lab ExampleImplement a 4-Bit Ripple Carry Adder in Verilog in the following steps:
1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding functions for Sum and Carry_out, write a Verilog module, test it by writing a testbench for all possible cases.
2. Implement a 4-Bit Ripple Carry Adder by instantiating your 1-Bit Full Adder module as many times as necessary. Use structural design approach and explicit association. Test it by writing an appropriate testbench.
4-Bit Ripple
Carry Adder
![Page 85: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/85.jpg)
Lab Example Solution:
sum = (A^B)^CCout = AB+BC+AC
Full_Adder.v module
Note the behavioral
description
![Page 86: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/86.jpg)
Full_Adder_Testbench.v module
Simulation results:
![Page 87: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/87.jpg)
Four_Bit_RCA.v module
Note the structural
description and
explicit association
A1A2A3A4
![Page 88: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/88.jpg)
Four_Bit_RCA_Testbench.v module
Only some test cases.Why not all?
How can we automate the process?
![Page 89: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/89.jpg)
Lab Example 2 - Sequential Circuits
![Page 90: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/90.jpg)
Lab Example 2 - Sequential Circuits
![Page 91: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/91.jpg)
A flip flop is a basic building block of sequential logic circuits. It is a circuit that has two stable states and can store one bit of state information. The output changes state by signals applied to one or more control inputs.
A basic D Flip Flop has a D (data) input, a clock (CLK) input and outputs Q and Q’ (the inverse of Q). Optionally it may also include the PR (Preset) and CLR (Clear) control inputs.
Lab Example 2 - Sequential Circuits
![Page 92: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/92.jpg)
Lab Example 2 - Sequential CircuitsVerilog codes for different implementations of D flip-flop:
![Page 93: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/93.jpg)
Lab Example 2 - Sequential CircuitsVerilog codes for different implementations of D flip-flop:
![Page 94: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/94.jpg)
Lab Example 2 - Sequential Circuits
Here we state the steps of designing a sequential circuit with an example circuit specification:
111 Sequence Detector: Design a circuit that outputs 1 when a sequence three consecutive 1’s is applied to input, and 0 otherwise.
Y
![Page 95: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/95.jpg)
Lab Example 2 - Sequential Circuits
![Page 96: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/96.jpg)
Lab Example 2 - Sequential Circuits
![Page 97: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/97.jpg)
Lab Example 2 - Sequential Circuits
![Page 98: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/98.jpg)
Lab Example 2 - Sequential Circuits
From the state table above we obtain the following input equations:
![Page 99: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/99.jpg)
Lab Example 2 - Sequential Circuits
![Page 100: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/100.jpg)
Lab Example 2 - Sequential Circuits
Let’s choose rising-edge D flip-flop
![Page 101: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/101.jpg)
Let’s look at the code in parts...
![Page 102: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/102.jpg)
present_state[1] to store A present_state[0] to store B
next_state[1] to represent DAnext_state[0] to represent DB
Include D_ff module
Declare I/O ports
![Page 103: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/103.jpg)
Instantiating D flip flops:
![Page 104: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/104.jpg)
Handle reset and update present_state on change of next_state:
Combinational circuit to implement the output:How would you make output y implemented
in structural design approach as well?
![Page 105: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/105.jpg)
Solution No. 2 - Behavioral design
Note different reset implementation
Note multiple always blocks
![Page 106: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/106.jpg)
Use parameter to give constant names to your states
Whenever input x or state change
![Page 107: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/107.jpg)
Lab Example 2 - Sequential Circuits
How would we design a testbench for a sequence detector?
The idea is to have an input bit stream (e.g. a 20-bit binary sequence),
and send one input bit at a time at each clock cycle (e.g. using shifting).
![Page 108: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/108.jpg)
Entire sample testbench code:
![Page 109: Verilog HDL - web.cs.hacettepe.edu.trbbm231/files/Verilog_Tutorial.pdf1. Implement a 1-Bit Full Adder using behavioral design approach. Fill in the truth table, find the corresponding](https://reader033.vdocument.in/reader033/viewer/2022052000/6011e05bf6acf558db7b975e/html5/thumbnails/109.jpg)
References
● Slides are mostly based on: NPTEL Online Certification Course on Hardware Modeling Using Verilog, by Prof. Indranil Sengupta, Department of Computer Science and Engineering, Indian Institute of Technology Kharagpur - Available online at: https://www.youtube.com/playlist?list=PLUtfVcb-iqn-EkuBs3arreilxa2UKIChl
● Digital Design, M. Morris Mano and Michael D. Ciletti, Prentice Hall.
● Verilog for Sequential Circuits, Design of Digital Circuits 2014, Srdjan Capkun, Frank K. Gürkaynak. Available online at: https://syssec.ethz.ch/content/dam/ethz/special-interest/infk/inst-infsec/system-security-group-dam/education/Digitaltechnik_14/09_Verilog_Sequential.pdf
● Digital VLSI Systems Design, A Design Manual for Implementation of Projects on FPGAs and ASICs Using Verilog, Dr. Seetharaman Ramachandran, Springer.