Lec4 Verilog
Lec4 Verilog
Lec4 Verilog
Course Announcements
Homework
(10
Homework
Due
2 assigned today
Feb 6, 5pm
Course
web site
http://www.uscden.net
Email
06/15/16
EE 577B
Course Announcements
Homework
Due
5pm, Feb 6
Get
Refer
TA: Aditya
Deshpande, [email protected]
Mentor: Harpreet Bhatia, [email protected]
Last day to add/drop without penalty is Friday,
February 1
06/15/16
EE 577B
Project will probably require teaming into 2person teams (start considering teammate choices!)
06/15/16
EE 577B
Assignment Date
Due Date
Jan 16
Jan 28
HW2 (Verilog)
Jan 28
Feb 6
Feb 6
Feb 20
HW4 (Synthesis)
Feb 20
Feb 27
P1 (Verilog)
Feb 27
Mar 13
06/15/16
EE 577B
in Verilog
Synopsys: Design Compiler (synthesis), Primetime
(static timing analysis)
Cadence: NC-Sim (simulation), First Encounter
(place&route), Conformal (logical equivalence
checking)
Project
candidates:
06/15/16
EE 577B
Intro to Verilog
Needed for remaining homework assignments
and first phase(s) of project
More Verilog
concepts/sources
Semester Project Intro
06/15/16
EE 577B
HDL Specification
(Behavioral, Structural)
Synopsys Synthesis
(Structural)
EE 577B
Verilog References
References
A Verilog
HDL Primer
J.
Bhasker
Verilog HDL: A Guide to Digital Design and
Synthesis
Samir
Palnitkar
Many on-line references
Look
06/15/16
http://www-scf.usc.edu/~ee577/
EE 577B
What is Verilog?
Verilog
Public
IEEE
06/15/16
domain in 1990
standard in 1995
EE 577B
10
Verilog Features
Verilog
Behavioral
Algorithmic
RTL (register
transfer level)
Dataflow
Structural
Gate
Switch
Hybrid
06/15/16
mixture of levels
EE 577B
11
Verilog Identifiers
An
Examples
Count,
Identifiers
are case-sensitive
Many reserved keywords cannot be used
Example:
06/15/16
EE 577B
12
(similar to C++)
Use
Use
Side
Verilog
is free-format
Constructs
always
#50 clk = ~clk;
06/15/16
EE 577B
13
: logic-0 or false
: logic-1 or true
(or x) : unknown
(or z) : high-impedance
types of constants
Integer
Real
String
Probably will be using only integers for course project.
06/15/16
EE 577B
14
Integer Constants
Two
Simple
decimal
[size]base
06/15/16
value
EE 577B
15
If
06/15/16
EE 577B
16
// 5-bit octal
4d2 // 4-bit decimal
4b1x_01 // 4-bit binary ( _ has no effect but can be
// used for readability)
7hx // xxxxxxx in binary (x-extended)
4d-4 // Not legal: value cannot be negative
8 h 2A // spaces allowed between size and character
// and between base and value
3 b001 // not legal: no space allowed between and //
base b
(2+3)d10 // Not legal; size cannot be an expression
06/15/16
EE 577B
17
06/15/16
EE 577B
18
Data Types
Verilog
Nets
Specify
06/15/16
EE 577B
19
Defaults
to z if undriven
Examples
Many
06/15/16
20
always statement
initial statement
Default value of x
Five
Examples
06/15/16
21
Memories
In Verilog,
registers
Examples
06/15/16
EE 577B
22
Better way
06/15/16
EE 577B
23
$readmemh Example
File
lut.fill contains
0 F 5 A
After
execution of
Can
@0 0
@1 F
06/15/16
EE 577B
24
Parameters
Parameters
Typically
Parameters
Useful
06/15/16
EE 577B
25
Operators
Operator types
Arithmetic
(+, -, *, /, %)
Relational
Equality
(= =, !=, = = = , ! = =)
Logical
(&&, ||, !)
Bitwise
Reduction
Shift
(<<, >>)
Conditional
(?:)
Concatenation
06/15/16
and replication
EE 577B
26
06/15/16
+, -
!, ~
&, ~&
^, ~^
|, ~|
*, /, %
+, -
<<, >>
<, <=
>, >=
27
06/15/16
= =, !=
===
case equality
!= =
case inequality
&
bitwise and
^, ~^
bitwise or
&&
logical and
||
logical or
?:
conditional operator
EE 577B
28
Operator Summary
All
a + b c is evaluated as (a + b) c
A ? B : C ? D : E is evaluated A ? B : (C ? D : E)
Parentheses
precedence
Most operators have same meaning as in
similar languages (e.g., C or C++)
06/15/16
EE 577B
29
Result
Examples:
contain x or z
06/15/16
EE 577B
30
Equality Operators
Result
must be 0 or 1, not x
For logical
06/15/16
EE 577B
31
Bitwise Operators
Same
06/15/16
&
EE 577B
32
Reduction Operators
Operate
Examples:
A = 4b0110; B = 4b0100;
33
Example:
{ rep_number {expr}}
Example:
EE 577B
34
Assignment Types
Continuous
Used
Useful
Procedural
Used
assignment
Useful
06/15/16
assignment
EE 577B
35
Continuous Assignment
Form:
Example
is assignment executed?
Whenever
06/15/16
EE 577B
36
behavior
Changes
Example
EE 577B
37
Procedural Assignment
Form:
Must
Timing
06/15/16
EE 577B
38
initial Statement
Begins
initial procedural_statement
Example
EE 577B
39
always Statement
Begins
Example
reg Q;
wire D, clk;
always @(posedge clk)
Q = D;
06/15/16
EE 577B
40
initial
initial
begin
begin
a = #7 0; // occurs at time 7
b = #5 1; // occurs at time 12
end
06/15/16
EE 577B
41
Assignment Summary
Procedural
Continuous
Drives registers
Drives nets
06/15/16
EE 577B
42
just like C
Two
casez (sel)
2b1? : out = 0; // ? Can be used for z, matches if sel is 10, 11, 1z
2b01 : out = 1;
default : out = x;
endcase
06/15/16
EE 577B
43
statements
06/15/16
EE 577B
44
Block Statements
Two
types
06/15/16
EE 577B
45
Module
Basic
or structure of a design
Modules
06/15/16
EE 577B
46
Module Syntax
module module_name ( port_list )
port declarations: input, output, inout, reg
internal declarations: reg, wire, parameter, function, task,
Statements: initial, always, module instantiation, gate instantiation,
continuous assignment
endmodule
Example
module HA (A, B, S, C);
input A, B;
output S, C;
assign #3 S = A ^ B;
assign #2 C = A & B;
endmodule
06/15/16
EE 577B
47
Module Ports
A port
Ports
06/15/16
EE 577B
48
position
06/15/16
EE 577B
49
endmodule
module FA (P, Q, Cin, Sum, Cout);
input P, Q, Cin;
output Sum, Cout;
wire S1, C1, C2;
HA h1 (P, Q, S1, C1); // association by position
HA h2 (.A(Cin), .S(Sum), .B(S1), .C(C2)); // association by name
assign Cout = C1 | C2;
endmodule
06/15/16
EE 577B
50
06/15/16
EE 577B
51
06/15/16
EE 577B
52
endmodule
module Top;
Pa 4 3 2 1 0
Bdl
1 2
Py 2 1 0
Mpr 2 3 4 5 6
endmodule
06/15/16
EE 577B
53
machine guidelines
Develop
State memory
Next-state logic
Output logic
Take care of reset appropriately
Use
06/15/16
EE 577B
54
fsmin = 0
fsmin = 1
SEE1
fsmout = 1
SEE0
fsmout = 0
fsmin = 1
06/15/16
EE 577B
55
Quick
06/15/16
EE 577B
56
concepts
Floating-point
Project
arithmetic tutorial
description
Homework
2 due Feb 6
Homework 3 (more Verilog concepts) will be
assigned Feb 6
57
58