Lecture 22 n State encoding n Onehot encoding

  • Slides: 24
Download presentation
Lecture 22 n State encoding ¡ ¡ n One-hot encoding Output encoding State partitioning

Lecture 22 n State encoding ¡ ¡ n One-hot encoding Output encoding State partitioning 1

FSM design n FSM design procedure 1. 2. 3. 4. 5. 6. State diagram

FSM design n FSM design procedure 1. 2. 3. 4. 5. 6. State diagram State-transition table State minimization State encoding Next-state logic minimization Implement the design 2

Usual example n n n 15 cents for a cup of coffee Doesn’t take

Usual example n n n 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 3

After state minimization Reset present state 0¢ D' N' N 5¢ 5¢ D N

After state minimization Reset present state 0¢ D' N' N 5¢ 5¢ D N D 10¢ D' N' 15¢ N+D 15¢ [open] 1 inputs D N 0 0 0 1 1 0 0 0 1 1 – – next state 0¢ 5¢ 10¢ – 5¢ 10¢ 15¢ – 15¢ output open 0 0 0 – 1 symbolic state table 4

How many state encodings? n Assume n state bits and m states ¡ 2

How many state encodings? n Assume n state bits and m states ¡ 2 n! / (2 n – m)! possible encodings n n Example: 3 state bits, 4 states, 1680 possible state assignments Which encoding is best? ¡ Want to pick state encoding strategy that results in optimizing your criteria n n n FSM size (amount of logic and number of FFs) FSM speed (depth of logic and fan-in/fan-out) FSM ease of design or debugging 5

State encoding strategies n No guarantee of optimality ¡ n An intractable problem Most

State encoding strategies n No guarantee of optimality ¡ n An intractable problem Most common strategies ¡ ¡ ¡ Binary (sequential) – number states as in the state table Random – computer tries random encodings Heuristic – rules of thumb that seem to work well n ¡ ¡ ¡ e. g. Gray-code – try to give adjacent states (states with an arc between them) codes that differ in only one bit position One-hot – use as many state bits as there are states Output – use outputs to help encode states Hybrid – mix of a few different ones (e. g. One-hot + heuristic) 6

One-hot encoding n One-hot: Encode n states using n flipflops ¡ Assign a single

One-hot encoding n One-hot: Encode n states using n flipflops ¡ Assign a single “ 1” for each state n ¡ Example: 0001, 0010, 0100, 1000 Propagate a single “ 1” from one flip-flop to the next n All other flip-flop outputs are “ 0” 7

One-hot variants n The inverse: One-cold encoding ¡ Assign a single “ 0” for

One-hot variants n The inverse: One-cold encoding ¡ Assign a single “ 0” for each state n ¡ Example: 1110, 1101, 1011, 0111 Propagate a single “ 0” from one flip-flop to the next n All other flip-flop outputs are “ 1” 8

