Synchronous: Sequential Logic
Synchronous: Sequential Logic
Sequential Logic
1
Toma Sacco, Ph.D.
2
Toma Sacco, Ph.D.
NS
Combinational
Circuit
Clock
n
Flip-Flops
PS
Outputs
Inputs
2n possible states
3
Toma Sacco, Ph.D.
Memory
0
Q
1
Q
0
Q
Latches
Q
1
Q'
1
2
Q'
Q
Q
5
Toma Sacco, Ph.D.
RS Latch
R
PS/NS table
Q'
S Set Store 1
R Reset Store 0
PS Present State Q
NS Next State what will next
be stored in the flip-flop
Q+
S R PS
(Q)
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
NS
(Q+)
0
1
0
0
1
1
In determinate
In determinate
6
Toma Sacco, Ph.D.
Characteristic Table
Q
Q
S R
Operation
0 0
0 1
hold
reset
1 0
1 1
set
Not allowed
Characteristic Equation:
Q+ = [(Q + S) + R] =(Q+S) . R = Q . R + S . R
7
Toma Sacco, Ph.D.
S'
1
2
R'
S R
Operation
Q'
0 0
0 1
Not allowed
set
1 0
1 1
reset
hold
8
Toma Sacco, Ph.D.
RS Latch application
switch debouncing
VCC
Switch is closed
At this moment
Switch
debounces
for several
milliseconds
S'
VCC
SPDT
1
2
1
2
Q'
R'
S
R
10
Toma Sacco, Ph.D.
Gated
G
0
1
Y
0
X
11
Toma Sacco, Ph.D.
Gated RS Latch
1
Q'
G
1
1
3
G
S
1
2
S'
1
2
Q'
G
1
1
4
R'
12
Toma Sacco, Ph.D.
Timing diagram
G
R
S
Q
13
Toma Sacco, Ph.D.
Gated D Latch
Transparent D Latch
Level-sensitive flip-flop
S
1
2
S'
1
2
Q'
G
1
1
G
Q
1
4
R'
Characteristic Table
G D operation
0x
hold
10
reset
11
set
14
Toma Sacco, Ph.D.
Timing diagram
G
D
Q
15
Toma Sacco, Ph.D.
16
Toma Sacco, Ph.D.
Combinational
Circuit
Inputs
Clock
PS
n
G Flip-Flops
Outputs
18
Toma Sacco, Ph.D.
Pulse-narrowing
1
clk
pulse
clk'
clk
Clk
pulse
= gate delay
19
Toma Sacco, Ph.D.
clk
pulse
clk'
clk
Q
20
Toma Sacco, Ph.D.
clk
slave
Qm
Qs
clk
Q
21
Toma Sacco, Ph.D.
master
D
clk
Qm
D
G
slave
Qs
clk
Q
22
Toma Sacco, Ph.D.
clk
D
Qm
Q
clk
Q
24
Toma Sacco, Ph.D.
If the clock is low, both the output signals of the input stage are high
regardless of the data input; the output latch is unaffected and it stores the
previous state. When the clock signal changes from low to high, only one of
the output voltages (depending on the data signal) goes low and sets/resets
the output latch: if D = 0, the lower output becomes low; if D = 1, the upper
output becomes low. If the clock signal continues staying high, the outputs
keep their states regardless of the data input and force the output latch to stay
in the corresponding state as the input logical zero remains active while the
clock is high. Hence the role of the output latch is to store the data only while
the clock is low.
25
Toma Sacco, Ph.D.
T
Toma Sacco, Ph.D.
Qa
clk
G
D
Q
D
D
Qa
Qb
clk
Qb
Q
Qc
D
clk
clk
Qc
Q
27
Toma Sacco, Ph.D.
clk
Q
PS
0
0
1
1
NS
0
1
0
1
D
0
1
0
1
28
Toma Sacco, Ph.D.
Verilog Description
module flipflop(D, Clk, Q);
input D, Clk;
output Q;
reg Q;
always @(posedge Clk)
Q<= D;
clk
Q
endmodule
29
Toma Sacco, Ph.D.
clk
Reset
clk
Reset
endmodule
31
Toma Sacco, Ph.D.
State
name
State
transition
Decision box
32
Toma Sacco, Ph.D.
D
1
0
State diagram
1
D
0
ASM chart
33
Toma Sacco, Ph.D.
1-bit register
data
Q
load 1-bit
clk
load
data
Load data
0x
clk
Q+
0x
11
1
0
10
11
10
34
Toma Sacco, Ph.D.
State/Excitation table
P.S.
inputs
N.S.
load
data
Lo
ad Q
da
ta
00
01
11
10
D load Q loaddata
data
load
I0
I1
s
clk
35
Toma Sacco, Ph.D.
n-bit register
Data[0]
load
n
data
Q
load n-bit
clk
I0
I1
s
D
clk
Data[n-1]
load
Q[0]
I0
I1
s
Q[n-1]
clk
36
Toma Sacco, Ph.D.
Register
A flip-flop stores one bit of information. When a set of n flipflops is used to store n bits of information, we refer to these
flip-flops as a register
L clk operation
QQ
QI
0
1
I2
I3
I1 I0
S
I1 I0
S
D Q
I0
I1
I1 I0
S
I1 I0
S
D Q
D Q
D Q
clk
37
Q3
Q2
Q1
Q0
Verilog Description
module reg4(I,L,clk,Q);
input L, clk;
input [3:0] I;
output [3:0] Q;
reg [3:0] Q;
always @ (posedge clk)
begin
if(L)
Q <= I;
else
Q <= Q;
end
endmodle
38
Toma Sacco, Ph.D.
Shift Register
clk operation
SHR(Q)
D Q
D Q
D Q
D Q
clk
Q3
Q2
Q1
I clk Q3 Q2 Q1 Q0
0
Initial state
39
Toma Sacco, Ph.D.
Q0
Verilog Description
module reg4(I,clk,Q);
input I, clk;
output [3:0] Q;
reg [3:0] Q;
always @ (posedge clk)
Q < = {I,Q[3:1};
endmodle
40
Toma Sacco, Ph.D.
Shift Register
SHL clk operation
0
QQ
1
SHL(Q)
SISHL
SHL
I1 I0
S
I1 I0
S
D Q
I1 I0
S
I1 I0
S
D Q
D Q
D Q
clk
Q3
Q2
Q1
41
Toma Sacco, Ph.D.
Q0
Verilog Description
module reg4(SISHL,SHL,clk,Q);
input SISHL, SHL, clk;
output [3:0] Q;
reg [3:0] Q;
always @ (posedge clk)
begin
if(SHL)
Q <={Q[2:0] , SISHL} ;
else
Q <= Q;
end
endmodle
42
Toma Sacco, Ph.D.
Shift Register
S
clk
I
4
operation
00
01
SHL(Q)
10
SHR(Q)
11
Load
SISHR
SISHL
clk
SISHR
I3
SISHL
I3 I2 I1 I0
S
I2
I1
I0
I3 I2 I1 I0
S
I3 I2 I1 I0
S
I3 I2 I1 I0
S
D Q
D Q
D Q
D Q
clk
Q3
Q2
Q1
Q0
43
Toma Sacco, Ph.D.
module GPR(clk,SISHL,SISHR,S,I,Q );
parameter n=4;
input clk,SISHL,SISHR;
input [1:0] S;
input [n-1:0]I;
output reg [n-1:0] Q=0;
always@(posedge clk)
case(S)
0: Q<=Q;
1: Q<= {Q[n-2:0],SISHL};
2: Q<= {SISHR,Q[n-1:1]};
3: Q<= I;
endcase
endmodule
Toma Sacco, Ph.D.
44
module testregister;
// Inputs
reg clk;reg SISHL;reg SISHR;reg [1:0] S;reg [3:0] I;
// Outputs
wire [3:0] Q;
localparam [7:0] period=1;
// Instantiate the Unit Under Test (UUT)
GPR uut (.clk(clk),.SISHL(SISHL),.SISHR(SISHR),.S(S),.I(I),.Q(Q));
//clk
initial
begin
clk=0;
forever # (period/2.0) clk=~clk;
end
//testing
initial
begin
// Initialize Inputs
SISHL = 0;SISHR = 0;S = 0;I = 0;
# period S = 3;I = 14; //load
# period S=0; I=0;
//hold
# period S=2;
//Shift right
# (period*2) S=1;
//Shift left
# (period*2) S=0;
//hold
end
always
begin
clk<=0; #(period/2.0);
clk<=1; #(period/2.0);
end
endmodule
45
Register Applications
1. Store Data
2. Shift Data left (Multiply by powers of 2)
3. Shift Data right (Divide by powers of 2)
4. Convert parallel data to serial
5. Convert serial data to parallel
>>
<<
>>>
arithmetic right shift (filling the most significant bit with the original
value of the most significant bit, in order to retain the sign)
<<<
46
Analysis
1
2
1
2
4
1
4
Q
D
clk
Q
clk
D = Q.T + Q . T
T
0
0
1
1
PS
0
1
0
1
D NS
0 0
1 1
1 1
0 0
47
Toma Sacco, Ph.D.
T flip-flop
T
Q
clk
Q
Excitation table
PS NS
0
0
1
1
0
1
0
1
T
0
1
1
0
Characteristic Table
operation
hold
toggle
Truth table or
Characteristic equation
Q+ = T Q + T Q
48
Toma Sacco, Ph.D.
0
1
0
0
T
1
State diagram
0
T
clk
T
1
ASM chart
Q
Timing diagram
49
Toma Sacco, Ph.D.
Binary Counter
11
10
01
00
2
Q
T1= Q0 , T0=1
T
clk
VCC
clk
Q1
Q0
clk
Q1
Q0
Toma Sacco, Ph.D.
50
PS
Q1 Q0
NS
Q1 Q0
T1 T0
0 1
1 1
0 1
1 1
Verilog description
2-bit Counter
module upcount(Clk, Q);
input Clk, ;
output [1:0] Q;
reg [1:0] Q;
always @(posedge Clk)
Q <= Q + 1;
endmodule
51
Toma Sacco, Ph.D.
clk
reset
Binary Counter
n
Q
//n-bit counter
module counter(reset,clk,Q);
parameter n=4;
input clk,reset;
output [n-1:0] Q;
reg [n-1:0]Q;
initial Q=0;
always@(posedge clk)
if(reset)
Q<=0;
else
Q <= Q + 1;
endmodule
52
Toma Sacco, Ph.D.
`timescale 1ns/10ps
module counter_test_v_tf();
// Inputs
reg reset;
reg clk;
// Outputs
wire [1:0] Q;
// Instantiate the UUT
counter uut (
.reset(reset),
.clk(clk),
.Q(Q)
);
// Initialize Inputs
initial
begin
reset = 0;
clk = 0;
forever
#1 clk=~clk;
end
initial
begin
#2 reset=1;
#2 reset=0;
end
endmodule
53
Toma Sacco, Ph.D.
I
Q
clk
L
E
Reset
Asynchronous reset
Reset
0
1
1
1
L
x
1
0
0
E CLK Q
x x
0
x
I
1 Q+1
0
Q
54
Toma Sacco, Ph.D.
I
clk
L
E
L
1
0
0
E CLK
x
Q
I
Q-1
Q
I
clk
L
E
UD
L
1
0
0
0
E
x
0
1
1
UD CLK Q
x
I
x
Q
1
Q+1
0
Q-1
58
Toma Sacco, Ph.D.
Counter
S
clk
operation
00
Hold
01
QQ+1
10
QQ-1
11
Load
I
n
clk
n
59
module testcounter;
// Inputs
reg clk; reg [1:0] S;reg [3:0] I;
// Outputs
wire [3:0] Q;
localparam [7:0] period=1;
// Instantiate the Unit Under Test (UUT)
GPC uut (.clk(clk), .S(S), .I(I), .Q(Q));
// clock
initial begin
clk=0;
forever #(period/2.0) clk=~clk;
end
//testing
initial
begin
S = 0;I = 0;
#period S=3; I=4'd6; //load
#period S=0;
//hold
#period S=2;
//decrement
#(period *2) S=1;
//increment
#(period *2) S=0;
end
endmodule
60
Applications of Counters:
1. Count Events
2. Change the rate of change of a signal, such as clk
dividers
3. Time the generation of events
4. Time events
5. Time the time between events
61
Analysis
1
J
K
4
1
Q
D
clk
Q
clk
D = J.Q + K.Q
D = J.Q + K.Q
J
0
0
0
0
1
1
1
1
K PS
0 0
0 1
1 0
1 1
0 0
0 1
1 0
1 1
D NS
0 0
1 1
0 0
0 0
1 1
1 1
1 1
0 0
Characteristic equation
Q+ = JQ + K Q
63
Toma Sacco, Ph.D.
JK flip-flop
J
Q
clk
Characteristic Table
Q
Excitation table
PS NS J K
0
0
1
1
0
1
0
1
0x
1x
x1
x0
J K operation
00
hold
01
10
11
reset
set
toggle
Truth table
Characteristic equation
Q+ = JQ + K Q
64
Toma Sacco, Ph.D.
10, 11
00, 01
Inputs=JK
0
00, 10
JK
01, 11
0x
1x
State diagram
JK
clk
J
x0
x1
ASM chart
Timing diagram
65
Toma Sacco, Ph.D.
Vi1
Vo1, Vi2
Q
Q=1
Metastable state
Vo2
Q=0
Q
Vi1
Vo2
Specify a setup time, tsu, and hold time, th, requirements. The
setup time is the time that the D input to a gated D Latch
circuit must be held stable prior to the G input going low. The
hold time is the time that the D input must be held stable after
the G input goes low. If the D input changes too soon before
or after the C input changes from high to low, then the latch
may fail to store the intended value of D.
G
D
Q
tsu
th