07-SequentialLogic
07-SequentialLogic
and
System Design
7. Sequential Logic
COL215, I Semester 2024-2025
Venue: LHC 408
‘E’ Slot: Tue, Wed, Fri 10:00-11:00
a b c a b c
• Implement: y = a + b + c
• ...with only ONE adder
• REUSE the adder t=a+b
• Need to STORE
intermediate value y
y=t+c
• t=a+b 2 Adders
Store intermediate value t
• y=t+c Use later for 2nd addition
(C) P. R. Panda, IIT Delhi, 2024
Complex Computation
a b c d
• Break up complex y=a+b+c–d+e
function/computation
• intermediate values s=a+b t=c-d
s=a+b
• similar to software t=c–d
• Efficient resource u=s+t e
y=u+e
utilization u=s+t
• same adder reused
for several additions
y=u+e
(C) P. R. Panda, IIT Delhi, 2024
New Hardware Components
a b c d
• Elementary operation:
• Store a value
• use it later s=a+b t=c-d
• Control and Sequencing
• Manage order of operations e
• Decide what action is performed by unit u=s+t
(ADD vs SUB)
• Provide alternative paths for operands
y=u+e
(C) P. R. Panda, IIT Delhi, 2024
Combinational vs. Sequential Logic
inputs
• Combinational: Combinational
• Output is a function only of Logic
present inputs outputs
• Independent of earlier input values
inputs
• Sequential:
• Output is a function of present Sequential
input AND earlier inputs memory Logic
Clock Signal
Positive Negative
Edge Edge
• No common clock
• Completion signalled by individual components
• Contrast: In Synchronous Design completion is checked only at
clock edges
R (reset)
Q
Q’ (complement of Q)
S (set)
1 1 0 0
R (reset) R 0 R (reset) R 1
Q Q Q Q
Q’ Q’ Q’ Q’
S (set) 0 S 0 1 S (set) 1 S 1 0
R (reset)
Q
Q’ (complement of Q)
S (set)
0 0 0 0
R (reset) 0 R 0 R (reset) 1 R 1
Q Q Q Q
Q’ Q’ Q’ Q’
S (set) 0 1 S 0 1 S (set) 0 0 S 0 0
RS = 00: Outputs QQ’=01 maintained (no change) RS = 00: Outputs QQ’=10 maintained (no change)
(C) P. R. Panda, IIT Delhi, 2024
Unstable conditions in SR Latch
1 1 0 0
R (reset) R 0 R 0 R 1
Q Q Q Q
Q’ Q’ Q’ Q’
S (set) 1 S 1 0 S 0 0 S 0 1
1 0 0 0
R 0 R 1 R 1 R 0
Q Q Q Q
Q’ Q’ Q’ Q’
S 0 1 S 1 0 S 0 0 S 0 1
S (set) Q
R (reset) Q’ (complement of Q)
0 0 1 1
S (set) S 1 S (set) S 0
Q Q Q Q
R (reset) Q’ R 0 Q’ R (reset) Q’ R 1 Q’
1 1 0 0
S (set) Q
R (reset) Q’
1 1 0 1 1
S 0 S S 1 S 1
Q Q Q Q
R Q’ R Q’ R Q’ R Q’
1 1 1 1 1 0 1 0
SR = 11: Outputs QQ’=01 maintained (no change) SR = 11: Outputs QQ’=10 maintained (no change)
0 0 1 1 0
S S 1 S 1 S
Q Q Q Q
R Q’ R Q’ R Q’ R 0
Q’
0 0 1 1 1 1
SR = 00: Outputs QQ’=11 SR = 11: Outputs QQ’=00
1 1 0
S 1 S
Q Q
0 1 1 0 1
1 0 S S 1
S Q S Q Q Q
R Q’ R Q’
R 0 Q’ R 1 Q’ 1 1 1 0
1 0
SR = 01: Output Q=1 SR = 10: Output Q=0 SR = 11: Output Q unchanged
S R Q Q’
Working of the NAND SR Latch 0 1 1 0
• Normally, SR=11 1 1 1 0
• If Q=0 needed, make SR=10. Return to SR=11.
1 0 0 1
• If Q=1 needed, make SR=01. Return to SR=11. Not Allowed
• Don’t set SR=00 1 1 0 1
• Don’t go directly from SR=01 to SR=10 0 0 1 1
(C) P. R. Panda, IIT Delhi, 2024
Function Table
NAND/NOR Latch needs enhancement
S (set)
Q
Derive R from S?
R (reset) Q’
En
• En (enable) signal
S (set)
x
• When En=0: x = y = 1 Q
• save state
• When En = 1:
• x = S’ Q’
R (reset) y
• y = R’
• En (enable) signal
• When En=0: x = y = 1 D
• save state
x
• When En = 1: Q
• x = D’
• y=D En
• D input ignored when En = 0
Q’
• When En=1: Q = D y
• Q follows D when En enabled
• Last D value saved when En
disabled
previous
Q value
D En D Q previous
0 0 q Q value
0 1 q En D Q
1 0 0 0 x q
Q
1 1 1 1 x D
Function Function
Table Table
(C) P. R. Panda, IIT Delhi, 2024
Concerns about Latches
Clock
Master Slave
D-Latch D-Latch
D R Q D
D Q D Q
En En R
Q
Clock
Clock=1: Master Enabled. Slave disabled. Q follows R when Clock=0 (Slave Enabled)
Clock=0: Slave Enabled. Master disabled.
Clock
Master Slave
D-Latch D-Latch
D R Q D
D Q D Q
En En R
Q
Clock
Clk = 0:
3 SR Latches
S
1 Q
Clk
Maintain Q,Q’
0
1 Q’
R
D D
0 1
Hold Time
Setup Time
D needs to be constant for this
D needs to be constant for this
duration after clock edge
duration before clock edge
Minimum Pulse Width
Clock needs to be constant
for at least this duration
Clock
• T flip-flop
• T=0: Q=q
• T=1: Q=NOT q
• JK flip-flop
• J=1,K=0: Q=1
• J=0,K=1: Q=0
• J=1,K=1: Q=NOT q
• J=0,K=0: Q=q
(C) P. R. Panda, IIT Delhi, 2024
T (Toggle) Flip-Flop
T Flip-flop Specification
q
Q
? D Q
T
Clk
Clock
Specification
• J=1,K=0: Q=1
On clock edge: • J=0,K=1: Q=0
• J=1,K=1: Q=NOT q
• J=0,K=0: Q=q
q
Q
J ? D Q
K
Clk
Clock
S S
Q Q
Clk Clk
Q’ R
Q’
R
D RESET acts
D independently
RESET of Clk, D
RESET Asynchronous Reset
??
(C) P. R. Panda, IIT Delhi, 2024
Characteristic Tables: Flip-flop Properties
D Q (t+1) J K Q (t+1)
0 0 Reset 0 0 Q(t) No change
1 1 Set 0 1 0 Reset
1 0 1 Set
D Flip-flop 1 1 Q’(t) Complement
Characteristic Table
JK Flip-flop
T Q (t+1) Characteristic Table
0 Q(t) No change
1 Q’(t) Complement
T Flip-flop
Characteristic Table
D Q (t+1) J K Q (t+1)
0 0 Reset 0 0 Q(t) No change
1 1 Set 0 1 0 Reset
1 0 1 Set
D Flip-flop 1 1 Q’(t) Complement
Q (t+1) = D
JK Flip-flop
T Q (t+1) Q (t+1) = Q’J + QK’
0 Q(t) No change
1 Q’(t) Complement
Q (= Q(t)): Value of Q just before clock edge
T Flip-flop
Clock is implicit (not written in equation)
Q (t+1) = Q ⊕ T
x A
• All clocked sequential D Q
circuits have: Clk
A’
• Inputs
• Outputs
• Combinational logic B
D Q
• functions of inputs and Qs
B’
• A set of flip-flops (any type) Clock Clk
• A clock (common to all flip-
flops) y
State
next
Register present
state f
F D Q state
Clk
G g
D Q
Clk
a Combinational preset next
inputs b Logic i/p state state o/p
c a b c f g h F G H x y
H D Q h 0 0 0 0 0 0 0 1 0 1 0
• on clock edge: F,G,H →f,g,h Clk 0 0 0 0 0 1 0 1 0 1 0
x
• clock implicit y
• Given circuit, we can derive state table outputs state table
• Given state table, can derive circuit (C) P. R. Panda, IIT Delhi, 2024
Deriving State Table
State Table
x A a
D Q a b x A B y
0 0 0 0 0 0
Clk 0 0 1 0 1 0
0 1 0 0 0 1
0 1 1 1 1 0
b 1 0 0 0 0 1
B
D Q 1 0 1 1 0 0
1 1 0 0 0 1
Clock Clk 1 1 1 1 0 0
10
10
Assume: P=0 upon reset
(C) P. R. Panda, IIT Delhi, 2024
Deriving State Table from FSM
present next
state state
FSM (States + Transitions)
R=1/P=0 a b R A B P
0 0 0 0 0 0
R=0/P=0 00 01
R=0/P=0 0 0 1 0 1 0
main loop 0 1 0 0 0 0
R=0/P=0 0 1 1 1 0 0
R=1/P=1 R=1/P=0
1 0 0 0 0 0
1 0 1 0 0 1
10
1 1 0 - - -
1 1 1 - - -
present next
state state
next State
a b R A B P present a state Register
0 0 0 0 0 0 state A
D Q
0 0 1 0 1 0
b Combi- Clk
0 1 0 0 0 0
0 1 1 1 0 0 national
B
1 0 0 0 0 0 Logic D Q
1 0 1 0 0 1 R Clk
1 1 0 - - - P
1 1 1 - - -
10 11
Specification
What changes? Sequence of states: 0,1,3,0,1,3,...
Output P = 1 every 3rd clock cycle
What remains unchanged? Output P = 0 in other cycles Output P sequence unchanged!
Is the functionality still delivered? If input R = 0, reset count to zero Specification still met.
If input R = 1, resume counting Values 00, 01, etc., don’t matter
(C) P. R. Panda, IIT Delhi, 2024
FSM States can be Symbolic
10 Z
present
Encoded State Table state
(Truth Table)
a next State
present next state Register
state state A Q
D
a b R A B P Clk
0 0 0 0 0 0 b
0 0 1 0 1 0
0 1 0 0 0 0 B
D Q
0 1 1 1 0 0
1 0 0 0 0 0 Clk
P
1 0 1 0 0 1
R
• Design FSM
• Inputs? Outputs? States? Transitions?
(C) P. R. Panda, IIT Delhi, 2024
FSM Design
Input: 0 1 1 0 1 1 1 0 1 0 1 1 1 1 0 1
Output: 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0
0/0 1/0
Style: Mealy Machine
S0 S1 Output is a function of both state and input.
0/0 Output is associated with transition.
• Controller + Datapath
Control
• Controller: FSM (sends control signals)
Signals
• What activity to enable in each clock cycle?
• MUX select inputs FSM
Datapath
• Load enable signals to flip-flops/registers (Controller)
• Datapath: Computation
Status
• Adders, Multipliers, MUXes Signals
• May send status signals back to FSM
• results of comparisons
• overflow/exceptions
VHDL Model
VHDL
Present State Signal entity...
port...
end entity
architecture...
VHDL signal...
VHDL Comb Output process...
State
Input Logic Port -- state register
Register
Port end process
Inputs: Next process...
State Outputs:
Status -- comb. logic
VHDL VHDL Control
Signals end process
Process Process Signals
end architecture
State Reduction :
S2 S2 ?
S1 S1
Equivalent States S0 ? S0 ?
S3 S2 S1 S3S2 S1
0/0 1/0 S2: 0/0 1/1 S2: 0/0 1/1
S1: 0/0 1/0 S3: 0/0 1/1
S0 S1
0/0 O/P Conflict O/P Compatible
0/0 1/0 Step 7 Step 8
0/0
S2 ? S2 ✓
S2 S3
S1 S1
1/1 1/1
S0 S0
S3 S2 S1 S3 S2 S1
S0: 0/[0,S0] 1/[0,S1] S2: 0/[0,S0] 1/[1,S2]
S1: 0/[0,S0] 1/[0,S3] S3: 0/[0,S0] 1/[1/S2]
Next State Conflict Next State Compatible
(C) P. R. Panda, IIT Delhi, 2024
Reducing the FSM