rtl hardware design by p. chu chapter 101. 1. overview 2. fsm representation 3. timing and...

66
Finite State Machine RTL Hardware Design by P. Chu Chapter 10 1

Upload: pauline-mathews

Post on 16-Dec-2015

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 1

Finite State Machine

RTL Hardware Design by P. Chu

Page 2: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 2

1. Overview 2. FSM representation3. Timing and performance of an FSM4. Moore machine versus Mealy machine5. VHDL description of FSMs6. State assignment7. Moore output buffering8. FSM design examples

RTL Hardware Design by P. Chu

Outline

Page 3: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 3RTL Hardware Design by P. Chu

1. Overview on FSM

Contain “random” logic in next-state logic Used mainly used as a controller in a large

system Mealy vs Moore output

Page 4: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 4RTL Hardware Design by P. Chu

2. Representation of FSM State diagram

Page 5: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 5RTL Hardware Design by P. Chu

E.g. a memory controller

Page 6: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 6RTL Hardware Design by P. Chu

ASM (algorithmic state machine) chart ◦ Flowchart-like diagram ◦ Provide the same info as an FSM◦ More descriptive, better for complex description◦ ASM block

One state box One ore more optional decision boxes: with T or F

exit path One or more conditional output boxes: for Mealy

output

Page 7: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 7RTL Hardware Design by P. Chu

Page 8: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 8RTL Hardware Design by P. Chu

State diagram and ASM chart conversion

E.g. 1.

Page 9: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 9RTL Hardware Design by P. Chu

E.g. 2.

Page 10: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 10RTL Hardware Design by P. Chu

E.g. 3.

Page 11: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 11RTL Hardware Design by P. Chu

E.g. 4.

Page 12: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 12RTL Hardware Design by P. Chu

E.g. 6.

Page 13: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 13RTL Hardware Design by P. Chu

Difference between a regular flowchart and ASM chart:◦ Transition governed by clock ◦ Transition done between ASM blocks

Basic rules:◦ For a given input combination, there is one unique

exit path from the current ASM block◦ The exit path of an ASM block must always lead to

a state box. The state box can be the state box of the current ASM block or a state box of another ASM block.

Page 14: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 14RTL Hardware Design by P. Chu

Incorrect ASM charts:

Page 15: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 15RTL Hardware Design by P. Chu

Page 16: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 16RTL Hardware Design by P. Chu

3. Performance of FSM Similar to regular sequential circuit

Page 17: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 17RTL Hardware Design by P. Chu

Sample timing diagram

Page 18: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 18RTL Hardware Design by P. Chu

Page 19: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 19

Moore machine: ◦ output is a function of state

Mealy machine: ◦ output function of state and output

From theoretical point of view◦ Both machines have similar “computation

capability” Implication of FSM as a controller?

RTL Hardware Design by P. Chu

4. Moore vs Mealy output

Page 20: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 20

E.g., edge detection circuit◦ A circuit to detect the rising edge of a slow

“strobe” input and generate a “short” (about 1-clock period) output pulse.

RTL Hardware Design by P. Chu

Page 21: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 21RTL Hardware Design by P. Chu

Three designs:

Page 22: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 22RTL Hardware Design by P. Chu

Page 23: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 23

Comparison◦ Mealy machine uses fewer states◦ Mealy machine responds faster◦ Mealy machine may be transparent to glitches

Which one is better? Types of control signal

◦ Edge sensitive E.g., enable signal of counter Both can be used but Mealy is faster

◦ Level sensitive E.g., write enable signal of SRAM Moore is preferred

RTL Hardware Design by P. Chu

Page 24: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 24

Follow the basic block diagram Code the next-state/output logic according

to the state diagram/ASM chart Use enumerate data type for states

RTL Hardware Design by P. Chu

VHDL Description of FSM

Page 25: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 25RTL Hardware Design by P. Chu

E.g. 6.

Page 26: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 26RTL Hardware Design by P. Chu

Page 27: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 27RTL Hardware Design by P. Chu

Page 28: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 28RTL Hardware Design by P. Chu

Page 29: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 29RTL Hardware Design by P. Chu

Page 30: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 30RTL Hardware Design by P. Chu

Page 31: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 31RTL Hardware Design by P. Chu

Page 32: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 32RTL Hardware Design by P. Chu

Combine next-state/output logic together

Page 33: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 33RTL Hardware Design by P. Chu

Page 34: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 34RTL Hardware Design by P. Chu

Page 35: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 35

State assignment: assign binary representations to symbolic states

In a synchronous FSM◦ All assignments work◦ Good assignment reduce the complexity of next-

state/output logic Typical assignment

◦ Binary, Gray, one-hot, almost one-hot

