0% found this document useful (0 votes)
66 views

Logic Design: Design of Finite State Machines (Chapter 3)

Uploaded by

yonas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

Logic Design: Design of Finite State Machines (Chapter 3)

Uploaded by

yonas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Quick summary…

• Combinational logic circuits


• Basic gates (OR, AND,….)

Logic Design • Combinational devices (Multiplexers, Decoders, Adders,…)

Design of Finite State •We now have storage devices


• D-Latch, RS Latch, D flip-flop

Machines • Implementation of registers and memory


• Using D-latches
(Chapter 3)
• ok…now back to sequential circuits and state machines
Based on slides © McGraw-Hill
Additional material © 2004/2005/2006 Lewis/Martin
• Recall examples of Vending Machine and Counter
Additional material © 2008 Roth
Additional material © 2010 Taylor •Refer to example circuits in fsm-examples.cdl
Additional material © 2013 Farmer
Additional material © 2019 Narahari • The link Examples of Finite State Machines

3 “Storage” Devices Clocked Flip-Flops/Circuits


•Subsystem in a computer consists of a large number of
combinational and sequential devices
RS Latch – Stores 1 Bit, Level-Triggered • Each sequential device is like latch which is in one of two states
R Q -1 “forbidden” input: S=0, R=0 • As machine executes its cycle, the states of all sequential devices
S RS Q’
-Holds Data when RS=11 change with time
•To control large collection of devices in an orderly
WE
(synchronized) fashion, machine maintains a clock
D-Latch – Stores 1 Bit, Level-Triggered • Requires all devices to change their states at the same time
-No “forbidden” inputs (fixes RS Latch) • Clock generates sequence of pulses
D D Q -D=Q when WE=1
-Holds Data when WE=0 • Much easier to design, debug, implement, and test

D-Flip-Flop – Stores 1 Bit, Edge-Triggered •How do we change latches so that they allow change in state
D DFF Q -No “forbidden” inputs synchronized with the clock ?
-D=Q when WE (CLK) transitions from 0 to 1 •Sequential logic circuits require a means by which events can
CLK be sequenced…..clock!
-Holds Data for WE=1 or WE=0
-Except when WE transitions from 0 to 1

1
States in a FSM
Finite State Machine
• The concept of state • In general a Finite State Machine consists of
• the state of a system is a “snapshot” of all relevant elements at a An n-bit storage (register?) which stores the state of the machine
moment in time. A block of logic that computes the next state as a function of the
• a given system will often have only a finite number of possible states. current state and the inputs, if any
• For many systems, we can define the rule which determines under A block of logic which computes the output based on the current
what conditions a system can move from one state to another. state.
So when do they change states ?
– Random times ? Combinational
– Only at specific times ? Clock Logic Blocks

Inputs
Next State Output Outputs
State Register Function
Function (storage)

Latches and Flip-Flops D Flip-Flop


•Latch: basic circuit for storage • We can think of the D Flip-Flop as a 1 bit storage container with an
• Operate on changes in Level (i.e., 1 or 0) input, D, and an output, Q.
• The D flip-flop takes a clock input (often denoted with a triangle)
•Flip-flop:
• A set of D flip-flops can be grouped together with common Clock and
• Sequential circuits take input from output of storage WE inputs to form a register. A key component in our processor
• Latches that work on change of level can lead to unstable sequential
circuits
As level changes the outputs change --- inputs change!
• Flip-Flop circuits designed to operate properly when they are part of a
sequential circuit
Flip flop becomes basic circuit for storage in clocked Flip-Flop
(synchronous) sequential circuits !
D Q

Clock

2
One Last Thing…
D Flip-Flop with Additional Write Enable Examples
• From previous slides, we attached clock to WE of the D-flip-flop •Page 1 of fsm-examples.cdl
• Now, we add another WE line to the flip flop
Just holds onto data already stored in DFF
• Give it the ability to “ignore” the clock!

WE

WE

0
D 1 Q D DFF Q

Clock Clock
Flip-Flop w/WE

Next: Design methodology for sequential logic


State Machine
circuits
•type of sequential circuit
•We have storage devices and method for synchronization • Combines combinational logic with storage
• Flip flops and Clock • “Remembers” state, and changes output and state at each clock
cycle based on inputs and current state
• We can map from Finite state machine diagram (graph) to
truth table
• and we now have a storage device to store the state! State Machine

Inputs Combinational Outputs


Logic Circuit

Storage
Elements

3
States in a FSM
Finite State Machine
• The counter we designed is an example of a finite state machine. • The concept of state
• In general a Finite State Machine consists of • the state of a system is a “snapshot” of all relevant elements at a
moment in time.
An n-bit register which stores the state of the machine
• a given system will often have only a finite number of possible states.
A block of logic that computes the next state as a function of the
current state and the inputs, if any • For many systems, we can define the rule which determines under
what conditions a system can move from one state to another.
A block of logic which computes the output based on the current
state. So when do they change states ?
Combinational – Clock !
Clock Logic Blocks • Encode each state with a binary label
Inputs
Next
State Output Outputs
State
Register Function
Function

