To Verilog: Digital Design
To Verilog: Digital Design
to
Verilog
Digital Design
About Verilog
Verilog is a HDL (Hardware Description Language) to design
the digital system
VHDL is other hardware description language
Virtually every chip (FPGA, ASIC, etc.) is designed in part
using one of these two languages
Verilog was introduced in 1985 by Gateway Design System
Corporation
Other differences:
In arithmetic expressions,
An integer is treated as a signed quantity.
A reg is treated as an unsigned quantity.
General rule of thumb
reg used to model actual hardware registers
such as counters, accumulator, etc.
integer used for situations like loop counting.
Examples:
8b01110011 // 8-bit binary number
12hA2D
// 12-bit hexadecimal number
1b0
// Logic 0
1b1
// Logic 1
Primitive Gates
Primitive logic gates (instantiations):
and
nor
xor
G (out1, in);
buf
G (out1, in);
Verilog Operators
Arithmetic operators
*, /, +, -, %
Logical operators
!
logical negation
&&
logical AND
| | logical OR
Relational operators
>, <, >=, <=, ==, !=
Bitwise operators
~, &, |, ^, ~^
Shift operators
>>, <<
Conditional
<condition> ? <expression1> : <expression2>
Data-flow Modeling
Identified by the keyword assign.
assign
a = b & c;
assign
f[2] = c[0];
c = a+b;
Behavioral Modeling
The procedural block defines
A region of code containing sequential statements.
Two types of procedural blocks in Verilog
The always block
A continuous loop that never terminates.
The initial block
Executed once at the beginning of simulation (used in
Test-benches).
Examples
Majority Detector
Parity Checker
2 Input Multiplier
Majority Detector
Design Digital System to detect a majority vote
4 inputs
Detect majority vote if more than two inputs are pressed
Inputs : S1, S2, S3, S4
Function : S4S3(S2+S1) + S2S1(S3+S4)
Test Bench
module stimulus;
reg s1,s2,s3,s4;
wire y;
majority_data m1(s1,s2,s3,s4,y);
initial
begin
s1 = 1'b0;
s2 = 1'b0;
s3 = 1'b0;
s4 = 1'b0;
#5 s1 = 1'b1;
#50 s2 = 1'b1;
#100 s3 = 1'b1;
#150 s4 = 1'b1;
#150 s4 = 1'b1;
end
endmodule