Professional Documents
Culture Documents
Verilog Lecture
Verilog Lecture
Verilog Lecture
Verilog basics
Lab evaluation criteria
¨ Pre-lab task
¤ 2 marks
¨ Lab task
¤ Simulation4 marks
¤ Lab report 1 mark
n Should be submitted in the next week lab.
¨ Viva (individual)
¤ 3 marks
¤ Actual attendance
Verilog - HDL
¨ Hardware Description Language
¨ C like in syntax but has distinct character and
interpretation
¤ must set perception right before coding in Verilog
¤ must visualize hardware in mind while structuring
Verilog
¨ Modules consisting of procedural blocks and
assignments
Modules – the building block
¨ Module is the basic building block in Verilog
¤ For example : module of full adder
¨ Modules are
¤ Declared
¤ Instantiated
¨
Hierarchical Design
¨ Verilog code contains a top‐level module and zero or more
instantiated modules
¨ The top‐level module is not instantiated anywhere
¨ Several copies of a lower‐level module may exist
¨ Each copy stores its own values of regs/wires
¨ Ports are used for interconnections to instantiated modules
¨ Order of ports on first line of module definition determine
order for connections of instantiated module
¨ Order of listing inputs, outputs, and inouts on the following
lines is not important
Module Example
Module Ports
¨ x: unknown
¨ octal
¤ 4’o15
¨ hexadecimal
¤ 4’hd
Data Types
¨ Nets
¤ physicalconnections between components
¤ always show the logic value of the driving components
¤ Many types of nets, we use wire in RTL
¨ Registers
¤ Implicitstorage – unless variable of this type is
modified it retains previously assigned value
¤ Does not necessarily imply a hardware register
¤ Register type is denoted by reg
Variable Declaration
¨ Declaring a net
¤ wire [range] net_name;
¤ Range is specified as [MSb:LSb]
n Default is one bit wide
¨ Declaring a register
¤ reg[range] reg_name;
¨ Declaring memory
¤ reg[range] memory_name [start_addr : end_addr];
¨ Examples
¤ reg r; // 1-bit reg variable
¤ wire w1, w2; // 2 1-bit wire variable
¤ reg[7:0]vreg; // 8-bit register
¤ reg[7:0] memory [0:1023]; //a 1 KB memory
Levels of Abstraction
¨ Gate level
¤ Continuousassignment
¤ Used to model combinational logic
assign net_name = expression;
example:
assign out = in1 & in2;
assign sum = a + b;
Verilog Operators
¨ Arithmetic: +, = , *, /, %
¨ Binary bitwise: ~, &, |, ^, ~^
¨ Unary reduction: &, ~&, |, ~|, ^, ~^
¨ Logical: !, ~, &&, ||, ==, ===, !=, !==
¨ == returns x if any of the input bits is x or z
¨ === compares xs and zs
¨ Relational: <. >, <=, >=
¨ Logical shift: >>, <<
¨ Conditional: ?:
¨ Concatenation: {}
¨ Replication: {{}}
Example: Concatenation operator
Behavioral Modeling
¨ High level language constructs are used
¤ for loop
¤ if else
¤ while
¨ Signals
¤ Posedge – rising-edge triggered
¤ Negedge – falling-edge triggered
¤ example: