CH 05
CH 05
Sequential Circuits
Various definitions
Combinational circuits with feedback
Combinational circuits with memory
Combinational circuits with state
whatever...
Synchronous...
If there are synchronous circuits, there must
be asynchronous as well.
We (and everybody else) deal mostly with
synchronous.
Synchronous circuits have a clock (it can
take a few different forms)
Asynchronous circuits
Depend on time delay devices for storage
Can exhibit instabilities (due to effects like
racing conditions)
Hard to design
Used mainly for special subcomponents
Latches
The simplest kind of memory
They are primitive flip-flops
Flip-flops can contain one or more latches
usually more
S-R Flip-Flop
S-R stands for Set-Reset
Just two NOR gates
could use NAND as well
Using NAND
Everything is just the opposite
Set and Reset are active low
The illegal input is 0-0
Is it perfect?
It has an indeterminate next state
What if the feedback propagates more than
once
This could lead to more indeterminacies
It would require a very short clock pulse.
D Flip-Flop
The D flip-flop has one input
The D stands for Data or Delay
With one input it is hard to have an illegal
input
Graphic Symbols
Flip-flops are drawn as rectangles
The standard names (S, R, D, J, K, etc) are
drawn inside.
If it follows negative logic then the input has
a negation circle.
Master-Slave D flip-flop
Use two D flip-flops with control input
The output of the first is the input to the
second
The first is the master
The second is the slave
Master-Slave Operation
When the CLK is low the slave copies the
state of the master
When the clock is high the state of the
master is copied from its input
The input cannot propagate more than one
stage per clock transition.
Master-Slave Alternatives
Master-Slave is not the only known solution.
A less expensive version would need three
bare latches
Operation
When the CLK is 0 the input to the SR
output latch is 1-1, and the output is
maintained.
When the CLK goes 1, the S of the output
latch becomes equal to D and R becomes
equal to D
If D changes while CLK is high, the SR are
not affected
Timing
In real-life circuits nothing is instantaneous
The input D has to stabilize for a short time
before the clock transition
this is called setup time
Graphic Symbol
The clock of a positive edge triggered F-F is
indicated by a small arrowhead and the letter
C (sometimes CLK)
The little arrowhead is called dynamic
indicator.
A small circle (bubble... whatever)
designates a negative edge triggered F-F
Other Flip-Flops
The least expensive F-F is the edge triggered
D F-F (if you count VLSI real estate)
It needs the fewest gates to implement.
Often it needs the smallest total number of
gates (gates inside the F-F and external
logic)
Other Flip-Flops
Other F-Fs can be built using D F-Fs
There are three desired operations on a F-F
Set (to 1)
Reset (to 0)
Toggle
J-K Flip-Flop
Can do all desired operations
Usually needs the smallest number of
external gates (its excitation table has many
dont cares)
Often the best when using MSI technologies
Less impressive in VLSI implementations
Like SR but without illegal inputs
J-K Flip-Flop
D = J Q + K Q
The F-F is set when JK = 10
The F-F is reset when JK = 01
Nothing changes if JK = 0
The F-F toggles if JK = 11
That would be indeterminable for SR latches
T Flip-Flop
T stands for trigger or toggle
Was popular in the era of discrete transistors
could be implemented with two transistors and
several resistors and capacitors.
T Flip-Flop
D = TQ + TQ
The F-F toggles if the input T=1
Nothing happens if T=0
Characteristic Tables
The truth tables of F-F
Give us the next state of the F-F given the
input and current state
Can be expressed in various equivalent
forms
JK
Q(t+1)
00
01
10
11
Q(t)
0
1
Q (t)
No change
Reset
Set
Toggle
D Q(t+1)
Q(t+1)
0 0
1 1
0
1
1
0
Characteristic Equations
Same info as tables, but in algebraic form
The D F-F
Q(t+1) = D
The T F-F
Q(t+1)= TQ + TQ
Direct Inputs
Need to preset a F-F during startup.
also when we have a general reset
State Equations
Every combination of the flip-flop values is
called state
The state changes after every clock pulse
State equations are the equations that give us
the next state as a function of the current
state and the input
State Equations
The state equations are also called transition
equations
We derive the state equations from the
circuit schematic
Example
We analyze a simple circuit with two F-F
named A and B, one input x and an output y
We derive the state equations first
The Equations
These can be written as
A(t+1) = A(t)x(t) + B(t)x(t)
B(t+1) = A(t)x(t)
State Table
The state table presents the same
information in tabular form
Also called transition table
Also bundled with the output data
State Table
Present
state
Input
Next
State
Output
AB
AB
00
00
01
01
10
10
11
11
0
1
0
1
0
1
0
1
00
01
00
11
00
10
00
10
0
0
1
0
1
0
1
0
Next State
Output
x=0
x=1
x=0
x=1
AB
AB
AB
00
01
10
11
00
00
00
00
01
11
10
10
0
1
1
1
0
0
0
0
State Diagram
We see the circuit more like something that
changes states, than a collection of F-F and
gates
It is really a Finite State Machine (FSM)
So can be represented by a State Diagram
(you know, the thingy with the bubbles and
the arrows between them...)
State Diagram
The bubbles represent the states and are
labeled (usually) with the binary number of
the state
The edges are the transitions and are labeled
with the input that cause the transition
We indicate the output after the slash
Similarly
D_B = A x
State Equations
A(t+1) = A xor x xor y
The Steps
Determine the F-F input Equations
List the binary values for each input equation
and state
Use the char. tables to determine the next
state
State Table V1
Present
State
Input
Next
State
F-F Inputs
AB
JA KA JB KB
00
00
01
01
10
10
11
11
0
1
0
1
0
1
0
1
0
0
1
1
0
0
1
1
0
0
1
0
0
0
1
0
1
0
1
0
1
0
1
0
0
1
0
1
1
0
1
0
State Table V2
Present
State
Input
Next
State
F-F Inputs
AB
AB
JA KA JB KB
00
00
01
01
10
10
11
11
0
1
0
1
0
1
0
1
01
00
11
10
11
10
00
11
0
0
1
1
0
0
1
1
0
0
1
0
0
0
1
0
1
0
1
0
1
0
1
0
0
1
0
1
1
0
1
0
Alternatively...
We can use the characteristic equation
A(t+1) = J_a A + K_a A
B(t+1) = J_b B + K_b B
Matter of taste
State Table
Present
State
Next
State
FF input
A
B
Input
AB
AB
JK JK
00
00
01
01
10
10
11
11
0
1
0
1
0
1
0
1
01
00
11
10
11
10
00
11
00
00
11
10
00
00
11
10
10
01
10
01
11
00
11
00
Structural Description
By describing the interconnection between gates
and FFs
Edge triggered
triggered by positive only or negative only
events
useful in sequential circuits
Of course!
There are two kinds of edge-triggered events
keyword negedge
keyword posedge
Procedural Assignments
These are gated and happen only when
always blocks are executed
Different from the dataflow assignment,
which is continuous
The lhs has to be of type reg.
And guess what...
Non-Blocking
The next statement sees the old value of the lhs
of the previous statement
Example: Blocking
Consider the following blocking procedural
assignments, where A is initially 3 and B is
initially 1
B=A
C=B+1
Example: non-Blocking
If the assignment is non-blocking
B <= A
C <= B + 1
D Latch
The D latch has two inputs
the D input
and the control input
D Flip-Flop
Slightly more complex
It is triggered by the clock edge
If the input D changes the state or output of
the FF does not change before the clock edge
D FF with RESET
We now have two asynchronous inputs
The RESET is active low
Observation
In the if statement the then clause is
asynchronous logic
Same for else if, if there was any.
The last else statement is synchronous logic
Observation
In the sensitivity list we have posedge CLK
and negedge RST
As long as RST is 0, the FF is reset, despite
the fact that we trigger with negedge
The CLK is effective only during the
positive edge, and the only when RST=1
T Flip-Flop
The characteristic equation is
Q(t+1) = Q xor T
J-K Flip-Flop
The characteristic equation is
Q(t+1) = JQ + JK
We use again a D FF
State Diagrams
Verilog (and other HDLs) can immitate state
diagrams
There are two basic variations: Mealy and
Moore
Makes life easier to use keyword parameter.
Example: Mealy
Mealy is the one with the outputs on the
edges
The structure of the HDL program reflects
the H/W:
one always for the sequential circuit
one always for the next state calculation
one always for the output
Example: Moore
Moore is the one with the outputs inside the
state bubble (or implied)
The HDL reflects again the (slightly) simpler
H/W
Here we combine the always.
Moore in HDL
moduleMoore_mdl(x,AB,CLK,RST);
inputx,CLK,RST;
output[1:0]AB;
reg[1:0]state;
parameterS0=2'b00,S1=2'b01,S2=2'b10,S3=2'b11;
always@(posedgeCLKornegedgeRST)
if(~RST)state=S0;//InitializetostateS0
else
case(state)
S0:if(~x)state=S1;
S1:if(x)state=S2;elsestate=S3;
S2:if(~x)state=S3;
S3:if(~x)state=S0;
endcase
assignAB=state;//Outputofflipflops
endmodule
State Reduction
Often a sequential circuit with fewer states
can do exactly the same job
There are multiple benefits from reducing
the number of states
State tables (or diagrams) generated by
software tend to have redundant states.
The Benefits
Fewer flip-flops
More unused states, thus more dont cares
Definition
Two FSM are equivalent when for all input
sequences they produce the same output
Unfortunately all is too many
We have to find a more workable definition
How About...
Define the equivalence of states. If we find
that two states are equivalent we merge them
Two states in an FSM are equivalent if for
every input produce the same output and
jump to the same state or to equivalent states.
Sounds better
This is a workable definition
We can use it to simplify state diagrams by
hand
We can use it to design an algorithm.
Example
In the next FSM we observe that states g and
e are equivalent
with input 1 they go to f and produce 1
with input 0 they go to a and produce 0
Some More...
So e and g is one state with two different
names.
But now f and d are equivalent
with input 0 they go to {e,g} and produce 0
with input 1 they go to f and produce 1
The Algorithm
Initial step:
For every state fill in the truth table that relates
inputs to outputs
Place all the states in groups such that all states
in the same group have identical truth tables
Iteration
Repeatedly select a group of states i
if the states within i jump to different groups,
split i into several groups
Inp
0
1
0
1
0
1
0
1
0
1
0
1
0
1
Out
0
0
0
0
0
0
0
1
0
1
0
1
0
1
Next
a
b
c
d
a
d
e
f
a
f
g
f
a
f
Groupings
abc
defg
bc
bc
defg
df
eg
df
eg
State Assignment
With N states there are at least N! possible
state assignments
Some of them are better than others
There is little algorithmic help to find the
optimal state assignment
Number of F-F
A circuit always has a power of two number
of states, although the FSM requires fewer
We end up with unused states
This is good: lots of dont cares!
Sometimes it is worth having extra F-F just
for the dont cares.
In the Extreme
We can even have one F-F per state (aka one
hot)
This often saves enough gates to justify the
real estate taken up by the extra F-F
Design Procedure
Now we are ready to design a circuit
Design consists of
translating words to symbols, tables, HDL...
specifying the logic
optimizing the design for cost and or
performance
communicating the results
Detailed Steps
Produce a state diagram
Minimize it
Assign binary values to states
Choose the technology
Obtain state table (binary coded)
Minimize FF input equations
...Detailed Steps
Draw logic diagram (or equivalent)
Calculate costs
Do it again until you nauseate (or have
reduced the cost enough)
Word Specification
Comes from the system architect
Might or might not be exact, unambiguous
There is some help from various design aids
Needs experience
Example
Design a module that detects three or more
consecutive 1s.
This module should have 4 states
One state for zero 1s
One for one 1
One for two 1s
One for three or more 1s
State Table
Present
Input
Next
Output
AB
AB
00
00
01
01
10
10
11
11
0
1
0
1
0
1
0
1
00
01
00
10
00
11
00
11
0
0
0
0
0
0
1
1
Using D F-F
Using D F-F the next state is the same as the
F-F input
A(t+1) = Sum(3,5,7)
B(t+1) = Sum(1,5,7)
y = Sum(6,7)
Q(t+1)
JK
Q(t)
Q(t+1)
0
0
1
1
0
1
0
1
0X
1X
X1
X0
0
0
1
1
0
1
0
1
0
1
1
0
Input
Next
AB
AB
00
00
01
01
10
10
11
11
0
1
0
1
0
1
0
1
00
01
10
01
10
11
11
00
F-F Inputs
Input
Next
F-F Inputs
AB
AB
JK
JK
00
00
01
01
10
10
11
11
0
1
0
1
0
1
0
1
00
01
10
01
10
11
11
00
0X
0X
1X
0X
X0
X0
X0
X1
0X
1X
X1
X0
0X
1X
X0
X1
Next
A2 A1 A0
A2 A1 A0
0
0
0
0
1
1
1
1
0
0
0
1
1
1
1
0
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
Flip-Flop Inputs
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
Present
Next
Flip-Flop Inputs
A2 A1 A0
A2 A1 A0
T1 T2 T3
0
0
0
0
1
1
1
1
0
0
0
1
1
1
1
0
0
0
0
1
0
0
0
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
0
1
0
1
0
1
0
1
1
1
1
1
1
1
1
1