Designing and implementing a FSM Counter from 0 to 3 (2-bit counter)


1. First draw the state diagram Reset Circuit has a “ON” switch (input)
• Encode each state in binary using N bits If ON=0 then machine goes to 00
• These N bits correspond to N “state variables” that need to be
ON=1
stored. Call them SN-1 SN-2 …S1S0
ON=1 00
• State diagram will show transitions from state to state based on
value of inputs
01
2. Next, derive the truth table (from state diagram)
• “inputs” in truth table are N current state variables and the inputs 11
• “outputs” are the values of the state variables in the next state and ON=1
the output at each state -- common notation is S’ but confusion ON=1
10
with complement operator, so let’s use S*
3. From truth table, derive combinational circuit (boolean
function) for each of the next state values
• State variables are stored in your N storage elements

4
FSM Representation of 3-bit Counter Storage
Reset •Each D flip flop stores one state bit.

Bubbles represent all •The number of storage elements (flip-flops) needed is


000 possible “states” for the determined by the number of states
machine (aka your flip-flop (and the representation of each state).
111 001 based circuit) • Each bit can be 0 or 1 = 2 states
• N bits can represent 2N states
Arrows show movement from
110 010 one state to the next
•Example: If a FSM has 12 states, then the circuit needs log2
Transitions occur at pulse of
12 = 4 storage elements.
• Fewer the states, less hardware needed
101 011 the clock
 Concept of Minimization of States for a given FSM

100

Designing and implementing a FSM Truth Table for a 2-bit Counter


1. First draw the state diagram • Derive Truth table
• Encode each state in binary using N bits • Using ON, A, B as inputs and A*, B* as outputs
• These N bits correspond to N “state variables” that need to be ON A B A* B*
stored. Call them SN-1 SN-2 …S1S0
1 0 0 0 1
• State diagram will show transitions from state to state based on
value of inputs 1 0 1 1 0
1 1 0 1 1
2. Next, derive the truth table (from state diagram)
1 1 1 0 0
• “inputs” in truth table are N current state variables and the inputs
0 X X 0 0
• “outputs” are the values of the state variables in the next state and
the output at each state -- common notation is S’ but confusion
with complement operator, so let’s use S*
3. From truth table, derive combinational circuit (boolean
function) for each of the next state values
• State variables are stored in your N storage elements

5
Truth Table Representation of 3-bit Counter Designing and implementing a FSM
1. First draw the state diagram
• Encode each state in binary using N bits
Present State Next State
• These N bits correspond to N “state variables” that need to be
D2 (t) D1 (t) D0 (t) D2 (t+1) D1 (t+1) D0 (t+1)
stored. Call them SN-1 SN-2 …S1S0
0 0 0 0 0 1 • State diagram will show transitions from state to state based on
0 0 1 0 1 0 value of inputs
0 1 0 0 1 1 2. Next, derive the truth table (from state diagram)
0 1 1 1 0 0 • “inputs” in truth table are N current state variables and the inputs
1 0 0 1 0 1 • “outputs” are the values of the state variables in the next state and
1 0 1 1 1 0 the output at each state -- common notation is S’ but confusion
with complement operator, so let’s use S*
1 1 0 1 1 1
1 1 1 0 0 0
3. From truth table, derive combinational circuit (boolean
function) for each of the next state values
• State variables are stored in your N storage elements

Functions and Circuit for a 2-bit Counter Example 2-bit Counter


•functions: • Page 9
• A,B current state •Output of the two flip flops are current state variables
• A is top flip flop, B is lower one
• A*, B* next state ON A B A* B* A B A* B*
• Input to Flip flop for A is function for A*
• A* = ON.( (A’B) + (A B’)) = ON.( A XOR B) 1 0 0 0 1 • i.e., output of circuit for A*
• B* = ON.( (A’B’) + (AB’)) = ON. B’ 0 0 0 1
1 0 1 1 0 •Input to flip flop for B is function for B*
1 1 0 1 1 • i.e., output of circuit for B*

1 1 1 0 0 •next state functions: 0 1 1 0


0 X X 0 0 • A,B current state
• A*, B* next state 1 0 1 1
• A* = (A’B) + (A B’) = A XOR B
• B* = (A’B’) + (AB’) = B’ 1 1 0 0

