Lecture 17 General finite state machine (FSM) design Moore/Mealy machines 1 Finite state machines FSM: A system that visits a finite number of logically distinct states Counters are simple FSMs Outputs and states are identical Visit states in a fixed sequence without inputs 2 More than counters FSMs are typically more complex than counters Outputs can depend on current state and on inputs State sequencing depends on current state and on inputs 3 FSM design Counter design procedure 1. State diagram 2. State-transition table 3. Next-state logic minimization 4. Implement the design FSM design procedure 1. 2. 3. 4. 5. State diagram State-transition table State minimization State encoding Next-state logic minimization 6. Implement the design 4 Example: Vending machine 15 cents for a cup of coffee Doesn’t take pennies or quarters Doesn’t provide any change Reset N Coin Sensor D Vending Machine FSM Clock Open Release Mechanism 5 1. State diagram Reset (from all states) S0 N D S1 N S3 N S7 [open] Draw self-loops for N’ D’ for S0 to S3 S2 D N S4 [open] S5 [open] D Also draw self-loops for 1 for S4 to S8 S6 [open] D S8 [open] 6 2. State transition table present state S0 S1 S2 S3 S4 S5 S6 S7 S8 inputs D N 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 X X X X X 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 X X X X X next state S0 S1 S2 X S1 S3 S4 X S2 S5 S6 X S3 S7 S8 X S4 S5 S6 S7 S8 output open 0 0 0 X 0 0 0 X 0 0 0 X 0 0 0 X 1 1 1 1 1 7 3. State minimization present state 0¢ Reset N’D’ 0¢ N’D’ N 5¢ N’D’ D 5¢ D 10¢ N 10¢ 15¢ N+D 15¢ [open] Reset inputs D N 0 0 0 1 1 0 1 1 0 0 0 1 1 0 1 1 0 0 0 1 1 0 1 1 – – next state 0¢ 5¢ 10¢ – 5¢ 10¢ 15¢ – 10¢ 15¢ 15¢ – 15¢ output open 0 0 0 – 0 0 0 – 0 0 – 1 symbolic state table 8 4. State encoding present state inputs Q1 Q0 D N 0 0 0 0 0 1 1 0 1 1 0 1 0 0 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 1 1 – – next D1 0 0 1 – 0 1 1 – 1 1 1 – 1 state D0 0 1 0 – 1 0 1 – 0 1 1 – 1 output open 0 0 0 – 0 0 0 – 0 0 0 – 1 9 5. Next-state logic minimization Q1 D1 D 0 0 1 1 0 1 1 1 X X X X 1 1 1 1 Q0 Q1 D0 D0 N D 0 1 1 0 1 0 1 1 X X 0 1 N X X 1 Q1 Open 1 Q0 D 0 0 1 0 0 0 1 0 X X 1 X 0 0 1 Q0 0 N D1 = Q1 + D + Q0 N D0 = Q0’ N + Q0 N’ + Q1 N + Q1 D OPEN = Q1 Q0 10 6. Implement the design 11 Generalized FSM model Combinational logic computes next state and outputs Next state is a function of current state and inputs Outputs are functions of Current state (Moore machine) Current state and inputs (Mealy machine) Inputs output logic Next-state logic Current State Outputs Next State 12 Moore vs. Mealy machines inputs combinational logic for next state reg logic for outputs state feedback inputs logic for outputs combinational logic for next state state feedback outputs reg Moore machine Outputs are a function of current state outputs Outputs change synchronously with state changes Mealy machine Outputs depend on state and on inputs Input changes can cause immediate output changes (asynchronous) 13 State diagrams Moore machine Each state is labeled by a statename/output pair. Mealy machine Each transition arc is labeled by a inputcondition/output pair. 14 Example: 10 01 Circuits recognize AB=10 followed by AB=01 What kinds of machines are they? out A DQ Q DQ Q B DQ Q DQ Q out clock Moore A D Q Q B D Q Q clock Mealy 15 Example: "01" or "10" detector Moore: Output is a function of state only Specify output in the state bubble current next reset input state state 0 1 B/0 D/1 0 reset 0 1 A/0 1 1 C/0 1 0 E/1 0 1 0 0 0 0 0 0 0 0 0 0 – 0 1 0 1 0 1 0 1 0 1 – A A B B C C D D E E A B C B D E C E C B D current output 0 0 0 0 0 0 0 1 1 1 116 Example: "01" or "10" detector Mealy: Output is a function of state and inputs Specify outputs on transition arcs 0/0 B 0/0 reset/0 0/1 A 1/1 1/0 C 1/0 current next reset input state state 1 0 0 0 0 0 0 – 0 1 0 1 0 1 – A A B B C C A B C B C B C current output 0 0 0 0 1 1 0 17 Moore vs. Mealy Moore machines + Safer to use because outputs change at clock edge – May take additional logic to decode state into outputs Mealy machines + Typically have fewer states + React faster to inputs — don't wait for clock – Asynchronous outputs can be dangerous 18 Synchronous Mealy machines We often design synchronous Mealy machines Design a Mealy machine Then register the outputs 19 Synchronous Mealy machines Registered state and registered outputs No glitches on outputs No race conditions between communicating machines inputs logic for outputs combinational logic for next state reg outputs reg state feedback 20 Example: "== 01?" Recognize AB = 01 Mealy or Moore? A D B Synchronous Mealy (Moore) clock Q ou t Q A D ou t Q Q B clock D Q Q Moore 21
© Copyright 2026 Paperzz