Anda di halaman 1dari 70

Verilog

EEN-611 FPGA Implementation of Signal Processing


Monday, August 12, 2019 2
Systems, Department of Electrical Engg., IIT Roorkee
HDL Tool Suites

1. Text editor – allows you to write , edit and save an HDL program
2. Compiler – responsible for parsing the HDL program, finding syntax errors,
and figuring out what the program says.
3. A Synthesizer – targets the design to a specific hardware technology such
as a PLD, CPLD, FPGA or ASIC
4. Simulator- the inputs to the simulator are the HDL program and a timed
sequence of inputs for the hardware it describes.
5. Test bench – The input sequence can be contained in another HDL
program, which is written in same language
6. Waveform editor - or it can be described graphically using another tool

The simulator runs the specified input sequence on the described


hardware and determines the values of the hardware’s internal signals and
its outputs over a specified over a period time.
The output of the simulator can include waveforms to be viewed using the
waveform editor, text files which lists signal values over simulated time,
error and warning messages that highlight unusual conditions.
EEN-611 FPGA Implementation of Signal Processing
Monday, August 12, 2019 3
Systems, Department of Electrical Engg., IIT Roorkee
HDL integrated Tool Suite:
1. Template generator – creates a text file with the outline of a commonly
used program structure, so the designer “can fill the blanks” to create a
source code.
input output declarations, logic structures like decoders, adder, and
registers and test benches.
2. Schematic viewer – may create a schematic diagram corresponding to a
HDL program based on the intermediate-language output of the compiler.
3. Translator- targets the compiler’s intermediate-language output to a real
device such as PLD, FPGA or ASIC.
4. Fitter –which fits the translated realization into the available resources on
the real device.
5. Chip viewer-lets the designer see how the design has been laid out on the
chip.
6. Timing analyzer – calculates the delays through some or all of the signal
paths in the final chip and produces a report showing the worst case paths
and their delays
7. Back annotator inserts delay clauses or statements in the original HDL
source program, corresponding to the delays calculated by the timing
analyzer.
EEN-611 FPGA Implementation of Signal Processing
Monday, August 12, 2019 4
Systems, Department of Electrical Engg., IIT Roorkee
HDL Based Design Flow

Front end begins with figuring out the basic approach and building blocks at
the block-diagram level.
Large logic designs, like software programs, are hierarchical and VHDL and
Verilog give a framework for defining modules and their interfaces
Writing HDL codes for modules, their interfaces and their internal details.
HDL compiler checks for syntax error and compatibility with other modules.
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 5
Engg., IIT Roorkee
Simulation allows to apply inputs to your design
Its just on piece of a larger step called verification

Verification – functional verification, timing verification


Functional verification- study the circuit logical operation independent of
timing considerations; gate delays and other timing parameters are
considered to be zero.
Timing verification-study the circuit’s operation including estimated
delays, and verify that the setup, hold and other timing requirements for
sequential devices are met.
Back-end stage
Synthesis- converting the HDL description into a set of primitives or
components that can be assembled in the target technology.
Fitting – maps the synthesized primitives or components into available
device resources.
Post fitting timing verification- In this stage the actual circuit delays due
to wire lengths, electrical loading, and other factors can be calculated
with reasonable precision.

EEN-611 FPGA Implementation of Signal Processing


Monday, August 12, 2019 6
Systems, Department of Electrical Engg., IIT Roorkee
Features:

Design may be decomposed hierarchically


Each design element has both a well-defined interface and a precise
functional specification
Functional specifications can use either a behavioral algorithm or an
actual hardware structure to define an elements operation.
Concurrency , timing, clocking can all be modeled. VHDL handles
asynchronous and synchronous sequential structures.
The logic operation and timing behavior of a design can be simulated.

EEN-611 FPGA Implementation of Signal Processing


Monday, August 12, 2019 7
Systems, Department of Electrical Engg., IIT Roorkee
Module is a text file containing declarations and statements

EEN-611 FPGA Implementation of Signal Processing


Monday, August 12, 2019 8
Systems, Department of Electrical Engg., IIT Roorkee
Module is a text file containing declarations and statements.
Declarations describe the names and types of the module’s inputs and
outputs, local signals, constants, variables and functions. These are strictly
used inside the module and are not visible outside.
Statements specify the operation of the module’s output and internal
signals.

