DigitalLogic ComputerOrganization L9 10 FPGA Verilog Handout
DigitalLogic ComputerOrganization L9 10 FPGA Verilog Handout
COMPUTER ORGANIZATION
Lecture 9-10: FPGA and Verilog
ELEC3010
ACKNOWLEGEMENT
2
COVERED IN THIS COURSE
❑ Binary numbers and logic gates
❑ Boolean algebra and combinational logic
❑ Sequential logic and state machines
❑ Binary arithmetic
Digital logic
❑ Memories
4
FIELD PROGRAMMABLE GATE ARRAY
I/O I/O I/O I/O
SM SM SM SM
I/O
SM SM SM SM
I/O
SM SM SM SM
I/O
5
FIELD PROGRAMMABLE GATE ARRAY
Configurable 16x1 G
LUT: GQ
Logic Block CLB Bool-function
FF
contains slices of 4
G
variables
6
FIELD PROGRAMMABLE GATE ARRAY
Zynq UltraScale+ EV
Zynq® UltraScale+
1 CLB contains 1 slice
1 slice has 8 LUT6 and 16 FFs
7
FIELD PROGRAMMABLE GATE ARRAY
Zynq UltraScale+ EV
Zynq® UltraScale+
1 CLB contains 1 slice
1 slice has 8 LUT6 and 16 FFs
8
FIELD PROGRAMMABLE GATE ARRAY
Zynq UltraScale+ EV
9
HARDWARE DESCRIPTION LANGUAGES
❑ Hardware Description Language (HDL): a language for
describing hardware
– Efficiently code large, complex designs
• Programming at a more abstract level than schematics
– CAD tools can automatically synthesize circuits
❑ Industry standards:
– Verilog: We will use it from Lab 3
– SystemVerilog: Successor to Verilog, gaining wide adoption
– VHDL (Very High Speed Integrated Circuit HDL)
10
VERILOG
❑ Developed in the early 1980s by Gateway Design
Automation (later bought by Cadence)
❑ Supports modeling, simulation, and synthesis
– We will use a (synthesizable) subset of the language features
❑ Major language features (in contrast to software
programming languages)
– Concurrency
– Bit-level behavior
❑Versions: 1995 and revised version 2001
11
VERILOG SYNTAX
❑Verilog and SystemVerilog are case-sensitive languages,
Keywords are always in all lowercase letters.
❑Comments:
▪ A single line comment starts with //
▪ A multiple-line comment starts with /* and ends with */ and
cannot be nested
12
VERILOG SYNTAX
❑Strings: a sequence of characters enclosed in `` ``
▪ ``Hello world!``
❑Identifiers: names of variables which can be referenced
▪ Include [a-z], [A-Z], [0-9], underscore _, $
▪ Can not start with a digit or $
▪ E.g.,:
1ab: invalid
_abc5: OK
$abba: invalid
13
VALUES
❑ Verilog signals can take 4 values
▪ 0 Logical 0, or false
▪ 1 Logical 1, or true
▪ x Unknown logical value
▪ z High impedance (Hi-Z), floating/non-connected
14
BIT VECTORS
❑ Multi-bit values are represented by bit vectors
(i.e., grouping of 1-bit signals)
– Right-most bit is always least significant
– Example
• input[7:0] byte1, byte2, byte3; /* three 8-bit inputs */
• Binary Constants
❑ Constants – 8’b00000000
4’b1001 – 8’b0xx01xx1
• Decimal Constants
Base format (b,d,h,o)
– 4’d10 ; -4’d10
Decimal number representing bit width – 32’d65536
15
OPERATORS
❑ Bitwise Boolean operators
~ NOT
& AND
^ Exclusive OR
| OR
❑ Arithmetic operators
+ Addition – Subtraction
* Multiplication / Division % Modulus
<< Shift left >> Shift right
16
VERILOG PROGRAM STRUCTURE
❑ System is a collection of modules
– Module corresponds to a single piece
of hardware
❑ Declarations
– Describe names and types of inputs
and outputs
– Describe local signals, variables,
constants, etc.
❑ Statements specify what the
module does
17
VERILOG PROGRAM STRUCTURE
18
VERILOG HIERARCHY
19
VERILOG PROGRAMMING STYLES
❑ Structural
– Shows how a module is built from other modules via instance
statements
– Textual equivalent of drawing a schematic
❑ Behavioral
– Specify what a module does in high-level description
– Use procedural code (e.g., in always block) and continuous
assignment (i.e., assign) constructs to indicate what actions to take
❑ We can mix the structural and behavioral styles
in Verilog design
20
STRUCTURAL STYLE
module M_2_1 (input x, y, sel,
output out);
❑ The order of the module instantiation does not matter Essentially describing
the schematic textually
21
CAN YOU DO IT?
xor u1(a1,X1,X2);
and u2(a2,X1,X2);
and u3(a3,a1,Cin);
or u4(Cout,a2,a3);
xor u5(S,a1,Cin);
endmodule
22
BEHAVIORAL STYLE WITH CONTINUOUS ASSIGNMENTS
23
BEHAVIORAL STYLE COMBINATIONAL LOGIC WITH
ALWAYS BLOCK
24
SEQUENTIAL LOGIC IN ALWAYS BLOCKS
25
BLOCKING ASSIGNMENTS
26
NONBLOCKING ASSIGNMENTS
27
ASSIGNMENTS IN VERILOG
❑ Continuous assignments apply to combinational logic only
28
NET AND VARIABLE TYPES
❑ We will mainly use two data type classes
– wire: represents a physical connection (or net) between hardware
elements
• A stateless way of connected two elements
• Can only be used to model combinational logic
• Cannot be used in the left-hand side in an always block
– reg: similar to wires, but can be used to store information (or
state) like registers
• This is used in the behavioral style only
• Can be used to model both combinational & sequential logic
• Cannot be used in the left-hand side of a continuous assignment
statement
29
(IMPROPERLY CREATED) INFERRED LATCHES
❑ To infer combinational logic, you’re recommended to ensure that
each variable within an always block gets assigned a value (under all
possible conditions)
– Otherwise, the Verilog compiler assumes that the last value should be
used, and will create a latch
30
PROCEDURAL STATEMENTS
case (case_expression)
if(condition_1)
procedural_statement_1; case_item1: procedural_expression;
case_item2: begin procedural_statements;
else if(condition_2) end
procedural_statement_2; ....
default: expression;
else
procedural_statement_3; endcase
Note: a block of multiple statements must be grouped and be within begin and end
31
PROCEDURAL STATEMENTS
[source]
32
PROCEDURAL STATEMENTS
[source]
33
PROCEDURAL STATEMENTS
[source]
34
PROCEDURAL STATEMENTS
[source]
35
MODELLING FSM IN VERILOG
[source]
36
BEFORE NEXT CLASS
• Textbook: 3.5
• Next time: Timing Analysis
37