HDL
HDL
HDL is a language that describes the hardware of digital systems in a textual form. It resembles a programming language, but is specifically oriented to describing hardware structures and behaviors. The main difference with the traditional programming languages is HDLs representation of extensive parallel operations whereas traditional ones represents mostly serial operations. The most common use of a HDL is to provide an alternative to schematics.
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.
Design is first described in HDL Verified by simulating the design and checking it with a test bench which is also written in HDL.
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.
The first number specifies the unit of measurement for time delays. The second number specifies the precision for which the delays are rounded off, in this case to 0.1ns.
In the above example, cwd is declared as one instance circuit_with_delay. (similar in concept to object<->class relationship)
Bitwise NOT : Bitwise AND: Bitwise OR: Bitwise XOR: Bitwise XNOR:
~ & | ^ ~^ or ^~
endmodule
Gate-level modeling using instantiation of primitive gates and user defined modules.
This describes the circuit by specifying the gates and how they are connected with each other.
Dataflow modeling using continuous assignment statements with the keyword assign.
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.
4 primitive gates of 3-state type. Other 8 are: and, nand, or, nor, xor, xnor, not, buf
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.
In a top-down design, a 4-bit binary adder is defined as top-level block with 4 full adder blocks. Then we describe two half-adders that are required to create the full adder. In a bottom-up design, the half-adder is defined, then the full adder is constructed and the 4-bit adder is built from the full adders.
Gate-level Modeling
A bottom-up hierarchical description of a 4-bit adder is described in Verilog as
Half adder: defined by instantiating primitive gates. Then define the full adder by instantiating two halfadders. Finally the third module describes 4-bit adder by instantiating 4 full adders.
Note: In Verilog, one module definition cannot be placed within another module description.
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
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
The output of 3-state gates can be connected together to form a common output line. To identify such connections, HDL uses the keyword tri (for tri-state) to indicate that the output has multiple drivers.
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.
//Dataflow description of a 4-bit comparator. module magcomp (A,B,ALTB,AGTB,AEQB); input [3:0] A,B; output ALTB,AGTB,AEQB; assign ALTB = (A < B), AGTB = (A > B), AEQB = (A == B); endmodule
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.
end
The block is enclosed between begin and end. At time=0, A and B are set to 0. 10 time units later, A is changed to 1. 20 time units later (at t=30) a is changed to 0 and B to 1.
end
The 3-bit vector D is initialized to 000 at time=0. The keyword repeat specifies looping statement: one is added to D seven times, once every 10 time units.
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.
The stimulus model generates inputs for the design module by declaring identifiers TA and TB as reg data type, and checks the output of the design unit with the wire identifier TC. The local identifiers are then used to instantiate the design module under test.
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
//4-to-1 Mux: Dataflow Verilog Description module mux_4_to_1(S,D,Y); input [1:0]S; input [3:0]D; output Y; assign Y=S[1]?(S[0]?D[3]:D[2]):(S[0]?D[1]:D[0]); endmodule
Adder
4-bit Adder
4-bit-Adder
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
The event control expression specifies the condition that must occur to activate the execution of the procedural assignment statements. The variables in the left-hand side of the procedural statements must be of the reg data type and must be declared as such.
Edge-triggered (In synchronous sequential circuits, changes in flip-flops must occur only in response to a transition of a clock pulse.
always @(posedge clock or negedge reset)will cause the execution of the procedural statements only if the clock goes through a positive transition or if the reset goes through a negative transition.
Blocking assignments (executed sequentially in the order they are listed in a sequential block)
B=A C=B+1
Non-blocking assignments (evaluate the expressions on the right hand side, but do not make the assignment to the left hand side until all expressions are evaluated.
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
J-K Flip-Flop
Here the flip-flop is described
// 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
The case multiway branch condition checks the 2-bit number obtained by concatenating the bits of J and K. The case value ({J,K}) is evaluated and compared with the values in the list of statements that follow.
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
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
always@(X or state) begin case(state) A:if(X)next_state <= B:if(X)next_state <= C:if(X)next_state <= D:if(X)next_state <= endcase end always@(X or state) begin case(state) A:Z<=0; B:Z<=0; C:Z<=0; D:Z<=X?1:0; endcase end endmodule
B; C; C; B;
A; A; D; A;
Registers and counters can be described in HDL at either the behavioral or the structural level. In the behavioral, the register is specified by a description of the various operations that it performs similar to a function table. A structural level description shows the circuit in terms of a collection of components such as gates, flip-flops and multiplexers. The various components are instantiated to form a hierarchical description of the design similar to a representation of a logic diagram.
Mode Control S1 0 0 1 1 S0 0 1 0 1 Register Operation No Change Shift Right Shift Left Parallel Load
//Instantiate the four stages stage ST0 (A[0],A[1],lfin,I[0],A[0],select,CLK,Clr); stage ST1 (A[1],A[2],A[0],I[1],A[1],select,CLK,Clr); stage ST2 (A[2],A[3],A[1],I[2],A[2],select,CLK,Clr); stage ST3 (A[3],rtin,A[2],I[3],A[3],select,CLK,Clr); endmodule
endmodule
Example: 1000 10102 = -27+23+21=-11810 Leftmost bit called the sign bit
Sign extending a number: replicate the most significant bit the number of times needed
Logical operations
Result is a split of the execution core into integer and floating point sections
integer ALU integer register file
data memory
P C
instruction memory
flt pt multiplier
=> 2s complement adder/sub with overflow detection => Logical AND, logical OR, XOR, nor => 2s complement adder with inverter, check sign bit of result
ALU from from CS 150 / P&H book chapter 4 supports these ops
25 Rs Rs
funct xx xx xx xx xx xx xx xx
20 Rt Rt
Type ADD
15 Rd
5 funct Immed 16
op op
op 10
op 00
funct 40 41 42 43 44 45 46 47
Type
op 00 00
funct 50 51 52 53
ADDU 00 SUB 00
SLT
00
SLTU 00
a,b: the data (operands) to be operated on ALU operation: the operation to be performed Result: the result of the operation Zero: indicates if the Result = 0 (for beq, bne) CarryOut: the carry out of an addition operation Overflow: indicates if an add or sub had an overflow (later)
Outputs
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
Less
a-b=negative number implies that a<b Feed the adder output of bit 31 to the Less input of bit 0
Less
Both are 1 for subtract and 0 otherwise, so a single signal can be used
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
Subtracting a negative from a positive number gives a negative result Subtracting a positive from a negative number gives a positive result
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)
gi ! ai y bi
pi ! ai bi
gi ! ai y bi
pi ! ai bi
n+1 input OR and AND gates for nth input Irregular structure with many long wires
First level generates Result (using carry lookahead to generate the internal carries) and propagate and generate signals for a group of 4 bits (Pi and Gi) Second level generates carry outs for each group based on carry in and Pi and Gi from previous group
C1 ! G 0 P 0 y c 0
Generate cin in parallel and use a MUX to select the correct sum outputs Example for 8 bits
MUXes
propagated carry
Hint1: its to minimize the adder delay Hint2: assume a k-input block has k time units of delay, and the ANDOR logic has 1 time unit of delay
Ripple carry is the most regular structure (most amenable to VLSI implementation, but any can be used in practice) Carry skip requires clearing cins at start of operation (such as dynamic CMOS logic) Carry select requires driving many MUXes
Questions?