Modelling:
1. Behavioural
2. Structural
3. Data Flow

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 9
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 10
Engg., IIT Roorkee
Verilog modules can instantiate other modules.
Higher level module may use lower level module multiple times.
Top-level modules may use the same lower level one.

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 11
Engg., IIT Roorkee
Comments
Single line comments begin with double slashes and end at the end of the
line //.
Multi-line long comments begin anywhere with /* and end anywhere with
*/.

Reserved words or Keywords:

module, input, output, assign and endmodule.

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 12
Engg., IIT Roorkee
Identifiers:
User identifier begin with letter or underscore and can contain letters,
digits, underscore (_), and dollar sign($).

Identifiers are
VrInhibit, X, Y, and Z.

Verilog is case sensitive for both keywords (lower case only) and
identifiers.
Identifiers XY, xy, Xy, xY are different.

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 13
Engg., IIT Roorkee
1. Keyword
2. Identifier
3. List of identifiers
4. Declarations
5. keyword
Input, output ports are signals through which module communicates with
other modules.

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 14
Engg., IIT Roorkee
Each port that is named in input/output list must have input, output, or
inout declarations.

The keyword input, output, inout is followed by comma separated list of


identifiers for signals or ports of corresponding type.

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 15
Engg., IIT Roorkee
The keyword specifies the signal direction as follows.
input The signal is an input to the module
output The signal is an output of the module.
reg declaration is needed to read inside other modules.
inout The signal can be used as a module input or output.

The signal can be multi-bit or vector.


It can be declared by range specification [msb:lsb]
A range can be ascending or descending.

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 16
Engg., IIT Roorkee
Logic system
Verilog uses four valued logic system. 1-bit signal can take on one of only four
possible values.

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 17
Engg., IIT Roorkee
Verilog actually has two classes of signals
1. nets
2. Variables

A net corresponds to roughly a wire in a physical circuit. This provides


connectivity
between the modules and other elements in a structural module.
Input/output port lists are often nets.

The default net type is wire : any signal name that appears in input/output
port list but not in a net declaration which is assumed to be a wire.
It provides basic connectivity.

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 18
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 19
Engg., IIT Roorkee
Verilog variables store values during program execution, they need
to have physical significance in a circuit.
Variables are
1. reg
2. Integer
reg may be a single bit or vector of bits.
Variable values can be changed within the procedural code within a
module, it can not be changed from outside the module.
Therefore input inout ports cannot have variable type, they must
have a net type as wire.
Output ports can have either a net or a reg type. It can drive input
and inout ports of the other modules.

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 20
Engg., IIT Roorkee
Bit select: byte1[7] , Zbus[16]
Part select : Zbus[2:5]

Literals:
n’ B ddd…d

n is a decimal number size of the literal in bits. No of bits


B is a single letter specifying the base may be b(binary),
o(octal),h(hexadecimal), d (decimal and the default)
ddd…d is the string of one or more digits in the specified base.

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 21
Engg., IIT Roorkee
Concatenation: { }

{2’ b00, 2’ b01} = 4’ b0001

{byte1, byte1, byte2, byte3} = 32 bit vector

Replication operator : n { }

{2{byte1}, 2{byte2}}

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 22
Engg., IIT Roorkee
Padding: vectors are aligned with rightmost bit, left
bits are appended with zeros.
The value of 2’ b11 & 4’ b 0101 is 4’ b0001

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 23
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 24
Engg., IIT Roorkee
Shift operators:
8’ b11010011<<3 is 8’ b10011000

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 25
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 26
Engg., IIT Roorkee
1’ b1 is true
1’ b0 is false
4’ b0100 is true
4’ b1111 is also true
But 4’ b0000 is false

4’ b0100 && 4’ b1011 is true && true


But bitwise will be 4’ b0000 –false

Logical operations are preferred in


conditional operations.

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 27
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 28
Engg., IIT Roorkee
Structural Design elements

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 29
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 30
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 31
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 32
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 33
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 34
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 35
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 36
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 37
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 38
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 39
Engg., IIT Roorkee
4-1 Multiplexer - Structural Verilog Description
module multiplexer_4_to_1_st_v(S, I, Y);
input [1:0] S; // S is a vector with components S[1] and S[0]
input [3:0] I; // I is a 4-bit input; vectors: I[0]…I[3]
output Y;

wire [1:0] not_S; // connecting NOT-AND


