Sequential Circuits Hardware Description Language: Lecture
Sequential Circuits Hardware Description Language: Lecture
Sequential Circuits Hardware Description Language: Lecture
Lecture (8)
initial begin
clock = 1’b0;
repeat (30);
#10 clock = ~clock;
end
initial begin
clock = 1’b0;
#300 $finish;
end
always #10 clock = ~clock
Behavioral Modeling in SSD (3)
The always statement can be controlled by delays that
wait for a certain time or by certain conditions to
become true or by events to occur.
This type of statement is of the form:
always @ (event control expression)
Procedural assignment statements
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.
Behavioral Modeling in SSD (4)
The statements within the block, after the event control
expression, execute sequentially and the execution
suspends after the last statement has executed.
Then the always statement waits again for an event to
occur.
Two kind of events:
Level sensitive (E.g. in combinational circuits and in latches)
always @(A or B or Reset) will cause the execution of the
procedural statements in the always block if changes occur in A or
B or Reset.
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.
Behavioral Modeling in SSD (5)
A procedural assignment is an assignment within an
initial or always statement.
There are two kinds of procedural assignments: blocking
and non-blocking
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
Flip-Flops and Latches
The D-latch is transparent and responds to a change in
data input with a change in output as long as control
input is enabled.
It has two inputs, D and control, and one output Q.
Since Q is evaluated in a procedural statement it must
be declared as reg type.
Latches respond to input signals so the two inputs are
listed without edge qualifiers in the event control
expression following the @ symbol in the always
statement.
There is one blocking procedural assignment statement
and it specifies the transfer of input D to output Q if
control is true.
Flip-Flops and Latches
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
Flip-Flops and Latches
//D flip-flop //D flip-flop with asynchronous reset.
module D_FF (Q,D,CLK); module DFF (Q,D,CLK,RST);
output Q; output Q;
input D,CLK,RST;
input D,CLK;
reg Q;
reg Q;
always @(posedge CLK or negedge RST)
always @(posedge CLK)
if (~RST) Q = 1'b0; // Same as: if (RST = 0)
Q = D; else Q = D;
endmodule endmodule
D Flip-Flop with Reset
D Flip-Flop with
Asynchronous
Reset
T & J-K Flip-Flops
T & J-K Flip-Flops
//T flip-flop from D flip-flop and gates //JK flip-flop from D flip-flop and gates
module TFF (Q,T,CLK,RST); module JKFF (Q,J,K,CLK,RST);
output Q; output Q;
input T,CLK,RST; input J,K,CLK,RST;
wire DT; wire JK;
assign DT = Q ^ T ; assign JK = (J & ~Q) | (~K & Q);
//Instantiate the D flip-flop //Instantiate D flipflop
DFF TF1 (Q,DT,CLK,RST); DFF JK1 (Q,JK,CLK,RST);
endmodule endmodule
4 bit Binary
Counter with
Parallel Load
HDL for Registers and Counters (8)