Sie sind auf Seite 1von 42

State Machines

In this topic we will be covering

• Sequential circuits, state and clock


• State-transition diagrams
• State tables
• Creating a state machine: An example
• State machines in AHDL
State Machines
Sequential circuits, state and clock

Any digital circuit with memory in the form of latches


and flip-flops that is used in a feedback implementation
is a sequential circuit.
The output at the next clock transition is a function of
the present output condition.
So, to predict the future output, one only has to know the
present output and the combinational logic employed.
State Machines

Sequential circuit
State Machines
State transition diagram

In a general synchronous sequential circuit, the arrival of


each clock pulse causes the circuit to change from its
present state to a new state.
The state of the circuit is the combination of all the
individual states of the components within it.
If a circuit has n flip-flops then it can have a maximum
of 2n different states.
State Machines
State transition diagram

In a ring counter, each state of the counter comprises the


individual states of the D-type flip-flops in it.
We represent the transition of the circuit from one state
to the next by drawing its state-transition diagram.
In such a diagram, a circle represents a state and, within
this circle, we write the value of the output of that state.
The transition from one state to the next is represented
by an arrow.
State Machines
State transition diagram

The lower-case letters in the a,0001 b,0010

circles represent the different


states in the sequence.
e,0001

The central circle represents


the initial input to the system d,1000 c,0100
that will give rise to the
sequence of outputs State-transition diagram of a ring counter

The arrow indicates the change of state


at the input of the next clock pulse.
State Machines
State transition diagram
A number next to the arrow will show under what input condition
the machine will change to a particular state.

To see this clearly, consider a clocked JK flip-flop with a truth


table that may be written as follows:

Qn+1 represents
Qn represents the the next state
current state (output)
(output)
State Machines
State transition diagram
A number next to the arrow will show under what input condition
the machine will change to a particular state.

10,11

00 a, Q = 0 b, Q = 1 00
01 10

01,11

Truth table for a flip-flop State-transition diagram for a JK flip-flop


State Machines
State transition diagram
When the initial and the final states are the same, the transition
path is called a sling.

A sling starts from a circle (state) and returns to the same circle
(state).

The slings for the JK flip-


flops are shown as small
incomplete loops
State Machines
State transition diagram – An example
Draw the state-transition diagram for a synchronous sequential
circuit with three states a, b and c, which satisfies the following
conditions:

(a) state a changes to state b when the input is 1, or to state c


when the input is 0;
(b) state b changes to state c if the input is 0, or to state a if the
input is 1;
(c) state c changes to state a regardless of the input;
(d) the binary output is 0 except in state c.
State Machines
State transition diagram – An example

1
a, 0 b, 0
1
- 0
0

c, 1

State-transition diagram
State Machines
State tables
In order to realise a sequential machine from a state-
transition diagram, a state table must be generated.
Such a table shows the present state, the state required at
the next clock pulse, and the transitions required at the flip-
flops for the change.
State Machines
State tables
For JK flip-flops the input conditions required for any
transition are:
Using don’t care conditions we
can simplify the table to:
State Machines
State tables

As an exercise, check the validity of this table. For example:

QN = 0, J = 0 and K = 1, QN+1 = 0; and


QN = 0, J = 0 and K = 0, QN+1 = 0
State Machines
State tables – An example
Design a MOD 5 counter using JK flop-flops.

Step 1: The state-transition diagram


In this example the diagram is trivial.
State Machines
State tables – An example
Step 2: Determine the number of flip-flops required
For any MOD number between 4 and 7, three flop-flops are
required. The inputs required by the flip-flops for any
transition are given in the previous table.
State Machines
State tables – An example
Step 3: Create the state table
This is the table for the MOD 5 counter.
State Machines
State tables – An example
Step 3: Create the state table
Once more, as an exercise, check the validity of this table.
For example, on the first clock pulse, Q2 is to remain at 0,
hence J2 should be 0 and K2 is a don’t care. Similarly, Q0
should change from 0 to 1, requiring J0 = 1, and K0 is a don’t
care.
State Machines
State tables – An example
Step 4: From the state table, draw K-maps to simplify the flip-flop
inputs
First lets look at input J2 .
State Machines
State tables – An example
Step 4: From the state table, draw K-maps to simplify the flip-flop
inputs
Considering the current state when does the input J2 need to
be 1 to implement our desired sequence?