wire [0:3] D, N; // D connecting AND-AND
not // N  AND outputs
gn0(not_S[0], S[0]), // gn0(output, input)
gn1(not_S[1], S[1]);
and S[0] not_S[0]
g0(D[0], not_S[1], not_S[0]),
g1(D[1], not_S[1], S[0]), D0
g2(D[2], S[1], not_S[0]), g0 N[0]
g4
g3(D[3], S[1], S[0]),
g4(N[0], D[0], I[0]),
g5(N[1], D[1], I[1]),
g6(N[2], D[2], I[2]),
g7(N[3], D[3], I[3]);
or go(Y, N[0], N[1], N[2], N[3]); EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 40
endmodule Engg., IIT Roorkee
2-to-4 Line Decoder Structural Verilog
// 2-to-4 Line Decoder: Structural Verilog Description.
module decoder_2_to_4_st_v(EN, A0, A1, D0, D1, D2, D3);
input EN, A0, A1;
output D0, D1, D2, D3;

wire A0_n, A1_n, N0, N1, N2, N3;


not
go(A0_n, A0), A1_n
g1(A1_n, A1); A0_n
and N0
g3
g3(N0, A0_n, A1_n),
N1
g4(N1, A0, A1_n),
g5(N2, A0_n, A1),
g6(N3, A0, A1),
g7(D0, N0, EN), g6 N3
g8(D1, N1, EN),
g9(D2, N2, EN),
g10(D3, N3, EN);
endmodule
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 41
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 42
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 43
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 44
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 45
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 46
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 47
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 48
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 49
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 50
Engg., IIT Roorkee
Dataflow Verilog Modeling

1. A dataflow description is based on function rather than


structure.
2. A dataflow uses a number of operators that act on operands
to produce the desired function  Boolean equations are used
in place of logic schematics.

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 51
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 52
Engg., IIT Roorkee
A continuous assignment is the most basic
statement in data flow modeling, used to drive a
value onto a net. A continuous assignment
replaces gates in the description of the circuit
and describes the circuit at a higher level of
abstraction.
A continuous assignment statement starts with
the keyword assign.

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 53
Engg., IIT Roorkee
// Verilog code for AND-OR-INVERT gate
module AOI (input A, B, C, D, output F);
assign F = ~((A & B) | (C & D));
endmodule
// end of Verilog code

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 54
Engg., IIT Roorkee
OR Gate using Data flow modeling

module or2 (a,b,c);


input a,b;
output c;
assign c= a|b;
endmodule

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 55
Engg., IIT Roorkee
4-1 Multiplexer - Dataflow Verilog
// 4-to-1 Line Multiplexer: Dataflow Verilog Description (Boolean)
module multiplexer_4_to_1_df_v(S, I, Y);
input [1:0] S;
input [3:0] I;
output Y;

assign Y = (~ S[1] & ~ S[0] & I[0])| (~ S[1] & S[0] & I[1])
| (S[1] & ~ S[0] & I[2]) | (S[1] & S[0] & I[3]);
endmodule

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 56
Engg., IIT Roorkee
2-to-4 Line Decoder Dataflow Verilog
// 2-to-4 Line Decoder with Enable: Dataflow Verilog Desc.
module decoder_2_to_4_df_v(EN, A0, A1, D0, D1, D2, D3);
input EN, A0, A1;
output D0, D1, D2, D3;

assign D0 =(EN & ~A1 & ~A0);


assign D1 =(EN & ~A1 & A0);
assign D2 =(EN & A1 & ~A0);
assign D3 =(EN & A1 & A0);

endmodule

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 57
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 58
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 59
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 60
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 61
Engg., IIT Roorkee
Sensitivity list

Procedural statements in an always block executes sequentially.


However, always block itself executes concurrently with other
concurrent statements in the same module (instance,
continuous statement, and always)

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 62
Engg., IIT Roorkee
Blocking statement – immediate assignment

Non-blocking statement – late assignment

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 63
Engg., IIT Roorkee
A non-blocking statement evaluates its right-hand side
immediately, but does not assign this value to the left-hand side
until an infinitesimal delay after the entire always block has
completed execution

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 64
Engg., IIT Roorkee
Learn the rules

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 65
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 66
Engg., IIT Roorkee
Points to be noted

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 67
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 68
Engg., IIT Roorkee
EEN-611 FPGA Implementation of Signal
Monday, August 12, 2019 Processing Systems, Department of Electrical 69
Engg., IIT Roorkee
Points to be noted

EEN-611 FPGA Implementation of Signal


Monday, August 12, 2019 Processing Systems, Department of Electrical 70
Engg., IIT Roorkee

Anda mungkin juga menyukai