Salta al contenuto
Note per Studenti Finite State Machines - Analysis Report

Finite State Machines - Analysis

In questa pagina 5

Analysis starts from a synchronous sequential circuit (flip-flops and gates, Sequential Systems - State, Latches and Flip-FlopsA sequential circuit has outputs that depend on the inputs and on the state held in memory elements; it is a combinational network with flip-flops in a feedback loop, where present state is the flip-flop outputs and next state is their inputs. Synchronous circuits update only on the clock edge. The SR latch (NOR) sets, resets, holds, and forbids S=R=1; the D latch is transparent while C=1; the edge-triggered D flip-flop is two D latches in cascade (master-slave) and samples D only on the active clock edge, with Q(t+1)=D(t).Sequential Systems - State, Latches and Flip-Flops →) and derives its behaviour. It is the inverse of synthesis (Finite State Machines - SynthesisSynthesis of a synchronous sequential circuit follows specifications, state diagram, state table (merging equivalent states), binary state encoding, choice of D flip-flop, flip-flop input and output equations, minimisation, circuit and verification. A state summarises the useful part of history; a sequence recogniser has one state per recognised prefix, reusing states for overlaps. A reset gives a known initial state. Gray encoding (minimum flip-flops) versus one-hot (one flip-flop per state, simpler logic): for the 1101 recogniser Gray costs about half.Finite State Machines - Synthesis →).

Analysis procedure

  1. Flip-flop input equations: they compute the next state (for a D flip-flop, A(t+1)=DA(t)A(t+1)=D_A(t)). The subscript names the state variable; the equations contain state variables and inputs.
  2. Output equations.
  3. State table: for each combination of present state and inputs, gives next state and output.
  4. State diagram: the same data in graphical form.
  5. Simulation (timing diagram) to check the operation.

Definition (state table). With mm flip-flops (state variables) and nn inputs the table has 2m+n2^{m+n} rows: m+nm+n columns for present state and inputs, mm for the next state, plus the output columns. A two-dimensional state table has one row per state and separate columns for each input value (next state/output).

Example. With m=2m=2 flip-flops and n=1n=1 input: 2m+n=23=82^{m+n}=2^3=8 rows.

State diagram. States are circles; transitions are arrows, one for each input combination; next to the arrow write input/output. A reset signal brings the circuit to a known initial state (arrow entering the initial state).

Mealy and Moore models

Definition (Mealy and Moore).

  • Mealy: outputs depend on the present state and the inputs. In the diagram the output is next to each arrow (input/output).
  • Moore: outputs depend only on the present state. The output is written inside the circle; arrows carry only the input.
  • A Mealy machine may need fewer states and less logic, and reacts faster: the output may change between two clock edges, as soon as the input changes (it depends on it combinationally).
  • In a Moore machine the output depends on the state, held in flip-flops that change only on the active edge: the output changes only at clock edges and is more stable; it usually needs one more state.

Counting example. Detecting the sequence 0101 with output 1: 2 states in Mealy, 3 states in Moore (the third means "0101 recognised" and carries the output in the circle).

Example 1: a Moore machine

Two D flip-flops A,BA,B, input XX, output YY, reset to AB=00AB=00: DA=X+B,DB=X A‾,Y=A‾+B.D_A=X+B,\qquad D_B=X\,\overline A,\qquad Y=\overline A+B .

ABAB XX DADBD_AD_B (next state) YY
00 0 00 1
00 1 11 1
01 0 10 1
01 1 11 1
10 0 00 0
10 1 10 0
11 0 10 1
11 1 10 1

YY does not depend on XX: a Moore machine. State diagram (output in the circle):

  • state 00/100/1: X=0X=0 stays in 0000; X=1X=1 goes to 1111;
  • state 11/111/1: both X=0X=0 and X=1X=1 go to 1010;
  • state 10/010/0: X=0X=0 goes to 0000; X=1X=1 stays in 1010;
  • state 01/101/1: X=0X=0 goes to 1010; X=1X=1 goes to 1111.

From reset 0000, state 0101 is unreachable.

Simulation with X=1,0,0,1,1,0,1,0X=1,0,0,1,1,0,1,0 (one value per cycle, reset to 0000 first):

cycle 0 1 2 3 4 5 6 7
present state ABAB 00 11 10 00 11 10 00 11
input XX 1 0 0 1 1 0 1 0
output YY 1 1 0 1 1 0 1 1
next state 11 10 00 11 10 00 11 10

The output YY of cycle tt is determined by the present state.

Example 2: a Mealy machine