3-input K-map

From which J2 = Q0.Q1


State Machines
State tables – An example
Step 4: From the state table, draw K-maps to simplify the flip-flop
inputs

From which K2 = 1

From which J1 = Q0
State Machines
State tables – An example
Step 4: From the state table, draw K-maps to simplify the flip-flop
inputs

From which K1 = Q0

From which J0 = Q2
State Machines
State tables – An example
Step 4: From the state table, draw K-maps to simplify the flip-flop
inputs

From which K0 = 1
State Machines
State tables – An example
Step 5: Sketch the circuit
State Machines
Creating a state machine: An example

Sequence required: 0, 2, 13, 4, 0

Use JK flip-flops

Largest number is 13 which, in binary, is 1101.

As 4 bits are required, 4 flip-flops will also be required.

We will begin by drawing the flip-flops.


State Machines
Creating a state machine: An example

We will begin by drawing the flip-flops.

Clock
State Machines
Creating a state machine: An example

Next we list all possible states, and the


states that follow them.

Note that we have assumed that the


initial state is 0000.

If the initial state is unknown then all


states not in the sequence must point to
a state in the sequence. In the above
case, all the don’t care conditions (X)
would be changed to zeros (0).
State Machines
Creating a state machine: An example

Next let’s look at the JK transition (or excitation) table.

Thus we see that for a JKFF if Q is 0 and we want it to change to a


1 then the J input must be set to 1 and the K input can be anything
(don’t care).

Let’s add this to the state–next table…..


State Machines
Creating a state machine: An example

Looking at the first row the state of A is 0 and the next state of A is
0. Therefore, from the transition table we see that Ja must be 0 and
Ka must be X. The state of C is 0 and the next state of C is 1.
Therefore, from the transition table we see that Jc must be 1 and
Kc must be X.
When the next state is XXXX all J and K inputs can also be X
because we don’t care what happens here.
State Machines
State Machines
Creating a state machine: An example
Next a Karnaugh map must be done for each J and K input using
the current state as the inputs.

Thus for input Ja we have:


State Machines
Creating a state machine: An example
Doing Karnaugh maps for all the other inputs and we get

Now we can draw the rest of the schematic.

Clock
State Machines
Creating a state machine: An example
We have created the state machine with JK flip flops, can we
achieve the same outcome using D-flip flops?

Yes

First lets draw them up

Clock
State Machines
Creating a state machine: An example
Let’s draw the state-next table again.
State Machines
Creating a state machine: An example
Now draw a Karnaugh map for each column of the next state using
the current state as the inputs.
So for Da (first column of Next State) we get the following:
State Machines
Creating a state machine: An example
Doing Karnaugh maps for all D inputs we get the following:

Drawing the new schematic we get:

Clock
State Machines
State machines in AHDL
Here is where we see some of the simplicity of AHDL
over VHDL. In AHDL we need do nothing more than
enter the table showing the current state and the next
state.
State Machines
State machines in AHDL
SUBDESIGN statemachine
(
clk : INPUT;
reset : INPUT;
z[3..0] : OUTPUT;
)
VARIABLE
% current current %
% state output %
ss: MACHINE OF BITS (z[3..0])
WITH STATES ( s0 = 0,
s1 = 2,
s2 = 13,
s3 = 4);
State Machines
State machines in AHDL
BEGIN
ss.clk = clk;
ss.reset = reset;
TABLE
% current next %
% state state %
ss => ss;
s0 => s1;
s1 => s2;
s2 => s3;
s3 => s0;
END TABLE;
END;
State Machines
State machines in AHDL
This describes the state machine in the previous example.
The state machine itself is declared as a buried variable.
We have called it ss.
It uses 4 bits, (z[3..0]) and it has the states 0, 2, 13 and 4
which have been labelled s0, s1, s2 and s3.
In the logic section we first connect the clock signal to
the state machines clock and then the reset signal to the
state machines reset.
State Machines
State machines in AHDL
Finally, we use the truth table statement to list the current
and next states.
The first line of the TABLE statement, (not including the
comments), says that the current state and the next state
are from ss, the state machine.
The next few lines list the current state of the state
machine and the next state for the state machine.
State machines
In this topic we will be covering

• Sequential circuits, state and clock


• State-transition diagrams
• State tables
• Creating a state machine: An example
• State machines in AHDL

Das könnte Ihnen auch gefallen