6
Example Circuit for 2-bit counter Truth Table Representation of 3-bit Counter
•Page 2 of fsm-examples.cdl
• Implements the circuits from the truth table:
Present State Next State
• A,B current state: stored in two D flip flops
D2 (t) D1 (t) D0 (t) D2 (t+1) D1 (t+1) D0 (t+1)
• Read current state from output of D flip flop
• A*, B* next state 0 0 0 0 0 1
• Write next state into input of Flip flop – will be written at end of clock cycle
0 0 1 0 1 0
• A* = (A’B) + (A B’) = A XOR B
0 1 0 0 1 1
• B* = (A’B’) + (AB’) = B’
0 1 1 1 0 0
1 0 0 1 0 1
1 0 1 1 1 0
1 1 0 1 1 1
1 1 1 0 0 0

3-bit counter: Boolean functions for values of


Example: Blinking Traffic Sign
next state
•(from textbook) Design control circuitry for a blinking traffic
•For each state variable Di , derive function that determines sign (to show “move right” message):
next state D*i for that variable: •Page 3 of fsm-examples.cdl shows implementation
•Note: D2 (t+1) also denoted as D2’ or D2*
•Current states: D2 D1 D0
•Complete the circuit on Page 4 of fsm-examples.cdl 1 3
5
•D2* = ? Simplify using K-maps

•D1* = ?
4
2
•D0* = ?

DANGER
MOVE RIGHT

7
1 3 1 3
5 5

4 4
2 2

DANGER DANGER
MOVE RIGHT MOVE RIGHT

1 3 1 3
5 5

4 4
2 2

DANGER DANGER
MOVE RIGHT MOVE RIGHT

8
1 3 1 3
5 5

4 4
2 2

DANGER DANGER
MOVE RIGHT MOVE RIGHT

1 3 1 3
5 5

4 4
2 2

DANGER DANGER
MOVE RIGHT MOVE RIGHT

9
Example: Traffic Sign Traffic Sign State Diagram
•A blinking traffic sign: How many lights = 5
•How many states ?
•4 states
• No lights on
• 1 & 2 on Switch on
• 1, 2, 3, & 4 on Switch off
• 1, 2, 3, 4, & 5 on
• (repeat as long as switch is turned on)
•How many bits to represent the 4 states
State bit S1
•S1S0 State bit S0
• With S1S0 values: 00, 01, 10, 11 Outputs
•How many ‘outputs’ (to control the 5 lights) = 5 ?
•If the sign is switched off then all lights turn off
Transition on each clock cycle.

Outputs
•Note we really have 3 groups of lights to be controlled = 3
control lines X,Y,Z
• Group 1: Lights 1 and 2; controlled by Z
0 1
If Z=1 then Group 1 lights (1 and 2) are switched on 01
• Group 2: lights 3 & 4; controlled by Y
• Group 3: Light 5; controlled by X all off grp 1 on

•In this example, we associate each state with an output 00 0


1
• Depending on the current state, we switch on specific groups of lights
0
10
0,1
all on grp 1,2 on
11 1

10
Traffic Sign Truth Tables
• When is group 1 on?
• in states 01, 10 and 11 - but only when the switch IN is on!
Outputs Next State: S1’S0’
(depend only on state: S1S0) (depend on state and input)
• Logic expressions for X,Y,Z
Lights 1 and 2 Switch
• Depends on S0 and S1 and Input is on
 If Input is off then X,Y,Z are al 0
Lights 3 and 4 In S1 S 0 S 1’ S 0’
Light 5
• can you come up with a logic expression for next state values 0 X X 0 0
of S0 and S1? S1 S0 Z Y X 1 0 0 0 1
• Depends on current values of S0 and S1 and Input is on 1 0 1 1 0
 Input off then both bits are set to 0 since next state is 00
0 0 0 0 0
• Next state value of S0 denoted S’0 = 1 if current state is 00 or current 0 1 1 0 0 1 1 0 1 1
state 10 and In=1 1 1 1 0 0
1 0 1 1 0
• When do we switch to the next state? 1 1 1 1 1
Whenever In=0, next state is 00.
• the two bits of S[1:0] are updated at every clock cycle
• we have to make sure that the new state does not propagate to the
combinational circuit input until the next clock cycle.

Boolean functions for light control bits Traffic Sign Logic


• from truth table, consider all rows where outputs =1

• Z = ((NOT S1)S0 + S1 (NOT S0 ) + S1S0 ).In

•Y = (S1S0 + S1 (NOT S0 ) ).In

•X = (S1S0 ).In

D
flipflop

11
Summary of Digital Logic The Agenda
•Combinational logic
• Basic gates •Take the elements that we have encountered so far
• Combinational devices • Combinational Elements
Gates, Adders, Muxes, decoders
•Sequential logic • Storage Elements
• Storage element…Flip flop Flip flops, registers, memories
• Theory behind design of finite state machines
They act like controllers of a circuit •And use them to build a circuit that can perform a sequence of
•Sequential logic devices arithmetic operations.
• Memory, ROM, RAM, Registers • In essence, we will build a very simple CPU

So, what is the purpose of all this ?.........

12

You might also like