Two D flip-flops A,BA,B, input XX, output YY, reset to 0000: DA=B,DB=X⊕A‾,Y=A⊕B⊕X.D_A=B,\qquad D_B=\overline{X\oplus A},\qquad Y=A\oplus B\oplus X .

ABAB XX DADBD_AD_B YY
00 0 01 0
00 1 00 1
01 0 11 1
01 1 10 0
10 0 00 1
10 1 01 0
11 0 10 0
11 1 11 1

Here YY depends also on XX in every state: a Mealy machine. Diagram (arrows X/Y): 00→0/00100\xrightarrow{0/0}01, 00→1/10000\xrightarrow{1/1}00, 01→0/11101\xrightarrow{0/1}11, 01→1/01001\xrightarrow{1/0}10, 10→0/10010\xrightarrow{0/1}00, 10→1/00110\xrightarrow{1/0}01, 11→0/01011\xrightarrow{0/0}10, 11→1/11111\xrightarrow{1/1}11.

With X=1,1,0,1,0,0,1X=1,1,0,1,0,0,1 from reset: states 00,00,00,01,10,00,0100,00,00,01,10,00,01 and outputs Y=1,1,0,0,1,0,0Y=1,1,0,0,1,0,0.

States can be given symbolic names: S0=00S_0=00, S1=01S_1=01, S2=10S_2=10, S3=11S_3=11.

Equivalent states

Definition (equivalent states). Two states are equivalent if, for every input value, they give the same output and lead to equal or equivalent next states. Equivalent states can be merged, giving a simpler circuit with fewer states and flip-flops. Reduction does not always lower the cost: the cost also depends on the combinational network, not only on the flip-flops.

Example (Mealy, input xx, output 1 when xx goes from 1 to 0):

state x=0x=0 x=1x=1
S0S_0 S0/0S_0/0 S1/0S_1/0
S1S_1 S0/1S_0/1 S2/0S_2/0
S2S_2 S0/1S_0/1 S2/0S_2/0

S1S_1 and S2S_2 have the same outputs (11 for x=0x=0, 00 for x=1x=1) and the same destinations (S0S_0 for x=0x=0; S2S_2 for x=1x=1, which itself merges with S1S_1): they are equivalent. Merged into S12S_{12} the machine has 2 states (S0S_0: last input 0; S12S_{12}: last input 1), i.e. 1 flip-flop instead of 2. The systematic method is partition refinement: start by grouping states with the same output row and split those that, for the same input, go to different groups, until the partition no longer changes.

Versione ripasso

  • Steps: (1) FF input equations (A(t+1)=DAA(t+1)=D_A for D FFs); (2) output equations; (3) state table, 2m+n2^{m+n} rows for mm FFs and nn inputs; (4) state diagram (circles = states, arrows input/output); (5) simulation from reset. Two-dimensional table: one row per state.
  • Mealy: output =f(state,input)=f(\text{state},\text{input}), on the arrows, may change between clock edges, fewer states. Moore: output =f(state)=f(\text{state}), in the circle, changes only at edges. Detecting 0101: 2 states Mealy, 3 Moore.
  • Moore example: DA=X+BD_A=X+B, DB=XA‾D_B=X\overline A, Y=A‾+BY=\overline A+B. 00/100/1: 0→000\to00, 1→111\to11; 11/1→1011/1\to10; 10/010/0: 0→000\to00, 1→101\to10; 0101 unreachable. With X=1,0,0,1,1,0,1,0X=1,0,0,1,1,0,1,0: Y=1,1,0,1,1,0,1,1Y=1,1,0,1,1,0,1,1.
  • Mealy example: DA=BD_A=B, DB=X⊕A‾D_B=\overline{X\oplus A}, Y=A⊕B⊕XY=A\oplus B\oplus X. With X=1,1,0,1,0,0,1X=1,1,0,1,0,0,1: states 00,00,00,01,10,00,0100,00,00,01,10,00,01, outputs 1,1,0,0,1,0,01,1,0,0,1,0,0. Table: 0000: 0→01/00\to01/0, 1→00/11\to00/1; 0101: 0→11/10\to11/1, 1→10/01\to10/0; 1010: 0→00/10\to00/1, 1→01/01\to01/0; 1111: 0→10/00\to10/0, 1→11/11\to11/1.
  • Equivalent states: same output for every input and equal or equivalent next states, so merge (partition refinement). In the example S1≡S2S_1\equiv S_2, giving 2 states and 1 FF. Cost also depends on the combinational network.
  • Mistakes: calling a machine Mealy because it has an input (what counts is whether the output depends on it); Moore output on the arrows; reading next state as present state in the simulation; not checking reachability from reset.

Teoria collegata