Академический Документы
Профессиональный Документы
Культура Документы
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)
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
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
4
FSM Representation of 3-bit Counter Storage
Reset •Each D flip flop stores one state bit.
100
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
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
•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
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.
•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
12