Download presentation
Presentation is loading. Please wait.
1
Sequential System Synthesis -- Finite State Machine
2
ENEE 6442 Outline: Finite State Machine > Definitions > FSM Representations =State Transition Graph (STG) =Flow Table =Cube Table > State Minimization =Completely Specified FSM =Incompletely Specified Machine (ISM) > State Encoding
3
ENEE 6443 Definition: Finite State Machine > A Finite State Machine (FSM) of Mealy type is a 6 tuple > A Finite State Machine (FSM) of Mealy type is a 6 tuple =I: input alphabet, a non-empty set of input values; =S: a non-empty, finite set of states; = : SxI S, a function defines the next state; =S 0 : S, the set of initial/reset states; =O: output alphabet; = : SxI O, a function defines the output. > A finite state machine of Moore type is defined in the same way except that the output function : S O does not depend on the present inputs.
4
ENEE 6444 Example: Finite State Machine > I = {x,y} > S = {A,B,C} > S 0 = {A} > (A,x) = A, (B,x) = A, (C,x) = C (A,y) = B, (B,y) = C, (C,y) = A > O = {0,1} > (A,x) = 0, (B,x) = 0, (C,x) = 0 (A,y) = 1, (B,y) = 0, (C,y) = 1 (A,y) = 1, (B,y) = 0, (C,y) = 1
5
ENEE 6445 FSM Representation: STG In sum, a STG is a weighted, directed graph where self loops and duplicated edges are allowed. Each node has at most |I| outgoing edges and |I|x|S| incoming edges. Total number of edges is |I|x|S|+|S 0 |. > State Transition Graph: =Node state (S) =Edge transition ( : SxI S, : SxI O, S 0 ) Direction: from the current state to the next stateDirection: from the current state to the next state Label: input/output information for the transitionLabel: input/output information for the transition Special edges: edges without source, their ending nodes are initial statesSpecial edges: edges without source, their ending nodes are initial states
6
ENEE 6446 Example: FSM as an STG > I = {x,y} > S = {A,B,C} > S 0 = {A} > (A,x) = A, (A,y) = B, (B,x) = A, (B,y) = C, (C,x) = C, (C,y) = A > O = {0,1} > (A,x) = 0, (A,y) = 1, (B,x) = 0, (B,y) = 0, (B,x) = 0, (B,y) = 0, (C,x) = 0, (C,y) = 1 (C,x) = 0, (C,y) = 1AC B x/0 y/1 x/0 y/0 y/1
7
ENEE 6447 FSM Representation: Flow Table > The flow table of an FSM is a |S|x|I| table, where the i-th row represents state S i, the j-th column represents input value x j. The entry at (i,j) is a 2 tuple. The initial states S 0 can be specified separately. > Example: A CB x/0 y/1 x/0 y/0 y/1 A,1C,0 C,0A,0B,1A,0 C B Ayx
8
ENEE 6448 FSM Representation: Cube Table > The cube table of an FSM is a (|S|x|I|)x4 table, where in each row, the first column represents input value x j, second column is the state S i, third column is the next state (S i,x j ), and the last column is the output (S i,x j ). The initial states S 0 can be specified separately. > Example: A C B x/0 y/1 x/0 y/0 y/1 1ACy 0CCx 0CBy 0ABx 1BAy 0AAxONSPSI A,1C,0C C,0A,0B B,1A,0Ayx
9
ENEE 6449 FSM with Incomplete Specification > An FSM is incompletely specified if and/or are incompletely specified functions. (I.e., they are not defined on some combinations of inputs and present states.) Otherwise, it is completely specified. =In STG, this means there exist nodes with less than |I| outgoing edges; =In flow table, this means there exist undefined entries; =In cube table, this means there exist undefined rows.
10
ENEE 64410 Make Incomplete Complete > In STG: add a dummy state called trap state. > In flow table: leave the entry empty or fill it by. > In cube table: delete the undefined row or fill the last two columns by don’t cares. A C B x/0 y/1 x/0 y/0 y/1 D ? -/- A CB x/0 y/1 x/0 y/0 y/1 D x/- y/-
11
ENEE 64411 FSM Minimization > FSMs may contain redundant states, i.e. states whose function can be accomplished by other states. > Removing the redundant states decreases the number of states in the FSM, and in general results in a simplification in the final implementation. > State minimization is the transformation of a given FSM into an equivalent FSM with no redundant states (I.e. minimal number of states).
12
ENEE 64412 Binary Relations Given two sets A and B, a binary relation R between A and B is a subset of AxB={(x,y)|x A,y B}. We write x R y if (x,y) R. Relation R BxB is reflexive iff x R x for any x B; symmetric iff x R y y R x; anti-symmetric iff x R y, y R x x=y; transitive iff x R y, y R z x R z. A binary relation R BxB is an equivalent relation if it is reflexive, symmetric, and transitive. compatibility relation
13
ENEE 64413 Partition into Equivalent Classes A partition of a set of B is a set of subsets B i B, such that B i B i ( i j) iBi=B.iBi=B.iBi=B.iBi=B. Given an equivalent relation R BxB, the equivalent class of x B is [x]={y B|x R y}. = x,y B, [x]=[y] or [x] [y]= ; =If B 1,B 2,…,B n are all the different equivalent classes, then {B 1,B 2,…,B n } is a partition of B. An equivalent relation gives a unique partition.
14
ENEE 64414 Refinement of a Partition > Given two partitions P 1 ={B 1 1,B 2 1,…,B m 1 } and P 2 ={B 1 2,B 2 2,…,B n 2 } of a set B, P 1 is a refinement of P 2 if every subset (block) B i 1 B j 2 for some j. > Let P 1 ={B 1 1,B 2 1,…,B m 1 } and P 2 ={B 1 2,B 2 2,…,B n 2 } be two sets of subsets of a set B, the meet of P 1 and P 2 is defined as the following set: P 1 P 2 ={B i 1 B j 2 |i=1,2,…m,j=1,2,…,n} > Theorem: If P 1 and P 2 are partitions, then P 1 P 2 is also a partition of the same set B, furthermore, it is a refinement for both P 1 and P 2. [Proof:]
15
ENEE 64415 Equivalent States of an FSM > Given two states s and t in an FSM, and a k-string x=(x 0 x 1 …x k-1 ), suppose z s =(z s 0 z s 1 …z s k-1 ) and z t =(z t 0 z t 1 …z t k-1 ) are the corresponding output strings when states s and t are used as starting state respectively. x is called a length-k distinguishing sequence for states s and t iff z s k-1 z t k-1. x k-1 …x 1 x 0 s t z s k-1 …z s 1 z s 0 x k-1 …x 1 x 0 s t z t k-1 …z t 1 z t 0 == ?
16
ENEE 64416 Equivalent States of an FSM > Two states s and t are k-equivalent, written as s k t, iff there does not exist a distinguishing sequence for s and t of length k or less. > Two states are equivalent iff they are |S|- equivalent. > Define k ={(s,t)| s k t}, the set of all pairs of k- equivalent states. > k is an equivalent relation, I.e., it is =Reflexive: s k s =Symmetric: s k t t k s =Transitive: r k s, s k t r k t
17
ENEE 64417 Equivalent States of an FSM > 1 ={(A,C),(A,E),(C,E),(B,D),(B,F),(D,F), (C,A),(E,A),(E,C),(D,B),(F,B),(F,D), (A,A),…,(F,F)} =B 1 1 ={A,C,E} =B 2 1 ={B,D,F} > 2 ={(A,C),(A,E),(C,E),(B,D), (C,A),(E,A),(E,C),(D,B), (A,A),…,(F,F)} =B 1 2 ={A,C,E} =B 2 2 ={B,D} =B 3 2 ={F} > 3 ={(A,C),(B,D),(C,A),(D,B),(A,A),…,(F,F)} F C E B D A 1/1 0/0 1/1 0/0 1/1 1/0 0/0
18
ENEE 64418 Equivalent States Checking: Theory > Two states are equivalent iff they are |S|- equivalent. > Theorem 1. Let s x and t x be the x-successors of s and t in an FSM, then s k+1 t s k t and x I, s x k t x. > Theorem 2. Two states of a given FSM are equivalent iff they are (|S|)-equivalent.
19
ENEE 64419 State Equivalence Checking: Practice > Goal: determine |S| (S), all pairs of equivalent states in an FSM S. > Partition-Refinement procedure: =P k ={B 1 k,B 2 k,…}: the partition determined by k, the k- equivalent state pairs. (P 0 =S={B 1 0 }) =Idea: For each block in P k partition it (for all x I) if its x-successors are not in the same block;partition it (for all x I) if its x-successors are not in the same block; Refine the partition by taking the meet of these finer partitions;Refine the partition by taking the meet of these finer partitions; Stop when P k+1 =P k
20
ENEE 64420 P 0 ={(A,B,C,D,E,F)} (1-block) P 1 ={(A,C,E),(B,D,F)} for block P 1 2 =(A,C,E): on x=0: next states:EEC on x=0: next states:EEC blk indices:111 Pb 1 0 ={(A,C,E)}=P 1 2 (no refinement) on x=1:next states:DBF on x=1:next states:DBF blk indices:222 Pb 1 1 ={(A,C,E)}=P 1 2 (no refinement) (no refinement) P 2 ={(A,C,E)} PS NS, z x=0x=1 AE, 0D, 1 BD, 0F, 0 CE, 0B, 1 DB, 0F, 0 EC, 0F, 1 FB, 0C, 0 Example: Finding Equivalent States F C E B D A 1/1 0/0 1/1 0/0 1/1 1/0 0/0 input blk no. level
21
ENEE 64421 PS NS, z x=0x=1 AE, 0D, 1 BD, 0F, 0 CE, 0B, 1 DB, 0F, 0 EC, 0F, 1 FB, 0C, 0 Example: Finding Equivalent States P 1 ={(A,C,E),(B,D,F)} P 2 ={(A,C,E)} for block P 2 2 =(B,D,F): on x=0: next states:DBB on x=0: next states:DBB blk indices:222 Pb 2 0 ={(B,D,F)}=P 2 2 on x=1:next states:FFC on x=1:next states:FFC blk indices:221 Pb 2 1 ={(B,D),(F)} refine:P 2 2 =P 2 2 Pb 2 1 = Pb 2 1 refine:P 2 2 =P 2 2 Pb 2 1 = Pb 2 1 ={(B,D),(F)} ={(B,D),(F)} P 2 ={(A,C,E),(B,D),(F)} F C E B D A 1/1 0/0 1/1 0/0 1/1 1/0 0/0
22
ENEE 64422 PS NS, z x=0x=1 AE, 0D, 1 BD, 0F, 0 CE, 0B, 1 DB, 0F, 0 EC, 0F, 1 FB, 0C, 0 Example: Finding Equivalent States P 1 ={(A,C,E),(B,D,F)} P 2 ={(A,C,E),(B,D),(F)} for block P 1 3 =(A,C,E): on x=0: next states:EEC on x=0: next states:EEC blk indices:111 Pb 1 0 ={(A,C,E)}=P 1 3 on x=1:next states:DBF on x=1:next states:DBF blk indices:223 Pb 1 1 ={(A,C),(E)} refine:P 1 3 =P 1 3 Pb 1 1 = Pb 1 3 refine:P 1 3 =P 1 3 Pb 1 1 = Pb 1 3 ={(A,C),(E)} ={(A,C),(E)} P 3 ={(A,C),(E)} F C E B D A 1/1 0/0 1/1 0/0 1/1 1/0 0/0
23
ENEE 64423 PS NS, z x=0x=1 AE, 0D, 1 BD, 0F, 0 CE, 0B, 1 DB, 0F, 0 EC, 0F, 1 FB, 0C, 0 Example: Finding Equivalent States P 1 ={(A,C,E),(B,D,F)} P 2 ={(A,C,E),(B,D),(F)} P 3 ={(A,C),(E)} for block P 2 3 =(B,D): on x=0: next states:DB on x=0: next states:DB blk indices:22 Pb 1 0 ={(B,D)}=P 2 3 on x=1:next states:FF on x=1:next states:FF blk indices:33 Pb 1 1 ={(B,D)}=P 2 3 P 3 ={(A,C),(E),(B,D)} P 3 ={(A,C),(E),(B,D)} F C E B D A 1/1 0/0 1/1 0/0 1/1 1/0 0/0
24
ENEE 64424 PS NS, z x=0x=1 AE, 0D, 1 BD, 0F, 0 CE, 0B, 1 DB, 0F, 0 EC, 0F, 1 FB, 0C, 0 Example: Finding Equivalent States P 1 ={(A,C,E),(B,D,F)} P 2 ={(A,C,E),(B,D),(F)} P 3 ={(A,C),(E),(B,D)} for block P 3 3 =(F): contains single state, cannot be partitioned. P 3 ={(A,C),(E),(B,D),(F)} P 3 ={(A,C),(E),(B,D),(F)} P 3 ={(A,C),(E),(B,D),(F)} F C E B D A 1/1 0/0 1/1 0/0 1/1 1/0 0/0
25
ENEE 64425 PS NS, z x=0x=1 AE, 0D, 1 BD, 0F, 0 CE, 0B, 1 DB, 0F, 0 EC, 0F, 1 FB, 0C, 0 Example: Finding Equivalent States P 1 ={(A,C,E),(B,D,F)} P 2 ={(A,C,E),(B,D),(F)} P 3 ={(A,C),(E),(B,D),(F)} One can compute P 4 in the same way, which gives P 4 ={(A,C),(E),(B,D),(F)} P 4 =P 3 so we stop Conclusion: A and C are equivalent B and D are equivalent F C E B D A 1/1 0/0 1/1 0/0 1/1 1/0 0/0
26
ENEE 64426 FSM Minimization with Equivalent States STG: collapse states in the same equivalent class to one state; update edges. F C E B D A 1/1 0/0 1/1 0/0 1/1 1/0 0/0 Equivalent classes: (A,C), (B,D), (E), (F) C F E B D A 1/1 0/0 1/1 0/0 1/1 1/0 0/0 1/0 0/0 F E D A 1/1 0/0 1/1 1/0 0/0
27
ENEE 64427 Definition: Finite State Machine Recall: A Finite State Machine (FSM) of Mealy type is a 6 tuple Recall: A Finite State Machine (FSM) of Mealy type is a 6 tuple =I: input alphabet, a non-empty set of input values; =S: a non-empty, finite set of states; = : SxI S, a function defines the next state; =S 0 : S, the set of initial/reset states; =O: output alphabet; = : SxI O, a function defines the output.
28
ENEE 64428 FSM Equivalence Checking M 1 = M 2 = M 1 = M 2 = > What do we mean by M 1 and M 2 are equivalent? For any input, they should produce the same output. =I 1 = I 2 =O 1 = O 2 > How to verify that M 1 and M 2 are equivalent? =Assuming that S 0 1 ={s 0 1 } and S 0 2 ={s 0 2 }, then if there is no input string can distinguish s 0 1 and s 0 2, we claim that M 1 and M 2 are equivalent.
29
ENEE 64429 The Product Machine > The product machine of two FSMs, M 1 = and M 2 =, is defined as M 12 = > The product machine of two FSMs, M 1 = and M 2 =, is defined as M 12 = =S 12 =S 1 xS 2 ={(s 1,s 2 )| s 1 S 1,s 2 S 2 } = 12 : S 12 xI S 12 12 (s 12,x)=t 12 =(t 1,t 2 ) 12 (s 12,x)=( 1 (s 1,x), 2 (s 2,x)) =(t 1,t 2 ) 12 (s 12,x)=( 1 (s 1,x), 2 (s 2,x)) =(t 1,t 2 ) =S 0 12 =S 0 1 xS 0 2 ={(s 0 1,s 0 2 )| s 0 1 S 0 1,s 0 2 S 0 2 } = 12 : S 12 xI {0,1} 12 (s 12,x)=1iff 1 (s 1,x)= 2 (s 2,x) > M 1 and M 2 are equivalent M 12 always outputs 1.
30
ENEE 64430 Run and Reachable State > For an FSM M 1 =, an input string x 0 x 1 …x k-1 produces a sequence of states s 0 s 1 …s k (called a run, where s 0 is the starting state) and an output string z 0 z 1 …z k-1. > A state t is reachable from state s if there exists an input string that produces a run with s as the starting state and t as the ending state. > The reachable states of an FSM is defined as:{t S| t is reachable from s, s S 0 } We only need to check the reachable states for FSM equivalence.
31
ENEE 64431 FSM Equivalence Checking M 1 = M 2 = M 1 = M 2 = > If I 1 I 2 or O 1 O 2 return not equivalent; > Build the product machine M 12 ; > Start with the initial state s 0 12, traverse the STG of the FSM M 12 ; =For each reachable state in M 12, if it can output 0, return not equivalent; =Return equivalent; > To get a distinguishing sequence in the case of not equivalent, we need to store the predecessor information and do backtracking.
32
ENEE 64432 Example: FSM Equivalence Checking > M 1 = > M 1 = > M 2 = > M 2 = > M 12 = > M 12 = =|S 12 | = 9, however, only 3 states are reachable: (A,D),(B,E),(C,F) =Every reachable state outputs 1 on all inputs. =So M 1 and M 2 are equivalent. A C B x/0 y/1 x/0 y/0 y/1 D F E x/0 y/1 x/0 y/0 y/1 A,D C,F B,E x/1 y/1 x/1 y/1 A,E x/1 B,F y/0
33
ENEE 64433 Example: FSM Equivalence Checking > Now, M 1 and M 2 are not equivalent. > Consequently, one of the reachable state (C,F) outputs 0 on input x. > Backtracking to find the distinguishing sequence. A C B x/0 x/1 y/1 x/0 y/0 y/1 D F E x/0 y/1 x/0 y/0 y/1 A,D C,F B,E x/1 x/0 y/1 x/1 y/1 A,E x/1 B,F y/0
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.