03a Section3 Notes CPD SDDS1 FSM
03a Section3 Notes CPD SDDS1 FSM
===================
2021 Sept Dec
===================
..
..
===================
Finite State Machines 1 (FSM1)
===================
Richard Gahan
richard.gahan@tudublin.ie
Contents
Section 1
A nite state machine is an abstract model of a machine with a primitive internal mem-
ory 1 .
Many dierent styles are used to document the behaviour of FSMs in fact nearly every
company has their own method! But clarity is a necessity of all of them. We shall look at
a two dierent documentation styles:
Flowcharts.
Bubble Arrow diagrams.
We shall use owcharts to depict FSMs as it is simpler to use and is less error prone.
1
https://en.wikipedia.org/wiki/Finite-state_machine
This diagram shows that there are state ip-ops whose output is fed back and combined
with the inputs to generate the next state of the ip-ops. In this way the FSM can
remember what has occurred previously and transition to a new state based on current
state and input values.
The outputs can be generated from a combination of input signals, the current state and
output logic and sequential elements.
The Mealy machine is distinguished by its outputs being generated from its current state
and its inputs.
2. Combinations of the inputs and the current state of the FSM (Mealy outputs) or
3. Registering2 a Mealy or Moore generated signal and using that as an output signal.
2
i.e. Putting it through a ip-op
Flowcharts use 3 basic elements to describe the behaviour of FSMs. These are
1. State Descriptors usually shown as rectangular boxes. They show the STATE of
the FSM.
2. Decision diamonds. These show the questions asked and decisions made in moving
from one state to the next.
3. Output generation bubbles. These show the outputs generated and when and how
they occur.
A state Descriptor looks like a rectangular box with the name of the state written inside.
The name of the state should be meaningful to what the state represents. In a digital
system the state is implemented by assigning a unique value for the state to the state
ip-ops. This is called State Assignment.
The state assignment value represents the state of the FSM and in this case the state
called StateName is represented by the two ip-ops having values Q1=1 and Q0=0.
A decision diamond looks like a diamond with an input line (on top) and two output lines
(both sides).
In this example the signal attn(H) is being evaluated. If it is a 1 the left option is taken,
else the right option. The arrow into the diamond shows where the ow has come from.
The (H) sux means that the signal is asserted high. This means that when attn is "on"
it is high. Dierent norms may be used to confer this meaning. attn(H) or attH or just
attn where the default is that a signal is asserted high. If attn is asserted low then it is
written as attn(L) or attnL where the capital L indicates asserted low.
An output generation bubble looks like a rectangle with rounded corners. The output can
be generated from the state and inputs using combinational logic © or the output is
registered i.e. from a ip-op ®. All outputs must have either © or ® preceding them.
Note:
A registered output will assert on the next clock tick after the assignment is made
in the FSM owchart
A combinational output will occur on the current clock tick in which the assignment
is made on the owchart.
The rst output here shows the combinational signal out1(H) being assigned the value 1.
The second output shows the registered signal out2(H) being assigned the value 1.
With these basic elements complex Finite State Machines may be drawn and implemented.
See Figure 1.7.
Let the outputs be called CNT[1:0] and they should be glitchless. The circuit has a resetH
input which when asserted asynchronously resets the digital circuit to a known initial
state
Draw a nite state machine which implements this digital system. From the FSM draw
out the logic for the solution using D-type ip ops and combinational logic elements only.
Do not minimize any of the logic.
A block diagram is shown below.
Solution
Since we have only a 2 bit counter we have only 4 states. In this case then we only
need two bits to represent the 4 states AND the state ip ops can be used as the output
CNT[1:0]. We let the two ip ops be called Q1 and Q0. We can let Q1 represent CNT[1]
and Q0 represent CNT[0]
We can draw a owchart of the solution as follows
State0 We assume for now that the FSM is put into this initial state due to the assertion
of the resetH signal. This is not shown explicitly in the FSM owchart here. We needed
4 states to solve the problem. This means that 2 ip ops are needed since 2 ip ops
can have 4 states i.e. Q0,Q1 = 00 or 01 or 10 or 11.
In order to design the logic to implement this ow chart we must assign values to the ip
ops. The values assigned are given above since the counter must count in the specied
sequence. Then we can read from the owchart3 the conditions under which the D of each
Flip Flop must be a 1 so that on the next rising edge the Q is a 1.
3. Taking state1 rst. Identify all paths that transition into state1. There is only one
path i.e. from state0.
4. Write an equation that species each path into state1, i.e. write a logic equation
which determines when the D of the Q0 ip op should be a 1 such that on the next
rising edge the Q0 value will be a 1.
5. Looking at path1 when the current state is state0 then the next state is state1 and
Q0 must be a 1 in state state1. Thus when in state state0 the D of the Q0 ip op
must assert (i.e. be a 1) so that on the next rising edge Q0 is a 1 and thus . . .
6. path1 => DQ0 must be assigned a 1 when the FSM is in state0 i.e. when Q1=0
and Q0=0 i.e. DQ0 = !Q1 . !Q0 where ! Means NOT.
7. Taking state3. Identify all paths that transition into state3. There is only one path
i.e. from state2.
8. Write an equation that species each path into state3, i.e. write a logic equation
which determines when the D of the Q0 ip op should be a 1 such that on the next
rising edge the Q0 value will be a 1.
9. Looking at path2 when the current state is state2 then the next state is state3 and
Q0 must be a 1 in state state3. Thus when in state state2 the D of the Q0 ip op
must assert (i.e. be a 1) so that on the next rising edge Q0 is a 1 and thus
10. path2 => DQ0 must be assigned a 1 when the FSM is in state2 i.e. when Q1=1
and Q0=0 i.e. DQ0 = Q1 . !Q0 where ! Means NOT.
3
Also called IFDs i.e. Information Flow Diagrams
This does not take account of the reset function yet. The question states that the circuit
should be reset asynchronously i.e. the two ip-ops must be forced to 00 regardless of
the existence of the clock signal. Thus we must use ip-ops with an asynchronous reset
function on them.
Draw a timing diagram to convince yourselves that the circuit does indeed implement the
2 bit up counter.
tick0 tick1 tick2 tick3 tick4 tick5 tick6 tick7 tick8 tick9
Clock
rxSerD
out1H
out2H
Figure 1.13: Timing Diagram1
Draw a nite state machine which implements this digital system. From the FSM draw
out the logic for the solution using D-type ip ops and combinational logic elements only.
Do not minimize any of the logic.
1. We assume for now that the FSM is put into the INIT state due to the assertion of
the resetH signal. This is not shown explicitly in the FSM owchart here.
2. When in state INIT test the value on the input signal rxSerD and if it is a 0 then
transition to state SN0 else stay in state INIT.
3. State SN0(Seen 0) i.e. this is the rst 0 of the sequence 0110. State SN0 remembers
that we have seen the rst 0 of the 0110 sequence. This is the purpose of state SN0.
4. When in state SN0 test the value on the input signal rxSerD and if it is a 1 then
transition to state SN01 else stay in state SN0 this is still the rst 0 of the 00110
sequence.
5. When in state SN01 test the value on the input signal rxSerD and if it is a 1
then transition to state SN011 else go to state SN0 this is still the rst 0 of the
010110 sequence.
6. When in state SN011 test the value on the input signal rxSerD and if it is a 0
then transition to state SN0 and assert the outputs out1H and out2H for 1 tick each.
Else If rxSerD is a 1 go back to the INIT state and do not assert the output.
We transition to the S0 state from SN011 if rxSerD is a 0 since we now have detected
0110 and the last 0 could be the shared 0 of a new sequence i.e. we could be about
to detect the sequence 0110110.
State Assignment
In order to design the logic to implement this ow chart we must assign values of the
ip-ops to the states above.
If we let the state assignment be as follows(where Q1 and Q0 are state ip ops):
State Q1,Q0
INIT 00
SN0 01
SN01 10
SN011 11
3. Taking the SN0 state rst. Identify all paths that transition into state SN0 (and
don't forget that sn0 can transition back to itself!!). These are labeled as path1,
path2, path3 and path4 in the diagram.
4. Write an equation that species each path into SN0, i.e. write a logic equation which
determines when the D0 pin of the Q0 ip op should be a 1 such that on the next
rising edge the Q0 value will be a 1.
5. Consider path1 when the current state is INIT and rxSerD is a 0 then the next
state is SN0 and Q0 must be a 1 in state SN0. Thus when in state INIT and when
rxSerD is a 0 the D of the Q0 ip op must assert (i.e. be a 1) so that on the next
rising edge Q0 is a 1 and thus
10. These 4 conditions force the Q0 ip op to a 1 for transitions to state SN0. These
must be or'ed together for the full equation for DQ0 since these are independent
conditions. Thus:
12. But remember these are only for Q0 in state SN0. We must also force Q0 to a 1
when in state SN011. This is shown as path5 in the ow chart.
State Decode
Each state must be decoded to produce a signal which asserts when the FSM is in that
state. In state INIT the initH signal is asserted. Similarly for the other state decode
signals.
mminitH=Q1H.Q0H = Q1L.Q0L
mmsn0H=Q1H.Q0H = Q1L.Q0H
msn01H=Q1H.Q0H = Q1H.Q0L
sn011H=Q1H.Q0H = Q1H.Q0H
mm
Logic Schematic
The logic to implement the outputs is derived directly from the FSM.
out1H = sn011H.rxSerD
out2H = has the same conditions as out1H but put through a ip-op.
Can you derive the next state logic for the Q1 Flip-Flop.
The FSM in gure 1.7 has 4 states and this requires a minimum of 2 ip-ops to enumerate.
The state assignment has been given as
State Q1,Q0
Init 00
Sn0 01
Sn01 10
Sn011 11
The FSM in gure 1.7 has 4 states and a one-hot state assignment assigns a ip op for
every state of the FSM. One and only one of the ip ops are on for each state.
A one-hot state assignment for the above FSM might be given as:
State Q3,Q2,Q1,Q0
Init 0001
Sn0 0010
Sn01 0100
Sn011 1000
State Q1,Q0
Init 00
Sn0 01
Sn01 11
Sn011 10
This is clearly a dierent assignment to a binary state assignment. This is grey code
where only one bit changes at a time as states transition to other states.
Grey Code state assignment has some advantages under rather special circumstances. We
shall look at the special circumstances later.
Look closely at the FSM in gure 1.11 and the state to state transitions. Is there always
only one bit transitioning in all cases if the state assignment is as given in table 1.4.
We wish to design a synchronous digital circuit which monitors this two bit input bus and
if the value on the din[1:0] signal is 10101 an output pulse of exactly one tick duration
should be generated. Let the output be called out1H and it should be glitchless (i.e. it
must not have any hazards on it!). The circuit has a resetL input which when asserted
asynchronously resets the digital circuit to a known initial state.
We wish to draw a nite state machine which implements this digital system and from
the FSM to draw out the logic for the solution using D-type ip ops and combinational
logic elements only. The logic schematic is not to be minimised.
The next step is to do the state assignment i.e. assign values to the state ip-ops for
each state. Since there are 5 states in this system we could use 3 ip-ops and assign a
binary code to the ip-ops.
Since 3 ip ops are needed as a minimum we can have 8 states i.e.
We could use more than three ip ops but we can say that at least 3 are necessary.
A binary code state assignment is not always necessary or indeed the best choice any
state assignment we care to make is acceptable. For example we can have 5 ip-ops to
hold the state.
We could call them Q4,Q3,Q2,Q1,Q0. We can let the state assignment be as follows:
State Q4 Q3 Q2 Q1 Q0
Init 00001
Sn1 00010
Sn10 00100
Sn101 01000
Sn1010 10000
To design the logic for the Q0 Flip-Flop we must identify all paths that lead to Q0 being
a 1 i.e. all paths into the INIT state. These are identied in gure 1.18 . Five dierent
paths have been identied.
From this we can write an equation for DQ0 i.e. the D pin of the Q0 ip-op i.e. Path1
path2 path3 path4 path5
Since we know that only Q0H will ever assert in state INIT, only Q1H will ever assert in
SN1 etc. We can group terms to get
DQ0 = (Q0 + Q1 + Q3 + Q2 + Q4).!DIN[0].!DIN[1]
The logic schematic for DQ0 and Q0 is as follows: Notice that resetL is tied to the !PR
pin of the ipop.
Can you complete the logic derivation for this design i.e. Q1, Q2, Q3, Q4 and output
out1?
1.7 TestQuestions
1.7.1 TestQuestion1 3 bit Counter
Design an FSM to implement a three bit counter which generates the count sequence
000->010->101->011->111
The three bit counter outputs are called cnt[2:0]. When the count value is 111 the counter
should assert a terminal count signal call tcH which asserts high during that state.
1. Design and draw the FSM. Assign state Flip-Flops and values to each state.
3. Then draw a timing diagram showing the FSM going through all its states and
generating all outputs. Check that the logic you have derived works correctly with
respect to the timing diagram.
3. There are always exactly 8 data bits between the valid start and stop bits.
There are many ways to design this simple UART. Each designer will solve this in slightly
dierent ways.
1. Generates an output pulse called outA as a 1 if the sequences 1011 or 0010 are
detected on the serial input signal called xIn on four successive clock edges.
2. The output signal outA must be guaranteed never to glitch i.e. to have either
dynamic or static hazards.
A timing diagram in Figure 1.22 shows expected behavior for an example input sequence:
The FSM must be drawn neatly and clearly with all signals named.
1. The rst 6 bytes of the frame contains the destination address DA[47:0]
2. The next 6 bytes of the frame are the source address SA[47:0]
3. The next two bytes are the Length/Type of the frame.
If byte 13 is 0x81 and byte 14 is 0x00 then the VLAN ID or VID is contained in the
following two bytes otherwise this frame does not contain a VID.
4. For the Tag Extract Digital Block as shown in Figure 1.23 also.
sof(H) asserts for one clock tick only when the rst byte of the frame is presented
on rx[7:0]. Subsequent bytes come on every subsequent clock tick without gaps.
There are at least 64 bytes in every frame.
5. The signal tagDetectH asserts for one clock tick when vid[11:0] has a valid value.
6. All output signals should be registered.
The FSM must be drawn neatly and clearly with all signals named.
4
Steps Through
1. Design an FSM and associated logic to implement the CongRegWriter block. The
design extracts the 4 bit address and the 4 bits of data from the serial wire and
asserts a signal called wrRegH for 1 clock tick when they are updated so that the
appropriate register in the register bank can be written. The 4 bit address is put
onto serAdr[3:0] and the 4 bits of data is put onto serDat[3:0].
2. Design the logic for your FSM. Assign a binary code to the states of any FSM in
your design. Implement an asynchronous reset when a signal called resetH asserts
to reset all ip-ops in the system.
3. Draw a timing diagram showing all the signals in the context diagram and any FSM
states in your design. On the timing diagram show address 316 written with data
B16 .
1. This system has a start bit, 8 data bits and 2 stop bits.
2. The byte to be transmitted is copied into the transmitter block on cycle1 because
the block is empty/free but the 2nd byte oered on cycle3 is not copied immediately
because the block is busy sending out the rst byte.
Your design should determine when is a good time to copy byte i.e. when will the
second byteCopied signal assert in your design?