Transcript lecture15
Finite State Machines (FSMs)
• •
Today: First Hour : FSM Concept
–
Section 8.1 of Katz’s Textbook
–
In-class Activity #1
Second Hour : Design Example w/ FSM
•
Section 8.2 of Katz’s Textbook
–
In-class Activity #2 1
Counters vs FSMs
A Precursor of Finite State Machines • Counters: Simple sequential circuits State = Output No inputs Simple single-path sequencing through the states • Generalizes to Finite State Machines: Outputs are Function of State (and Inputs) Next States are Functions of State and Inputs Used to implement circuits that control other circuits "Decision Making" or “control” logic 2
Recap: Synchronous FSMs
•
Described by State Diagrams, much the same way that combinational logic circuits are described by Boolean Algebra.
Current State [output] Current Input(s) New State [output] Change of state happens only on the clocking event 3
Recap:
3-bit Binary Up-Counter
Each circle corresponds to a state The label inside each circle describes the state Arrows represent state transitions No labels on arrows, since the counter has no inputs 4
Example: Odd Parity Checker
Asserts output whenever input bit stream (seen so far) has odd # of 1's 0 1 Reset Even [0] 1 0 Present State Even Even Odd Odd Input 0 1 0 1 Next State Even Odd Odd Even Output 0 0 1 1 Symbolic State Transition Table Odd [1] State Diagram Present State 0 0 1 1 Input 0 1 0 1 Next State 0 1 1 0 Output 0 0 1 1 Encoded State Transition Table Observe that the output in this case depends only upon the present state, and not upon the input.
5
Design with Flip-flops
Q 0 0 1 1 Q + 0 1 0 1 T 0 1 1 0 T F/F: Excitation Table Q 0 0 1 1 Q + 0 1 0 1 D 0 1 0 1 D F/F: Excitation Table D F/F inputs are identical to the next state outputs in the state transition table 6
Odd Parity Checker Operation
Excitation/Output Functions D = PS
Input; Output = PS
D Input Clock D Q PS/Output R Q \Reset
D FF Implementation
Input Output T Q Clock R Q \Reset
T FF Implementation
Input 1 0 0 1 1 0 1 0 1 1 1 0 Clock Output 1 1 1 0 1 1 0 0 1 0 1 1
Timing Behavior: Input 1 0 0 1 1 0 1 0 1 1 1 0 7
Timing
When are inputs sampled, next states computed, outputs asserted?
State Time : Time between clocking events • Clocking event causes state/outputs to transition, based on inputs • For set-up/hold time considerations: Inputs should be stable before clocking event • After propagation delay , Next State entered, Outputs are stable NOTE: Asynchronous signals take effect immediately Synchronous signals take effect at the next clocking event E.g., 3-state enable: effective immediately sync. counter clear: effective at next clock event 8
Clock Inputs Outputs
Timing Example
Positive Edge Triggered Synchronous System
State Time
On rising edge: inputs sampled, outputs & next state computed After propagation delay: outputs and next state are stable Immediate Outputs affect datapath immediately could cause inputs from datapath to change Delayed Outputs take effect on next clock edge propagation delays must exceed hold times 9
Communicating State Machines
One machine's output is another machine's input X Y=0 Y=0 ,1 FSM 1 A [1] B [0] Y=0 Y=1 Y FSM 2 X=0 [0], [1] outputs X=0 D [1] X=0 C [0] X=1 X=1
CLK FSM 1
X
FSM 2
Y
Machines advance in lock step Initial inputs/outputs: X = 0, Y = 0
A C A D B D
Could be used to model: bus protocols, handshaking, 2-way communications, etc.
10
Do Activity #1 Now
11
Basic Design Approach
Six Step Process 1. Understand the statement of the Specification 2. Obtain an abstract specification of the FSM 3. Perform a state minimization 4. Perform state assignment 5. Choose FF types to implement FSM state register 6. Implement the FSM 12
Vending Machine Concept
General Machine Concept deliver package of gum after 15 cents is deposited single coin slot for dimes, nickels no change 13
Vending Machine FSM - 1
Step 1. Understand the problem INPUTS OUTPUTS Draw a picture!
N Coin Sensor D Reset Clk Vending Machine FSM Open Gum Release Mechanism Block Diagram 14
Vending Machine FSM - 2
Step 2. Map into more suitable abstract representation Tabulate typical input sequences three nickels nickel, dime dime, nickel two dimes two nickels, dime Res et S1 N S0 D S2 Draw state diagram Inputs: N, D, reset Output: open N S3 N D S4 [open] D S7 [open] S8 [open] N S5 [open] D S6 [open] 15
Vending Machine FSM - 3
Step 3: State Minimization Reset 0¢ N 5¢ D N 10¢ D N, D 15¢ [o pen ] reuse states whenever possible
Present State 0¢ 5¢ 10¢ 15¢ Inputs D N 0 0 1 1 X 0 0 1 1 0 0 1 1 0 1 0 1 X 0 1 0 1 0 1 0 1 Next State 0¢ 5¢ 10¢ X 5¢ 10¢ 15¢ X 10¢ 15¢ 15¢ X 15¢ Out put Open 0 0 0 X 1 0 0 0 X 0 0 0 X
Symbolic State Table 16
Vending Machine FSM - 4
Step 4: State Encoding How many flip-flops are needed?
Present State Q 1 Q 0 0 0 0 1 1 0 1 1 Inputs D N 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 Next State D 1 D 0 0 0 0 1 1 0 X X 0 1 1 0 1 1 X X 1 0 1 1 1 1 X X 1 1 1 1 1 1 X X Out put Open 0 0 0 X 0 0 0 X 0 0 0 X 1 1 1 X
17
Vending Machine FSM - 5a
Step 5. Choose F/Fs for implementation Q1 Q0 D N Q1 D F/F easiest to use Q1 Q1 Q0 D N Q1 Q0 D N Q1 N D N D N D Q0
K-map for D1
Q0
K-map for D0
Q0
K-map for Open
18
Vending Machine FSM - 5b
Step 5. Choose FF for Implementation (continued) J-K F/F
Present State Q 1 Q 0 0 0 0 1 1 0 1 1 Inputs D N 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 Next State Q 1 + Q 0 + 0 0 0 1 1 0 X X 0 1 1 0 1 1 X X 1 0 1 1 1 1 X X 1 1 1 1 1 1 X X J 1 0 0 1 X 0 1 1 X X X X X X X X X X 0 0 0 X X X X X X X X X 0 0 0 J 0 K 0 X 0 0 0 X X X X X 0 1 0 X X X X X X X X X 0 1 0 X X X X X 0 1 1
Remapped encoded state transition table 19
Vending Machine FSM - 6a
Step 6. Implementation: D F/Fs
Q 1 D Q 0 N N \ Q 0 Q 0 \ N Q 1 N Q 1 D D 1 D Q CLK \reset R Q Q 1 \ Q 1 OPEN D 0 D Q CLK \reset R Q Q 0 \ Q 0
D1 = Q1 + D + Q0 N D0 = N Q0 + Q0 N + Q1 N + Q1 D 8 Gates OPEN = Q1 Q0 20
Q1 Q0 D N Q0
K-map for J1
Q1 D D
Vending Machine FSM - 6b
Step 6. Implementation: J-K F/Fs Q1 Q1 Q1 Q0 D N Q1 Q0 D N J1 = D + Q0 N K1 = 0 N N D J0 = Q0 N + Q1 D K0 = Q1 N N Q1 Q0 D N Q0
K-map for K1
Q1 D
N
N
D
\
Q N
CLK
J Q K R Q
\
Q
OPEN
D
Q0
K-map for J0
Q0
K-map for K0
\
Q N
\reset CLK
J Q K R Q
\
Q
7 Gates 21
Do Activity #2 Now
Due: End of Class Today.
RETAIN THE LAST PAGE(S) (#3 onwards)!!
• •
For Next Class:
Bring Randy Katz Textbook, & TTL Data Book Required Reading:
–
Sec 8.4 of Katz
•
This reading is necessary for getting points in the Studio Activity!
22