Beruflich Dokumente
Kultur Dokumente
Anant Raj
anantraj@iitk.ac.in
Digital Design using Verilog
Basic Elements:
Gates: And, Or , Nor, Nand, Xor ..
Memory elements: Flip Flops, Registers ..
Techniques to design a circuit using basic
elements.
Lets see an end result of such a design:
Very messy!
Circuit with basic elements packaged into a
chip with some reconfigurability.
More sophisticated approach of designing
digital circuits.
eg: Designing a divide by 9 counter
Requires only a counter IC (4029) and may be 1/2
gates.
Limitation:
Only limited number of ICs with limited
functionalities.
A fully configurable IC
Contain programmable logic components called
logic blocks.
Contain hierarchy of reconfigurable interconnects
that allow the blocks to be wired together.
Logic Blocks can be configured to any complex
circuit.
FPGA can be made to work as a Xor gate, a Counter or
even bigger- an entire Processor!
Verilog, VHDL
Describe a digital circuit in software.
Adds a level of abstraction in digital design
Basic Idea:
Behavioral
Description of
required circuit
Complete
circuit
diagram
Verilog/VHDL
Synthesizer
Programming FPGAs
Used for prototyping hardware designs.
Used directly in many applications
Fabricating circuits on chip:
Entry point of design flow used for chip fabrication.
Used to design the circuit required.
Verify the circuit before fabrication
Designing large scale systems on chip:
eg: Processors-Multi-core
Data types?
-Yes, called Drivers in Verilog
Drivers: wire and register
Wire: Connects 2 points in a circuit wire clk
Register (reg) : Stores values reg A
Arrays?
wire [31:0] in
reg [16:0] bus
Modules are like Black boxes.
Example: Inverter
module Inverter(
input wire A,
output wire B
);
assign B = ~A;
endmodule
Module
Inputs Outputs
Note:
Input and Output
ports of the
module should be
specified.
Acyclic interconnections of gates.
And, Or, Not, Xor, Nand, Nor
Multiplexers, Decoders, Encoders .
How are gates, muxs etc. abstracted in Verilog?
And, Or, Not, Xor, Add, : by simple operators like in C
Multiplexers : by control statements like if-else, case,
etc.
Gate level implementation of above high level
operators done by Verilog synthesizer.
Arithmetic * Multiply
/ Division
+ Add
- Subtract
Logical ! Logical negation
&& Logical and
|| Logical or
Relational > Greater than
< Less than
== Equality
Shift >> Right shift
<< Left shift
Continuous assignment statement.
Used for modeling only combinational logic.
module Xor(
input wire A1,A2
output wire B );
assign B = (A1 & ~A2) | (~A1 & A2);
endmodule
Basically B is shorted to function on RHS..
LHS should have variable of wire type.
if-else, case :
Exactly like C.
Hardware view: implemented using multiplexers
for loops, repeat:
for-loops are synthesizable only if length of iteration
is determined at compile time & finite.
repeat -similar to for loop.
Hardware view: All loops are unrolled during
synthesis.
for (i=0; i<N; i=i +1)
begin
..
end
Note: N is finite/known at
compile time.
case(address)
0 : .
1 : .
2 : ..
default :
endcase
repeat (18)
begin
..
end
if ( . )
begin
end
else begin
..
end
Structure of always block:
always @( var1 or var2 or . varN)
begin
//All statements in body are
executed like a sequential code.
end
Block is executed when any if of the variable listed,
changes its value.
Use (*): Executed when any variable inside the
block changes.
Use the control statements only inside the always
block.
2-bit Multiplexer:
module MUX(
input wire in1, in2,sel,
output reg out);
always @( sel)
begin
if(sel)
out = in1;
else
out = in2;
end
module full_adder(
input wire a,
input wire b,
input wire cin,
output wire sum,
output wire carry
);
assign sum = a & ~b &
~cin | ~a & b & ~cin |~a &
~b & cin | a & b & cin;
assign carry = a & b |
a & cin | b & cin;
endmodule
module full_adder(
input wire a,
input wire b,
input wire cin,
output wire sum,
output wire carry
);
assign {carry,sum} =
a+b+cin;
endmodule
Gate Level Description Behavioral Description
If no size, 32 bits by default.
If <size> < value
MSB of value truncated
If <size> > value
MSB of value filled with zeros
e.g. - hexadecimal: 4hB
If no base given, number assumed
to be decimal. e.g. - 11
4b1011
Size in
bits
Base format
(d, b, h)
Value
Used to test the functionality of design by
simulation.
Instantiate our top most module and give
varying inputs & verify if the outputs match
expected results.
Added functionalities in Test Bench:
Delays
$display(), $monitor()
Not synthesized
Can be used to model delays in actual circuit
during simulation
Used mostly in Test Benches to provide inputs
at particular instants.
Syntax: #<time steps>
wire #10 out; assign out = a & b;
wire out; assign #10 out = in1 & in2;
#10 q = x + y;
q = #10 x + y; //only variable x is delayed
Most common:
always
#5 clk = ~clk;
$display()
used for printing text or variables to screen
syntax is the same as for printf in C
$display(input1 = %d, input2 = %d, output = %d,
in1, in2, out);
$monitor()
keeps track of changes to the variables in the list
Value printed when any of them change.
only written once in initial block.
$monitor(input1 = %d, input2 = %d, output = %d,
in1, in2, out);
$finish
Terminating simulation
Verilog, VHDL: Hardware Description languages
Used in FPGAs and designing circuits on chip.
Modules: Specify i/p, o/p signals with drivers
Wires:
Use assign statement. Continuous assignment.
Reg: Storage element
Use always@() block. Use control statements
Test Bench: Used to simulate circuit designed.
Always think of hardware when you write code!
Prof. Arvind, Complex Digital Systems,MIT:
http://csg.csail.mit.edu/6.375/6_375_2008
_www/handouts.html (Lectures- 2 & 3)
Verilog in one day- asic-world.com
http://asic-
world.com/verilog/verilog_one_day.html
VHDL Introduction
VHDL Introduction
V- VHSIC
H- Hardware
D- Description
L- Language
VHDL Statement Terminator
Each VHDL Statements is terminated using a
semicolon
;
VHDL Comment Operator
To include a comment in VHDL, use the
comment operator
-- This is a comment
-- This is an eample o! a comment
y "# $% -- can occur at any point
Signal &ssignment Operator
To assign a 'alue to a signal data o()ect in
VHDL, we use the
signal assignment operator
<=
Eample*
y "# +,-% -- signal y is
assigned the 'alue O.E
VHDL Eample - Hardware
in(
out(
buffer(
comparable to out
only 1 driver
inout(
bidirectional port
2 drivers
Data types
o
(it
o
8oolean
o
Character
o
Integer
o
Std9logic
o
:ost commonly used data type is std9logic2
o
Std9logic can ta1e !ollowing 'alues --- +;-,
+<-, -$-, +,-, +=-, + L-, +H-, +--
VHDL Eample - >*, mu
Li(rary ieee%
;se ieee2std9logic9,,?@2all%
;se ieee2std9logic9arith2all%
2ibrary declaration
Architecture concurrent of mux is
-- internal signal and constant declarations
Begin
y<= 3a and3not s44 or 3b and s4;
end architecture concurrent;
Entity mu is
port( a,(,s* in std9logic%
y* out std9logic);
End entity mu%
entity declaration
architecture declaration
Comple Concurrent Statements
with-select-when
with-select-when
Synta is
with select9signal select
signal9name "# 'alue, when 'alue,9o!9select9sig,
'alue> when 'alue>9o!9select9sig,
'alueA when 'alueA9o!9select9sig,
'alue9de!ault when others;
Comple Concurrent Statements
4ith-select-when * Eample
Verilog, VHDL
assign state(ent
always@() loc)