RTL Hardware Design by P. Chu

6. State assignment

Page 36: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 36RTL Hardware Design by P. Chu

Page 37: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 37RTL Hardware Design by P. Chu

State assignment in VHDL

Implicit: use user attributes enum_encoding

Explicit: use std_logic_vector for the register

Page 38: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 38RTL Hardware Design by P. Chu

Page 39: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 39RTL Hardware Design by P. Chu

Page 40: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 40RTL Hardware Design by P. Chu

Handling the unused state

Many binary representations are not used What happens if the FSM enters an unused

state?◦ Ignore the condition◦ Safe (Fault-tolerant) FSM: got to an error state or

return to the initial state. Easy for the explicit state assignment No portable code for the enumerated data

type

Page 41: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 41

FSM as control circuit ◦ Sometimes fast, glitch-free signal is needed◦ An extra output buffer can be added, but

introduce one-clock delay Special schemes can be used for Moore

output◦ Clever state assignment◦ Look-ahead output circuit

RTL Hardware Design by P. Chu

6. Moore output buffering

Page 42: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 42RTL Hardware Design by P. Chu

Potential problems of the Moore output logic:◦ Potential hazards introduce glitches◦ Increase the Tco delay (Tco = Tcq + Toutput)

Can we get control signals directly from the register?

Page 43: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 43

Assigning state according to output signal patterns

Output can be obtained from register directly Extra register bits may be needed Must use explicit state assignment in VHDL

code to access individual register bit Difficult to revise and maintain

RTL Hardware Design by P. Chu

Clever state assignment

Page 44: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 44RTL Hardware Design by P. Chu

Page 45: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 45RTL Hardware Design by P. Chu

VHDL code

Page 46: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 46

Output buffer introduces one-clock delay The “next” value of Moore output can be

obtained by using state_next signal Buffer the next value cancel out the one-clock

delay More systematic and easier to revise and

maintain

RTL Hardware Design by P. Chu

Look-ahead output circuit

Page 47: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 47RTL Hardware Design by P. Chu

Page 48: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 48RTL Hardware Design by P. Chu

Modification over original VHDL code:◦ Add output buffer◦ Use state_next to replace state_reg in Moore

output logic

Page 49: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 49RTL Hardware Design by P. Chu

Page 50: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 50

Edge detector circuit Arbitrator (read) DRAM strobe signal generation Manchester encoding/decoding (read) FSM base binary counter

RTL Hardware Design by P. Chu

7. FSM design examples

Page 51: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 51RTL Hardware Design by P. Chu

Edge detecting circuit (Moore)

Page 52: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 52RTL Hardware Design by P. Chu

Page 53: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 53RTL Hardware Design by P. Chu

Use clever state assignment

Page 54: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 54RTL Hardware Design by P. Chu

Use look-ahead output

Page 55: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 55RTL Hardware Design by P. Chu

Edge detecting circuit (Mealy)

Page 56: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 56RTL Hardware Design by P. Chu

Page 57: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 57RTL Hardware Design by P. Chu

Edge detecting circuit (direct implementation):◦ edge occurs when previous value is 0 and new value is

1◦ Same as Mealy design with state assignment:

zero => 0, one => 1

Page 58: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 58RTL Hardware Design by P. Chu

Page 59: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 59

DRAM strobe signal generation◦ E.g.,120ns DRAM (Trc=120ns):

Tras=85ns, Tcas=20ns, Tpr=35ns

RTL Hardware Design by P. Chu

Page 60: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 60RTL Hardware Design by P. Chu

3 intervals has to be at least 65ns, 20 ns, and 35 ns

A slow design: use a 65ns clock period ◦ 195 ns (3*65ns) read cycle

The control signal is level-sensitive

Page 61: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 61RTL Hardware Design by P. Chu

Page 62: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 62

Should revise the code to obtain glitch-free output

RTL Hardware Design by P. Chu

Page 63: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 63RTL Hardware Design by P. Chu

A faster design: use a 20ns clock period◦ 140 ns (7*20ns) read cycle

idle mem r1ras_n<=0

p1cras_n<=0cas_n<=0

r2ras_n<=0

r3ras_n<=0

p2

mem'

r4ras_n<=0

Page 64: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 64RTL Hardware Design by P. Chu

FSM-based binary counter:◦ Free-running mod-16 counter

Page 65: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 65RTL Hardware Design by P. Chu

4-bit binary counter with features:◦ Synchronous clear, load, enable

Page 66: RTL Hardware Design by P. Chu Chapter 101. 1. Overview 2. FSM representation 3. Timing and performance of an FSM 4. Moore machine versus Mealy machine

Chapter 10 66RTL Hardware Design by P. Chu