Title: Sequential Logic
1Sequential Logic
- Sequential Circuits
- Simple circuits with feedback
- Latches
- Edge-triggered flip-flops
- Timing Methodologies
- Cascading flip-flops for proper operation
- Clock skew
- Asynchronous Inputs
- Metastability and synchronization
- Basic Registers
- Shift registers
2Sequential Circuits
- Circuits with Feedback
- Outputs f(inputs, past inputs, past outputs)
- Basis for building "memory" into logic circuits
- Door combination lock is an example of a
sequential circuit - State is memory
- State is an "output" and an "input" to
combinational logic - Combination storage elements are also memory
reset
new
equal
value
C1
C2
C3
mux control
comb. logic
multiplexer
clock
state
comparator
equal
open/closed
3Circuits with Feedback
- How to control feedback?
- What stops values from cycling around endlessly
X1X2Xn
Z1Z2Zn
switchingnetwork
4Simplest Circuits with Feedback
- Two inverters form a static memory cell
- Will hold value as long as it has power
applied - How to get a new value into the memory cell?
- Selectively break feedback path
- Load new value into cell
5Memory with Cross-coupled Gates
- Cross-coupled NOR gates
- Similar to inverter pair, with capability to
force output to 0 (reset1) or 1 (set1) - Cross-coupled NAND gates
- Similar to inverter pair, with capability to
force output to 0 (reset0) or 1 (set0)
6Timing Behavior
Hold
Race
Reset
Set
Set
Reset
100
R S Q \Q
7S
R
Q
Q
R
a
b
Q
a
0
0
0/11/0
(no change)
0
1
0
1
1
0
1
0
1
1
0
0
Q
b
S
(a) Circuit
(b) Truth table
t
t
t
t
t
t
t
t
t
t
1
2
3
4
5
6
7
8
9
10
1
R
0
1
S
0
1
Q
?
a
0
1
Q
?
b
0
Time
(c) Timing diagram
Figure 7.5 A latch built with NOR gates
8 (
)
S
R
Clk
Q
t
1
R
R
Q
x
x
Q(
t
) (no change)
0
0
0
1
Q(
t
) (no change)
Clk
0
1
0
1
1
0
1
1
Q
1
1
1
x
S
S
(a) Circuit
(b) Truth table
1
Clk
0
1
R
0
1
S
0
1
?
Q
0
1
?
Q
0
Time
(c) Timing diagram
Q
S
Clk
Q
R
(d) Graphical symbol
Figure 7.6 Gated SR latch
9S
Q
Clk
Q
R
Figure 7.7 Gated SR latch with NAND gates
10 S
D
(Data)
Q
Clk
Q
R
(a) Circuit
D
Q
Clk
D
Q
t
1
(
)
Q
t
(
)
0
x
1
0
0
Q
Clk
1
1
1
(b) Truth table
(c) Graphical symbol
t
t
t
t
1
2
3
4
Clk
D
Q
Time
(d) Timing diagram
Figure 7.8 Gated D latch
11t
su
t
h
Clk
D
Q
Figure 7.9 Setup and hold times
12 Master
Slave
Q
Q
m
s
D
Q
Q
D
Q
D
Q
Clock
Q
Clk
Clk
Q
(a) Circuit
Clock
D
Q
m
Q
Q
s
(b) Timing diagram
D
Q
Q
(c) Graphical symbol
Figure 7.10 Master-slave D flip-flop
131
P3
P1
2
5
Q
Clock
6
Q
P2
3
P4
4
D
(a) Circuit
Figure 7.11 A positive-edge-triggered D
flip-flop
14 D
Q
D
Q
a
Q
Clock
Q
Clk
a
Q
D
Q
b
Q
Q
b
Q
D
Q
c
Q
Q
c
(a) Circuit
Clock
D
Q
a
Q
b
Q
c
(b) Timing diagram
Figure 7.12 Comparison of level-sensitive and
edge-triggered
15Preset
D
Q
Clock
Q
Clear
(a) Circuit
Preset
D
Q
Q
Clear
(b) Graphical symbol
Figure 7.13 Master-slave D flip-flop with
Clear and Preset
16 Preset
Q
Clock
Q
D
Clear
(a) Circuit
Preset
D
Q
Q
Clear
(b) Graphical symbol
Figure 7.14 Positive-edge-triggered D flip-flop
with Clear and Preset
17Figure 7.15 Synchronous reset for a D flip-flop
18 D
Q
Q
T
Q
Q
Clock
(a) Circuit
Q
t
1
(
)
T
Q
T
0
Q
t
(
)
1
(
)
Q
Q
t
(b) Truth table
(c) Graphical symbol
Clock
T
Q
(d) Timing diagram
Figure 7.16 T flip-flop
19J
Q
D
Q
K
Q
Q
Clock
(a) Circuit
Q
t
1
(
)
K
J
0
Q
t
(
)
0
J
Q
1
0
0
0
1
1
Q
K
1
Q
t
(
)
1
(b) Truth table
(c) Graphical symbol
Figure 7.17 JK flip-flop
20Q
Q
Q
Q
1
2
3
4
In
Out
D
Q
D
Q
D
Q
D
Q
Clock
Q
Q
Q
Q
(a) Circuit
Q
Q
Q
Q
Out
In
1
2
3
4
t
1
0
0
0
0
0
t
0
1
0
0
0
1
t
1
0
1
0
0
2
t
1
1
0
1
0
3
t
1
1
1
0
1
4
t
0
1
1
1
0
5
t
0
0
1
1
1
6
t
0
0
0
1
1
7
(b) A sample sequence
Figure 7.18 A simple shift register
21Parallel output
Q
Q
Q
Q
3
2
1
0
Q
Q
Q
Q
D
D
D
D
Q
Q
Q
Q
Clock
Serial
Shift/Load
input
Parallel input
Figure 7.19 A simple shift register
22Q
Q
Q
1
T
T
T
Clock
Q
Q
Q
Q
Q
Q
0
1
2
(a) Circuit
Clock
Q
0
Q
1
Q
2
Count
0
1
2
3
4
5
6
7
0
(b) Timing diagram
Figure 7.20 A three-bit up-counter
231
Q
Q
Q
T
T
T
Clock
Q
Q
Q
Q
Q
Q
0
1
2
(a) Circuit
Clock
Q
0
Q
1
Q
2
Count
0
7
6
5
4
3
2
1
0
(b) Timing diagram
Figure 7.21 A three-bit down-counter
24Clock cycle
Q
Q
Q
2
1
0
Q
changes
1
0
0
0
0
Q
changes
0
1
1
0
2
1
0
2
0
1
1
3
0
0
0
4
1
0
1
5
1
1
0
6
1
1
1
7
1
0
0
8
0
Table 7.1 Derivation of the synchronous
up-counter
251
T
Q
T
Q
T
Q
T
Q
Q
Q
Q
Q
0
1
2
3
Clock
Q
Q
Q
Q
(a) Circuit
Clock
Q
0
Q
1
Q
2
Q
3
Count
0
1
2
3
5
9
12
14
0
4
6
8
7
10
11
13
15
1
(b) Timing diagram
Figure 7.22 A four-bit synchronous up-counter
26T
Q
T
Q
Enable
T
Q
T
Q
Clock
Q
Q
Q
Q
Clear
Figure 7.23 Inclusion of enable and clear
capability
27 Q
Q
D
0
Enable
Q
Q
Q
D
1
Q
Q
Q
D
2
Q
Q
Q
D
3
Q
Output
carry
Clock
Figure 7.24 A four-bit counter with D flip-flop
28Enable
1
Q
D
0
0
0
Q
D
0
1
1
Q
D
0
2
2
Load
Clock
Clock
(a) Circuit
Clock
Q
0
Q
1
Q
2
0
1
2
3
4
5
0
1
Count
(b) Timing diagram
Figure 7.26 A modulo-6 counter with
synchronous reset
291
T
Q
T
Q
T
Q
Q
Q
Q
0
1
2
Clock
Q
Q
Q
(a) Circuit
Clock
Q
0
Q
1
Q
2
Count
0
1
2
3
4
5
0
1
2
(b) Timing diagram
Figure 7.27 A modulo-6 counter with
asynchronous reset
30Enable
1
Q
D
0
0
0
Q
D
0
1
1
BCD
Q
D
0
0
2
2
Q
D
0
3
3
Load
Clock
Clock
Enable
Clear
Q
D
0
0
0
Q
D
0
1
1
BCD
1
Q
D
0
2
2
Q
D
0
3
3
Load
Clock
Figure 7.28 A two-digit BCD counter
31Q
Q
Q
0
1
n
1
D
Q
D
Q
D
Q
Q
Q
Q
Reset
Clock
Figure 7.30 Johnson counter
32 Figure 7.57 Details for connecting a register
to a bus
33,
,
,
R
2
R
3
R
1
R
2
R
3
R
1
out
in
out
in
out
in
w
Q
Q
Q
D
D
D
Clock
Q
Q
Q
Reset
Figure 7.58 A shift-register control circuit
34R
2
R
3
,
R
1
R
2
,
R
3
R
1
,
out
in
out
in
out
in
Reset
w
P
D
Q
D
Q
D
Q
Q
Q
Q
Clock
Figure 7.59 A modified control circuit
35Bus
R
1
R
2
Rk
in
in
in
R
1
R
2
Rk
Clock
Data
S
0
Multiplexers
S
j
1
Figure 7.61 Using multiplexers to implement a
bus
36V
V
DD
DD
c
c
c
0
1
9
R
L
10-bit counter
V
LED
Clock
(a) Clock divider
(b) LED circuit
V
V
DD
DD
R
R
L
a
b
g
a
b
g
w
Converter
Converter
w
w
w
w
w
w
w
w
0
1
2
3
0
1
2
3
0
D
Q
1
1
c
Q
9
BCD
BCD
0
1
E
Two-digit BCD counter
Reset
Clear
(c) Push-button switch, LED, and 7-segment
displays
Figure 7.77 A reaction-timer circuit
37Figure 7.57 Details for connecting a register
to a bus
38Figure 7.70 A digital system that implements a
simple processor
39 State Behavior of R-S latch
- Truth table of R-S latch behavior
40Theoretical R-S Latch Behavior
- State Diagram
- States possible values
- Transitions changesbased on inputs
41Observed R-S Latch Behavior
- Very difficult to observe R-S latch in the 1-1
state - One of R or S usually changes first
- Ambiguously returns to state 0-1 or 1-0
- A so-called "race condition"
- Or non-deterministic transition
42R-S Latch Analysis
Q(t)
Q(t?)
S
R
characteristic equation Q(t?) S R Q(t)
43Gated R-S Latch
- Control when R and S inputs matter
- Otherwise, the slightest glitch on R or S while
enable is low could cause change in value stored
44Clocks
- Used to keep time
- Wait long enough for inputs (R' and S') to settle
- Then allow to have effect on value stored
- Clocks are regular periodic signals
- Period (time between ticks)
- Duty-cycle (time clock is high between ticks -
expressed as of period)
duty cycle (in this case, 50)
period
45Clocks (contd)
- Controlling an R-S latch with a clock
- Can't let R and S change while clock is active
(allowing R and S to pass) - Only have half of clock period for signal changes
to propagate - Signals must be stable for the other half of
clock period
46Cascading Latches
- Connect output of one latch to input of another
- How to stop changes from racing through chain?
- Need to control flow of data from one latch to
the next - Advance from one latch per clock period
- Worry about logic between latches (arrows) that
is too fast
47Master-Slave Structure
- Break flow by alternating clocks (like an
air-lock) - Use positive clock to latch inputs into one R-S
latch - Use negative clock to change outputs with another
R-S latch - View pair as one basic unit
- master-slave flip-flop
- twice as much logic
- output changes a few gate delays after the
falling edge of clock but does not affect any
cascaded flip-flops
48The 1s Catching Problem
- In first R-S stage of master-slave FF
- 0-1-0 glitch on R or S while clock is high
"caught" by master stage - Leads to constraints on logic to be hazard-free
49D Flip-Flop
- Make S and R complements of each other
- Eliminates 1s catching problem
- Can't just hold previous value (must have new
value ready every clock period) - Value of D just before clock goes low is what is
stored in flip-flop - Can make R-S flip-flop by adding logic to make D
S R' Q
10 gates
50Edge-Triggered Flip-Flops
- More efficient solution only 6 gates
- sensitive to inputs only near edge of clock
signal (not while high)
holds D' when clock goes low
negative edge-triggered D flip-flop (D-FF) 4-5
gate delays must respect setup and hold time
constraints to successfullycapture input
holds D whenclock goes low
characteristic equationQ(t1) D
51Edge-Triggered Flip-Flops (contd)
new D ? old D
when clock is low data is held
when clock goes high-to-low data is latched
52Edge-Triggered Flip-Flops (contd)
- Positive edge-triggered
- Inputs sampled on rising edge outputs change
after rising edge - Negative edge-triggered flip-flops
- Inputs sampled on falling edge outputs change
after falling edge
100
D CLK Qpos Qpos' Qneg Qneg'
positive edge-triggered FF
negative edge-triggered FF
53Timing Methodologies
- Rules for interconnecting components and clocks
- Guarantee proper operation of system when
strictly followed - Approach depends on building blocks used for
memory elements - Focus on systems with edge-triggered flip-flops
- Found in programmable logic devices
- Many custom integrated circuits focus on
level-sensitive latches - Basic rules for correct timing
- (1) Correct inputs, with respect to time, are
provided to the flip-flops - (2) No flip-flop changes state more than once per
clocking event
54Timing Methodologies (contd)
- Definition of terms
- clock periodic event, causes state of memory
element to change can be rising or falling edge,
or high or low level - setup time minimum time before the clocking
event by which the input must be stable (Tsu) - hold time minimum time after the clocking event
until which the input must remain stable (Th)
data
clock
there is a timing "window" around the clocking
event during which the input must remain stable
and unchanged in order to be recognized
changing
stable
data
clock
55Comparison of Latches and Flip-Flops
D CLK Qedge Qlatch
CLK
positiveedge-triggeredflip-flop
CLK
transparent(level-sensitive)latch
behavior is the same unless input changes while
the clock is high
56Comparison of Latches and Flip-Flops (contd)
Type When inputs are sampled When output is
valid unclocked always propagation delay from
input changelatch level-sensitive clock
high propagation delay from input
changelatch (Tsu/Th around falling or clock edge
(whichever is later) edge of clock) master-slave
clock high propagation delay from falling
edgeflip-flop (Tsu/Th around falling of
clock edge of clock) negative clock hi-to-lo
transition propagation delay from falling
edgeedge-triggered (Tsu/Th around falling of
clockflip-flop edge of clock)
57Typical Timing Specifications
- Positive edge-triggered D flip-flop
- Setup and hold times
- Minimum clock width
- Propagation delays (low to high, high to low, max
and typical)
all measurements are made from the clocking event
that is, the rising edge of the clock
58Cascading Edge-triggered Flip-Flops
- Shift register
- New value goes into first stage
- While previous value of first stage goes into
second stage - Consider setup/hold/propagation delays (prop must
be gt hold)
100
IN Q0 Q1 CLK
59Cascading Edge-triggered Flip-Flops (contd)
- Why this works
- Propagation delays exceed hold times
- Clock width constraint exceeds setup time
- This guarantees following stage will latch
current value before it changes to new value
In Q0 Q1 CLK
Tsu 4ns
Tsu 4ns
timing constraints guarantee proper operation
of cascaded components
Tp 3ns
Tp 3ns
assumes infinitely fast distribution of the clock
Th 2ns
Th 2ns
60Clock Skew
- The problem
- Correct behavior assumes next state of all
storage elementsdetermined by all storage
elements at the same time - tThis is difficult in high-performance systems
because time for clock to arrive at flip-flop is
comparable to delays through logic - Effect of skew on cascaded flip-flops
100
In Q0 Q1 CLK0 CLK1
CLK1 is a delayed version of CLK0
original state IN 0, Q0 1, Q1 1 due to
skew, next state becomes Q0 0, Q1 0, and not
Q0 0, Q1 1
61Summary of Latches and Flip-Flops
- Development of D-FF
- Level-sensitive used in custom integrated
circuits - can be made with 4 switches
- Edge-triggered used in programmable logic devices
- Good choice for data storage register
- Historically J-K FF was popular but now never
used - Similar to R-S but with 1-1 being used to toggle
output (complement state) - Good in days of TTL/SSI (more complex input
function D JQ' K'Q - Not a good choice for PALs/PLAs as it requires 2
inputs - Can always be implemented using D-FF
- Preset and clear inputs are highly desirable on
flip-flops - Used at start-up or to reset system to a known
state
62Metastability and Asynchronous inputs
- Clocked synchronous circuits
- Inputs, state, and outputs sampled or changed in
relation to acommon reference signal (called the
clock) - E.g., master/slave, edge-triggered
- Asynchronous circuits
- Inputs, state, and outputs sampled or changed
independently of a common reference signal
(glitches/hazards a major concern) - E.g., R-S latch
- Asynchronous inputs to synchronous circuits
- Inputs can change at any time, will not meet
setup/hold times - Dangerous, synchronous inputs are greatly
preferred - Cannot be avoided (e.g., reset signal, memory
wait, user input)
63Synchronization Failure
- Occurs when FF input changes close to clock edge
- FF may enter a metastable state neither a logic
0 nor 1 - May stay in this state an indefinite amount of
time - Is not likely in practice but has some probability
logic 1
logic 0
logic 0
logic 1
oscilloscope traces demonstrating synchronizer
failure and eventual decay to steady state
small, but non-zero probability that the FF
output will get stuck in an in-between state
64Dealing with Synchronization Failure
- Probability of failure can never be reduced to 0,
but it can be reduced - (1) slow down the system clock this gives the
synchronizer more time to decay into a steady
state synchronizer failure becomes a big
problem for very high speed systems - (2) use fastest possible logic technology in the
synchronizerthis makes for a very sharp "peak"
upon which to balance - (3) cascade two synchronizers this effectively
synchronizes twice (both would have to fail)
Q
asynchronous input
synchronized input
D
Q
D
Clk
synchronous system
65Handling Asynchronous Inputs
- Never allow asynchronous inputs to fan-out to
more than one flip-flop - Synchronize as soon as possible and then treat as
synchronous signal
Clocked
Synchronizer
Synchronous
System
Q0
Q0
Async
Async
Input
Input
Clock
Clock
Q1
Q1
Clock
Clock
66Handling Asynchronous Inputs (contd)
- What can go wrong?
- Input changes too close to clock edge (violating
setup time constraint)
In Q0 Q1 CLK
In is asynchronous and fans out to D0 and
D1one FF catches the signal, one does
not inconsistent state may be reached!
67Flip-Flop Features
- Reset (set state to 0) R
- Synchronous Dnew R' Dold (when next clock
edge arrives) - Asynchronous doesn't wait for clock, quick but
dangerous - Preset or set (set state to 1) S (or sometimes
P) - Synchronous Dnew Dold S (when next clock
edge arrives) - Asynchronous doesn't wait for clock, quick but
dangerous - Both reset and preset
- Dnew R' Dold S (set-dominant)
- Dnew R' Dold R'S (reset-dominant)
- Selective input capability (input enable/load)
LD or EN - Multiplexer at input Dnew LD' Q LD Dold
- Load may/may not override reset/set (usually R/S
have priority) - Complementary outputs Q and Q'
68Registers
- Collections of flip-flops with similar controls
and logic - Stored values somehow related (e.g., form binary
value) - Share clock, reset, and set lines
- Similar logic at each stage
- Examples
- Shift registers
- Counters
69Shift Register
- Holds samples of input
- Store last 4 input values in sequence
- 4-bit shift register
70Universal Shift Register
- Holds 4 values
- Serial or parallel inputs
- Serial or parallel outputs
- Permits shift left or right
- Shift in new values from left or right
clear sets the register contentsand output to
0s1 and s0 determine the shift function
s0 s1 function 0 0 hold state 0 1 shift
right 1 0 shift left 1 1 load new input
71Design of Universal Shift Register
- Consider one of the four flip-flops
- New value at next clock cycle
Nth cell
to N-1th cell
to N1th cell
Q
D
CLK
CLEAR
clear s0 s1 new value 1 0 0 0 0 output 0 0
1 output value of FF to left (shift
right) 0 1 0 output value of FF to right (shift
left) 0 1 1 input
s0 and s1control mux
QN-1(left)
QN1(right)
InputN
72Shift Register Application
- Parallel-to-serial conversion for serial
transmission
parallel outputs
parallel inputs
serial transmission
73Pattern Recognizer
- Combinational function of input samples
- In this case, recognizing the pattern 1001 on the
single input signal
74Counters
- Sequences through a fixed set of patterns
- In this case, 1000, 0100, 0010, 0001
- If one of the patterns is its initial state (by
loading or set/reset) - Mobius (or Johnson) counter
- In this case, 1000, 1100, 1110, 1111, 0111, 0011,
0001, 0000
75Binary Counter
- Logic between registers (not just multiplexer)
- XOR decides when bit should be toggled
- Always for low-order bit, only when first bit is
true for second bit, and so on
76Four-bit Binary Synchronous Up-Counter
- Standard component with many applications
- Positive edge-triggered FFs w/ sync load and
clear inputs - Parallel load data from D, C, B, A
- Enable inputs must be asserted to enable
counting - RCO ripple-carry out used for cascading counters
- high when counter is in its highest state 1111
- implemented using an AND gate
(2) RCO goes high
(3) High order 4-bits are incremented
(1) Low order 4-bits 1111
77Offset Counters
- Starting offset counters use of synchronous
load - e.g., 0110, 0111, 1000, 1001, 1010, 1011, 1100,
1101, 1111, 0110, . . . - Ending offset counter comparator for ending
value - e.g., 0000, 0001, 0010, ..., 1100, 1101, 0000
- Combinations of the above (start and stop value)
78Sequential Logic Summary
- Fundamental building block of circuits with state
- Latch and flip-flop
- R-S latch, R-S master/slave, D master/slave,
edge-triggered D FF - Timing methodologies
- Use of clocks
- Cascaded FFs work because prop delays exceed hold
times - Beware of clock skew
- Asynchronous inputs and their dangers
- Synchronizer failure what it is and how to
minimize its impact - Basic registers
- Shift registers
- Pattern detectors
- Counters