Intro HDL
Intro HDL
Intro HDL
Logic Simulation
A simulator interprets the HDL description and produces a
readable output, such as a timing diagram, that predicts
how the hardware will behave before its is actually
fabricated.
Simulation allows the detection of functional errors in a
design without having to physically create the circuit.
Logic Simulation
Logic simulation is a fast,
accurate method of
analyzing a circuit to see its
waveforms
Types of HDL
There are two standard HDLs that are supported by IEEE.
VHDL (Very-High-Speed Integrated Circuits Hardware
Description Language) - Sometimes referred to as
VHSIC HDL, this was developed from an initiative by
US. Dept. of Defense.
Verilog HDL developed by Cadence Data systems and
later transferred to a consortium called Open Verilog
International (OVI).
Verilog
Verilog HDL has a syntax that describes precisely the legal
constructs that can be used in the language.
It uses about 100 keywords pre-defined, lowercase,
identifiers that define the language constructs.
Example of keywords: module, endmodule, input, output
wire, and, or, not , etc.,
Any text between two slashes (//) and the end of line is
interpreted as a comment.
Blank spaces are ignored and names are case sensitive.
Verilog - Module
A module is the building block in Verilog.
It is declared by the keyword module and is always
terminated by the keyword endmodule.
Each statement is terminated with a semicolon, but there is
no semi-colon after endmodule.
Bitwise NOT :
Bitwise AND:
Bitwise OR:
Bitwise XOR:
Bitwise XNOR:
~
&
|
^
~^ or ^~
endmodule
This describes the circuit by specifying the gates and how they
are connected with each other.
Gate-Level Modeling
Here a circuit is specified by its logic gates and their
interconnections.
It provides a textual description of a schematic diagram.
Verilog recognizes 12 basic gates as predefined primitives.
When the gates are simulated, the system assigns a fourvalued logic set to each gate 0,1,unknown (x) and high
impedance (z)
Gate-level Modeling
Two or more modules can be combined to build a
hierarchical description of a design.
There are two basic types of design methodologies.
Top down: In top-down design, the top level block is defined and
then sub-blocks necessary to build the top level block are identified.
Bottom up: Here the building blocks are first identified and then
combine to build the top level block.
Gate-level Modeling
A bottom-up hierarchical description of a 4-bit
adder is described in Verilog as
2 to 4 Decoder
2 to 4 Decoder
//Gate-level description of a 2-to-4-line decoder
module decoder_gl (A,B,E,D);
input
A,B,E;
output[0:3]D;
wire
Anot,Bnot,Enot;
not
n1 (Anot,A),
n2 (Bnot,B),
n3 (Enot,E);
nand
n4 (D[0],Anot,Bnot,Enot),
n5 (D[1],Anot,B,Enot),
n6 (D[2],A,Bnot,Enot),
n7 (D[3],A,B,Enot);
endmodule
A0_n, A1_n, E;
g0(A0_n, A0), g1(A1_n, A1), g2(E,E_n);
g3(D0_n,A0_n,A1_n,E), g4(D1_n,A0,A1_n,E),
g5(D2_n,A0_n,A1,E), g6(D3_n,A0,A1,E);
Three-State Gates
Three-State Gates
Three-state gates have a control input that can place the
gate into a high-impedance state. (symbolized by z in
HDL).
The bufif1 gate behaves like a normal buffer if
control=1. The output goes to a high-impedance state z
when control=0.
bufif0 gate behaves in a similar way except that the
high-impedance state occurs when control=1
Two not gates operate in a similar manner except that the
o/p is the complement of the input when the gate is not in a
high impedance state.
The gates are instantiated with the statement
Three-State Gates
module muxtri(A,B,sel,out);
input
A,B,sel;
output
OUT;
tri
OUT;
bufif1
(OUT,A,sel);
bufif0
(OUT,B,sel);
endmodule
Three-State Gates
Keywords wire and tri are examples of net data type.
Nets represent connections between hardware elements.
Their value is continuously driven by the output of the device
that they represent.
The word net is not a keyword, but represents a class of
data types such as wire, wor, wand, tri, supply1 and
supply0.
The wire declaration is used most frequently.
The net wor models the hardware implementation of the
wired-OR configuration.
The wand models the wired-AND configuration.
The nets supply1 and supply0 represent power supply and
ground.
Dataflow Modeling
Dataflow modeling uses a number of operators that act on
operands to produce desired results.
Verilog HDL provides about 30 operator types.
Dataflow modeling uses continuous assignments and the
keyword assign.
A continuous assignment is a statement that assigns a value
to a net.
The value assigned to the net is specified by an expression
that uses operands and operators.
Behavioral Modeling
Behavioral modeling represents digital circuits at a
functional and algorithmic level.
It is used mostly to describe sequential circuits, but can also
be used to describe combinational circuits.
Behavioral descriptions use the keyword always followed
by a list of procedural assignment statements.
The target output of procedural assignment statements must
be of the reg data type.
A reg data type retains its value until a new value is
assigned.
4-to-1
line
multiplex
er
end
end
endmodule
A test module typically has no inputs or outputs.
The signals that are applied as inputs to the design module for
simulation are declared in the stimulus module as local reg data type.
The outputs of the design module that are displayed for testing are
declared in the stimulus model as local wire data type.
The module under test is then instantiated using the local identifiers.
mux
mux
// instantiate mux
B=%b OUT=%b",TS,TA,TB,Y);
Descriptions of Circuits
Structural Description This is directly equivalent to the
schematic of a circuit and is specifically oriented to
describing hardware structures using the components of a
circuit.
Dataflow Description This describes a circuit in terms of
function rather than structure and is made up of concurrent
assignment statements or their equivalent. Concurrent
assignments statements are executed concurrently, i.e. in
parallel whenever one of the values on the right hand side of
the statement changes.
4-to-1 Multiplexer
4-to-1 Multiplexer
//4-to-1 Mux: Structural Verilog
module mux_4_to_1_st_v(S,D,Y);
input [1:0]S;
input [3:0]D;
output Y;
wire [1:0]not_s;
wire [0:3]N;
not g0(not_s[0],S[0]),g1(not_s[1],S[1]);
and g2(N[0],not_s[0],not_s[1],D[0]),
g3(N[1],S[0],not_s[1],D[0]),
g4(N[2],not_s[0],S[1],D[0]),
g5(N[3],S[0],S[1],D[0]);
or g5(Y,N[0],N[1],N[2],N[3]);
endmodule
4-to-1 Multiplexer
Adder
4-bit Adder
4-bitAdder
4-bit Adder
//4-bit adder : dataflow description
module adder_4bit (A,B,C0,S,C4);
input [3:0] A,B;
input C0;
output [3:0]S;
output C4;
assign {C4,S} = A + B + C0;
endmodule
Obtain either the state diagram or the state table from the
statement of the problem.
If only a state diagram is available from step 1, obtain
state table.
Assign binary codes to the states.
Derive the flip-flop input equations from the next-state
entries in the encoded state table.
Derive output equations from the output entries in the
state table.
Simplify the flip-flop input and output equations.
Draw the logic diagram with D flip-flops and
combinational gates, as specified by the flip-flop I/O
equations.
B=A
C=B+1
B <= A
C <= B + 1
module D_latch(Q,D,control);
output Q;
input D,control;
reg Q;
always @(control or D)
if(control) Q = D; //Same as: if(control=1)
endmodule
input D,CLK;
reg Q;
always @(posedge
CLK)
Q = D;
endmodule
input D,CLK,RST;
reg Q;
if (~RST) Q = 1'b0;
(RST = 0)
else Q = D;
endmodule
// Same as: if
input T,CLK,RST;
wire DT;
assign DT = Q ^ T ;
endmodule
input J,K,CLK,RST;
wire JK;
endmodule
Q(t 1) Q T
Q(t 1) JQ' K ' Q
J-K Flip-Flop
// Functional description of JK
// flip-flop
module JK_FF (J,K,CLK,Q,Qnot);
output Q,Qnot;
input J,K,CLK;
reg Q;
assign Qnot = ~ Q ;
always @(posedge CLK)
case({J,K})
2'b00: Q = Q;
2'b01: Q = 1'b0;
2'b10: Q = 1'b1;
2'b11: Q = ~ Q;
endcase
endmodule
D-Flip-Flop
//Positive Edge triggered DFF with Reset
module DFF(CLK,RST,D,Q);
input CLK,RST,D;
output Q;
reg Q;
always@(posedge CLK or posedge RST)
if (RST) Q<=0;
else
Q<=D;
endmodule
Sequential Circuit
Sequence Recognizer
Identify the
sequence 1101,
regardless of
where it occurs
in a longer
sequence.
Sequence Recognizer
module seq_recognizer(CLK,RST,X,Z);
input CLK,RST,X;
output Z;
reg [1:0]state, next_state;
parameter A=2b00,B=2b01,C=2b10,D=2b11;
reg Z;
always@(posedge CLK or posedge RST) begin
if(RST==1) state <= A;
else state <= next_state;
end
B;
C;
C;
B;
else
else
else
else
next_state
next_state
next_state
next_state
<=
<=
<=
<=
A;
A;
D;
A;
CLK
Load
Count
Function
Clear to 0
+ve
Load inputs
+ve
Count next
binary state
+ve
No change
Mode Control
S1
S0
Register Operation
No Change
Shift Right
Shift Left
Parallel Load
4-bit
binary
counter
with
parallel
load
Function
table for
4-bit
Universal
Shift
Register
//Parallel input
//Mode select
input lfin,rtin,CLK,Clr;
//Serial input,clock,clear
output [3:0] A;
//Parallel output
//D flip-flop
always@(posedge CLK or negedge Clr)
if (~Clr) Q = 1'b0;
else Q = D;
endmodule
//Data input
output CO;
//Output carry
output [3:0] A;
//Data output
reg [3:0] A;
assign CO = Count & ~Load & (A == 4'b1111);
always @(posedge CLK or negedge Clr)
if (~Clr) A = 4'b0000;
else if (Load)
A = IN;
endmodule
Sign extending a number: replicate the most significant bit the number of
times needed
Logical operations
P
C
instruction
memory
integer
register
file
flt pt
register
file
integer
ALU
integer
multiplier
flt pt
adder
flt pt
multiplier
data
memory
25
20
op
Rs
Rt
op
Rs
Rt
15
Rd
funct
Immed 16
Type
op
funct
Type
op
funct
ADDI
10
xx
ADD
00
ADDIU 11
xx
SLTI
12
SLTIU
Type
op
funct
40
00
50
ADDU 00
41
00
51
xx
SUB
00
42
SLT
00
52
13
xx
SUBU 00
43
SLTU 00
53
ANDI
14
xx
AND
00
44
ORI
15
xx
OR
00
45
XORI
16
xx
XOR
00
46
LUI
17
xx
NOR
00
47
Outputs
(CarryIn)
a
b
(CarryOut) Sum
1-bit AND, 1-bit OR, 1-bit full add of a and b always calculated
Operation input (2 bits) determines which of these passes through the MUX and
appears at Result
CarryIn is from previous bit-slice
CarryOut goes to next bit-slice
(LSB)
(MSB)
Handling subtraction
Perform a+(-b)
Recall that to negate b we
Perform a+(-b)
NOR all Result bits to detect Result=0
Less
Less
3
Set
Only used for MSB
Overflow
Overflow occurs when the result from an operation cannot be
represented with the number of available bits (32 in our ALU)
For signed addition, overflow occurs when
Example: 01110000+00010000=1000000
Example: 10000000+10000000=0000000
Overflow
Overflow on unsigned arithmetic, which is primarily used for
manipulating addresses, is ignored in many ISAs (including
MIPS)
Overflow on signed arithmetic causes an interrupt to deal with
the problem (Chapter 5)
Overflow detection: XOR CarryIn of MSB with CarryOut of
MSB (problem 4.42)
Carry lookahead
Carry skip
Carry select
gi ai bi
pi ai bi
gi ai bi
pi ai bi
P0 p3 p 2 p1 p 0
C1 G 0 P 0 c 0
MUXes
propagated carry
(worst)
Questions?