One-hot variants n “almost one-hot” encoding (modified one-hot encoding) ¡ ¡ Use no-hot (000…

One-hot variants n “almost one-hot” encoding (modified one-hot encoding) ¡ ¡ Use no-hot (000… 0) for the initial (reset state) Assumes you never revisit the reset state till reset again 9

One-hot encoding n Often the best/convenient approach for FPGAs ¡ n FPGAs have many

One-hot encoding n Often the best/convenient approach for FPGAs ¡ n FPGAs have many flip-flops Draw FSM directly from the state diagram ¡ ¡ ¡ + One product term per incoming arc - Complex state diagram complex design - Many states many flip flops 10

Vending machine present state inputs next state output Q 3 Q 2 Q 1

Vending machine present state inputs next state output Q 3 Q 2 Q 1 Q 0 D N D 3 D 2 D 1 D 0 open 0 0 0 1 0 0 0 1 1 – 0 1 0 1 0 1 – 0 0 0 – 0 0 1 – 0 1 1 – 1 0 0 1 – 0 1 0 – 1 0 0 – 0 0 0 – 0 0 0 – 0 0 0 – 1 Reset D' N' 0¢ D' N' N 5¢ D N D 10¢ D' N' N+D 15¢ [open] 1 11

Designing from state diagram Reset D 0 = Q 0 D’N’ D' N' D

Designing from state diagram Reset D 0 = Q 0 D’N’ D' N' D 1 = Q 0 N + Q 1 D’N’ 0¢ D' N' D 2 = Q 0 D + Q 1 N + Q 2 D’N’ N 5¢ D 3 = Q 1 D + Q 2 N + Q 3 D OPEN = Q 3 N D 10¢ D' N' N+D 15¢ [open] 1 12

Output encoding n Reuse outputs as state bits ¡ ¡ Why create new functions

Output encoding n Reuse outputs as state bits ¡ ¡ Why create new functions when you can use outputs? Bits from state assignments are the outputs for that state n n Take outputs directly from the flip-flops Yields small circuits for most FSMs 13

Output encoding Inputs Combinational Logic State Inputs Outputs State Outputs Storage Elements 14

Output encoding Inputs Combinational Logic State Inputs Outputs State Outputs Storage Elements 14

FSM partitioning n Break a large FSM into two or more smaller FSMs ¡

FSM partitioning n Break a large FSM into two or more smaller FSMs ¡ Less states in each partition n ¡ Simpler minimization and state assignment Smaller combinational logic Shorter critical path But more logic overall 15

Example n Partition into two halves C 1 S 1 C 2 S 3

Example n Partition into two halves C 1 S 1 C 2 S 3 C 4 C 3 S 6 S 5 C 5 S 4 16

Introduce idle states n SA and SB handoff control between machines C 1 S

Introduce idle states n SA and SB handoff control between machines C 1 S 1 C 2 S 2 C 3 S 1 S 5 C 5 S 4 C 1 S 2 C 4 C 3+C 5 SA S 6 C 1 • S 1 (C 2 • S 6)’ C 2 • S 6 S 3 C 4 S 6 (C 1 • S 1+ C 3 • S 2+ C 4 • S 3+ C 5 • S 2)’ C 2 SB C 3 • S 2+ C 4 • S 3 S 5 C 5 • S 2 S 4 17

Partitioning rules Rule #1: Source-state transformation Replace by transition to idle state (SA) S

Partitioning rules Rule #1: Source-state transformation Replace by transition to idle state (SA) S 1 C 1 S 6 S 1 C 1 SA Rule #2: Destination state transformation Replace with exit transition from idle state S 1 C 2 S 6 S 1 C 2 • S 6 SA 18

Partitioning rules Rule #3: Multiple transitions with same source or destination Source Replace by

Partitioning rules Rule #3: Multiple transitions with same source or destination Source Replace by transitions to idle state (SA) Destination Replace with exit transitions from idle state C 3 S 2 C 3 • S 2 + C 4 • S 3 S 2 C 3+C 5 SA S 3 C 4 C 5 S 4 S 3 C 4 S 5 SB C 5 • S 2 S 4 Rule #4: Hold condition for idle state “OR exit conditions and invert” C 2 • S 6 S 1 C 2 • S 6 SA 19

Example U U S 0 S 5 D D U D S 1 S

Example U U S 0 S 5 D D U D S 1 S 4 D U D D S 2 S 3 U U 20

Example Count sequence S 0, S 1, S 2, S 3, S 4, S

Example Count sequence S 0, S 1, S 2, S 3, S 4, S 5 n S 2 goes to SA and holds, leaves after S 5 goes to SB and holds, leaves after S 2 Down sequence is similar ¡ ¡ ¡ S 0 S 5 U • S 5 U D D S 1 D U SA D • S 3 S 2 U (D • S 3 + U • S 5)’ (D • S 0+ U • S 2)’ SB U D • S 0 D U U • S 2 D S 4 D S 3 U 21

Example U Compare behavior on UUUUUU: U S 0 S 5 D D U

Example U Compare behavior on UUUUUU: U S 0 S 5 D D U D S 1 S 4 D U D D S 2 S 3 U U S 0 S 5 U • S 5 U D D S 1 D U SA D • S 3 S 2 U (D • S 3 + U • S 5)’ (D • S 0+ U • S 2)’ SB U D • S 0 D U U • S 2 D S 4 D S 3 U 22

Example n 4 -state machines need 2 state bits each – total 4 state

Example n 4 -state machines need 2 state bits each – total 4 state bits ¡ n Enough to represent 16 states, though the combination of the two FSMs has only 6 different configurations Why do this? ¡ ¡ Each FSM may be much simpler to think about (and design logic for) than the original FSM (not here, though) Essential to do this partitioning for large FSMs 23

Minimize communication n Ideal world: Two machines handoff control ¡ n Separate I/O, states,

Minimize communication n Ideal world: Two machines handoff control ¡ n Separate I/O, states, etc. Real world: Minimize handoffs and common I/O ¡ Minimize number of state bits that cross boundary 24